Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haskell generic bash completions break cross-compilation #49748

Closed
roberth opened this issue Nov 4, 2018 · 11 comments
Closed

Haskell generic bash completions break cross-compilation #49748

roberth opened this issue Nov 4, 2018 · 11 comments
Labels
0.kind: bug 6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: haskell

Comments

@roberth
Copy link
Member

roberth commented Nov 4, 2018

Issue description

Completions in Haskell currently break cross compilation.

Since #49477 we have a function that does this generically for Haskell packages. This can be improved by either:

  • not adding completions when cross compiling
  • emulating the behavior of optparse-applicative to generate the very simple scripts in plain bash, which seems feasible. The duplicated logic can then be tested against the native optparse-applicative behavior.

Steps to reproduce

Cross compile a package with completions, like stack. It will call the build output and fail.
Note that stack currently has its own override in hackage2nix, which is probably best to disable in favor of the library functions.

@roberth roberth added 0.kind: bug 6.topic: haskell 6.topic: cross-compilation Building packages on a different platform than they will be used on labels Nov 4, 2018
@roberth
Copy link
Member Author

roberth commented Nov 4, 2018

cc @Ericson2314

@Ericson2314
Copy link
Member

I would just not do it during cross compilation for. K
Now. We can also copy the output from a native build.

@matthewbauer
Copy link
Member

I think disabling makes the most sense. You could use the native-built one but it might end up being incorrect. For instance one option is only available for one architecture or operating system.

@roberth
Copy link
Member Author

roberth commented Nov 4, 2018

It's actually a very very predictable script that does not depend on the options. For this reason, duplicating it in Nix is actually feasible.

It depends only on the executable name/path and the command name.
Source.

Example:

$ nix-shell -p dhall --run 'stack --bash-completion-script dhall'
_stack()
{
    local CMDLINE
    local IFS=$'\n'
    CMDLINE=(--bash-completion-index $COMP_CWORD)

    for arg in ${COMP_WORDS[@]}; do
        CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg)
    done

    COMPREPLY=( $(dhall "${CMDLINE[@]}") )
}

complete -o filenames -F _stack stack

@roberth
Copy link
Member Author

roberth commented Nov 4, 2018

Of course this is a 'nice to have'. We can do without completions on cross.

@roberth roberth mentioned this issue Nov 4, 2018
9 tasks
@stale
Copy link

stale bot commented Jun 3, 2020

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 3, 2020
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 29, 2021
@roberth
Copy link
Member Author

roberth commented Apr 29, 2021

The protocol between shell and executable has been fairly stable and the maintainer cares about compatibility, because non-Nix users can have scripts that are out of sync with (upgraded) executables.
Additionally, the protocol may be upgraded to a more forward-compatible form similar to, say, http response headers. See pcapriotti/optparse-applicative#414

@marksisson
Copy link

Is there a recommended way to disable the completions for cross compiling?

@roberth
Copy link
Member Author

roberth commented Jun 10, 2022

None of the overrides in nixpkgs seem to handle this.

You could define a function with the same name in the package set pkgs/development/haskell-modules/make-package-set.nix, and make its definition conditional so that it returns an empty string when cross.
Instead of lib.generateOptparseApplicativeCompletion, you'll call super.generateOptparseApplicativeCompletion.

@Artturin
Copy link
Member

diff --git a/pkgs/development/haskell-modules/lib/compose.nix b/pkgs/development/haskell-modules/lib/compose.nix
index 600bf80cb19..575b2e08f11 100644
--- a/pkgs/development/haskell-modules/lib/compose.nix
+++ b/pkgs/development/haskell-modules/lib/compose.nix
@@ -437,9 +437,9 @@ rec {
       zshCompDir="''${!outputBin}/share/zsh/vendor-completions"
       fishCompDir="''${!outputBin}/share/fish/vendor_completions.d"
       mkdir -p "$bashCompDir" "$zshCompDir" "$fishCompDir"
-      "''${!outputBin}/bin/${exeName}" --bash-completion-script "''${!outputBin}/bin/${exeName}" >"$bashCompDir/${exeName}"
-      "''${!outputBin}/bin/${exeName}" --zsh-completion-script "''${!outputBin}/bin/${exeName}" >"$zshCompDir/_${exeName}"
-      "''${!outputBin}/bin/${exeName}" --fish-completion-script "''${!outputBin}/bin/${exeName}" >"$fishCompDir/${exeName}.fish"
+      ${pkgs.stdenv.hostPlatform.emulator pkgs.buildPackages} "''${!outputBin}/bin/${exeName}" --bash-completion-script "''${!outputBin}/bin/${exeName}" >"$bashCompDir/${exeName}"
+      ${pkgs.stdenv.hostPlatform.emulator pkgs.buildPackages} "''${!outputBin}/bin/${exeName}" --zsh-completion-script "''${!outputBin}/bin/${exeName}" >"$zshCompDir/_${exeName}"
+      ${pkgs.stdenv.hostPlatform.emulator pkgs.buildPackages} "''${!outputBin}/bin/${exeName}" --fish-completion-script "''${!outputBin}/bin/${exeName}" >"$fishCompDir/${exeName}.fish"
 
       # Sanity check
       grep -F ${exeName} <$bashCompDir/${exeName} >/dev/null || {

this would probably work, did not test

@marksisson
Copy link

marksisson commented Oct 15, 2022

Resolved by commit ac1f1ad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug 6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: haskell
Projects
None yet
Development

No branches or pull requests

5 participants