git.iko.soy/typeable/nixpkgs
on master help sign in
haskell-lib: Factor out shell completion scripts helper
commitc34f5176f1173ac2cdaeed4512a61389d98f9d9f authorJohn Ericson <John.Ericson@Obsidian.Systems> dateTue 30 Oct 2018, 14:20 (8 years ago) parent88cd633
2 files changed+18−7
pkgs/development/haskell-modules/lib.nix+15 pkgs/top-level/all-packages.nix+3−7
pkgs/development/haskell-modules/lib.nix+15
@@ -407,4 +407,19 @@ rec {
407407
408408 in
409409 builtins.listToAttrs (map toKeyVal haskellPaths);
410+
411+ # Modify a Haskell package to add completion scripts for the given executable
412+ # produced by it. These completion scripts will be picked up automatically if
413+ # the resulting derivation is installed, e.g. by `nix-env -i`.
414+ addOptparseApplicativeCompletionScripts = exeName: pkg: overrideCabal pkg (drv: {
415+ postInstall = (drv.postInstall or "") + ''
416+ bashCompDir="$out/share/bash-completion/completions"
417+ zshCompDir="$out/share/zsh/vendor-completions"
418+ fishCompDir="$out/share/fish/vendor_completions.d"
419+ mkdir -p "$bashCompDir" "$zshCompDir" "$fishCompDir"
420+ "$out/bin/${exeName}" --bash-completion-script "$out/bin/${exeName}" >"$bashCompDir/${exeName}"
421+ "$out/bin/${exeName}" --zsh-completion-script "$out/bin/${exeName}" >"$zshCompDir/_${exeName}"
422+ "$out/bin/${exeName}" --fish-completion-script "$out/bin/${exeName}" >"$fishCompDir/${exeName}.fish"
423+ '';
424+ });
410425}
pkgs/top-level/all-packages.nix+3−7
@@ -1001,10 +1001,10 @@ with pkgs;
10011001
10021002 cue2pops = callPackage ../tools/cd-dvd/cue2pops { };
10031003
1004− cabal2nix = haskell.lib.overrideCabal haskellPackages.cabal2nix (drv: {
1004+ cabal2nix = haskell.lib.overrideCabal (haskell.lib.addOptparseApplicativeCompletionScripts "cabal2nix" haskellPackages.cabal2nix) (drv: {
10051005 isLibrary = false;
10061006 enableSharedExecutables = false;
1007− executableToolDepends = [ makeWrapper ];
1007+ executableToolDepends = (drv.executableToolDepends or []) ++ [ makeWrapper ];
10081008 postInstall = ''
10091009 exe=$out/libexec/${drv.pname}-${drv.version}/${drv.pname}
10101010 install -D $out/bin/${drv.pname} $exe
@@ -1012,11 +1012,7 @@ with pkgs;
10121012 makeWrapper $exe $out/bin/${drv.pname} \
10131013 --prefix PATH ":" "${nix}/bin" \
10141014 --prefix PATH ":" "${nix-prefetch-scripts}/bin"
1015− mkdir -p $out/share/{bash-completion/completions,zsh/vendor-completions,fish/completions}
1016− $exe --bash-completion-script $exe >$out/share/bash-completion/completions/${drv.pname}
1017− $exe --zsh-completion-script $exe >$out/share/zsh/vendor-completions/_${drv.pname}
1018− $exe --fish-completion-script $exe >$out/share/fish/completions/${drv.pname}.fish
1019− '';
1015+ '' + (drv.postInstall or "");
10201016 });
10211017
10221018 stack2nix = with haskell.lib; overrideCabal (justStaticExecutables haskellPackages.stack2nix) (drv: {