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

haskellPackages: Add shell completions #49714

Merged
merged 2 commits into from
Nov 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions pkgs/development/haskell-modules/configuration-common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,11 @@ self: super: {
# This is due to GenList having been removed from generic-random in 1.2.0.0
# doJailbreak: Can be removed once https://github.com/haskell-nix/hnix/pull/329 is in (5.2 probably)
# This is due to hnix currently having an upper bound of <0.5 on deriving-compat, works just fine with our current version 0.5.1 though
hnix = dontCheck (doJailbreak (overrideCabal super.hnix (old: {
testHaskellDepends = old.testHaskellDepends or [] ++ [ pkgs.nix ];
})));
hnix =
generateOptparseApplicativeCompletion "hnix" (
dontCheck (doJailbreak (overrideCabal super.hnix (old: {
testHaskellDepends = old.testHaskellDepends or [] ++ [ pkgs.nix ];
}))));

# Fails for non-obvious reasons while attempting to use doctest.
search = dontCheck super.search;
Expand Down Expand Up @@ -713,7 +715,9 @@ self: super: {
});

# The standard libraries are compiled separately
idris = doJailbreak (dontCheck super.idris);
idris = generateOptparseApplicativeCompletion "idris" (
doJailbreak (dontCheck super.idris)
);

# https://github.com/bos/math-functions/issues/25
math-functions = dontCheck super.math-functions;
Expand Down Expand Up @@ -1047,7 +1051,20 @@ self: super: {
vector-algorithms = dontCheck super.vector-algorithms;

# The test suite attempts to use the network.
dhall = dontCheck super.dhall;
dhall =
generateOptparseApplicativeCompletion "dhall" (
dontCheck super.dhall
);

dhall-json =
generateOptparseApplicativeCompletions ["dhall-to-json" "dhall-to-yaml"] (
super.dhall-json
);

dhall-nix =
generateOptparseApplicativeCompletion "dhall-to-nix" (
super.dhall-nix
);

# https://github.com/well-typed/cborg/issues/174
cborg = doJailbreak super.cborg;
Expand All @@ -1064,14 +1081,18 @@ self: super: {
# haddock-library_1_6_0 = doJailbreak (dontCheck super.haddock-library_1_6_0);

# The tool needs a newer hpack version than the one mandated by LTS-12.x.
cabal2nix = super.cabal2nix.overrideScope (self: super: {
hpack = self.hpack_0_31_1;
yaml = self.yaml_0_11_0_0;
});
# Also generate shell completions.
cabal2nix = generateOptparseApplicativeCompletion "cabal2nix"
(super.cabal2nix.overrideScope (self: super: {
hpack = self.hpack_0_31_1;
yaml = self.yaml_0_11_0_0;
}));
stack2nix = super.stack2nix.overrideScope (self: super: {
hpack = self.hpack_0_31_1;
yaml = self.yaml_0_11_0_0;
});
# Break out of "aeson <1.3, temporary <1.3".
stack = generateOptparseApplicativeCompletion "stack" (doJailbreak super.stack);

# https://github.com/pikajude/stylish-cabal/issues/11
stylish-cabal = super.stylish-cabal.override { hspec = self.hspec_2_4_8; hspec-core = self.hspec-core_2_4_8; };
Expand Down Expand Up @@ -1112,6 +1133,9 @@ self: super: {
# https://github.com/snapframework/xmlhtml/pull/37
xmlhtml = doJailbreak super.xmlhtml;

# Generate shell completions
purescript = generateOptparseApplicativeCompletion "purs" super.purescript;

# https://github.com/NixOS/nixpkgs/issues/46467
safe-money-aeson = super.safe-money-aeson.overrideScope (self: super: { safe-money = self.safe-money_0_7; });
safe-money-store = super.safe-money-store.overrideScope (self: super: { safe-money = self.safe-money_0_7; });
Expand Down
44 changes: 40 additions & 4 deletions pkgs/development/haskell-modules/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,24 @@ rec {
in
builtins.listToAttrs (map toKeyVal haskellPaths);

# Modify a Haskell package to add completion scripts for the given executable
# produced by it. These completion scripts will be picked up automatically if
# the resulting derivation is installed, e.g. by `nix-env -i`.
addOptparseApplicativeCompletionScripts = exeName: pkg: overrideCabal pkg (drv: {
addOptparseApplicativeCompletionScripts = exeName: pkg:
builtins.trace "addOptparseApplicativeCompletionScripts is deprecated in favor of generateOptparseApplicativeCompletion. Please change ${pkg.name} to use the latter or its plural form."
(generateOptparseApplicativeCompletion exeName pkg);

/*
Modify a Haskell package to add shell completion scripts for the
given executable produced by it. These completion scripts will be
picked up automatically if the resulting derivation is installed,
e.g. by `nix-env -i`.

Invocation:
generateOptparseApplicativeCompletions command pkg


command: name of an executable
pkg: Haskell package that builds the executables
*/
generateOptparseApplicativeCompletion = exeName: pkg: overrideCabal pkg (drv: {
postInstall = (drv.postInstall or "") + ''
bashCompDir="$out/share/bash-completion/completions"
zshCompDir="$out/share/zsh/vendor-completions"
Expand All @@ -367,6 +381,28 @@ rec {
"$out/bin/${exeName}" --bash-completion-script "$out/bin/${exeName}" >"$bashCompDir/${exeName}"
"$out/bin/${exeName}" --zsh-completion-script "$out/bin/${exeName}" >"$zshCompDir/_${exeName}"
"$out/bin/${exeName}" --fish-completion-script "$out/bin/${exeName}" >"$fishCompDir/${exeName}.fish"

# Sanity check
grep -F ${exeName} <$bashCompDir/${exeName} >/dev/null || {
echo 'Could not find ${exeName} in completion script.'
exit 1
}
'';
});

/*
Modify a Haskell package to add shell completion scripts for the
given executables produced by it. These completion scripts will be
picked up automatically if the resulting derivation is installed,
e.g. by `nix-env -i`.

Invocation:
generateOptparseApplicativeCompletions commands pkg


commands: name of an executable
pkg: Haskell package that builds the executables
*/
generateOptparseApplicativeCompletions = commands: pkg:
pkgs.lib.foldr generateOptparseApplicativeCompletion pkg commands;
}
2 changes: 1 addition & 1 deletion pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ with pkgs;

cue2pops = callPackage ../tools/cd-dvd/cue2pops { };

cabal2nix = haskell.lib.overrideCabal (haskell.lib.addOptparseApplicativeCompletionScripts "cabal2nix" haskellPackages.cabal2nix) (drv: {
cabal2nix = haskell.lib.overrideCabal (haskell.lib.generateOptparseApplicativeCompletion "cabal2nix" haskellPackages.cabal2nix) (drv: {
isLibrary = false;
enableSharedExecutables = false;
executableToolDepends = (drv.executableToolDepends or []) ++ [ makeWrapper ];
Expand Down