cabal2nix
cabal2nix copied to clipboard
Automatically generate bash completion files for executables using optparse-applicative
All executables that use optparse-applicative for their command-line parsing can dump a bash completion file for themselves. We use that for stack
and cabal2nix
and others already, but we configure the appropriate postInstall
hook manually, i.e. in https://github.com/NixOS/cabal2nix/commit/d281a6023f1e0fdfd98796bd0ba3f7764c03a457. This should be something that
- the generic build does automatically (when an appropriate flag is enabled) or
-
cabal2nix
should generate an appropriate hook automatically when the dependency is detected.
:+1:
In the meanwhile could you describe what need to be added in the default.nix
or shell.nix
to enable completion when using nix-shell
? That would be very handy !
The hackage2nix
expression at https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/haskell/cabal2nix/hackage2nix.nix#L27-L31 uses the following code:
postInstall = ''
exe=$out/bin/${pname}
mkdir -p $out/share/bash-completion/completions
$exe --bash-completion-script $exe >$out/share/bash-completion/completions/${pname}
'';
Thanks for the input.
It does not work and my guest is that the culprit might be the $out
param. echo $out
in the shell does print some path but the path does not seem to match any directory. Am I supposed to use another variable
?
Well, nix-shell
does neither compile nor install anything -- it just provides an environment in which you can compile and/or install things --, thus the postInstall
hook is never executed by nix-shell
. If you want to get bash completions for projects you develop in nix-shell
, then you'll have to generate them manually.
Thanks for helping. I will use shellHook
for now to source the completion file.