Skip to content

Commit

Permalink
Add completions to nix-shell
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Jul 8, 2020
1 parent 63812f7 commit 6867e29
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
11 changes: 11 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ let
};
CARDANO_NODE_CONFIGS = cardano-node.deployments;
meta.platforms = lib.platforms.unix;
shellHook = ''
setup_completion() {
local p
for p in $buildInputs; do
if [ -d "$p/share/bash-completion" ]; then
addToSearchPath XDG_DATA_DIRS "$p/share"
fi
done
}
setup_completion
'';
};
stackShell = import ./nix/stack-shell.nix {
walletPackages = self;
Expand Down
46 changes: 38 additions & 8 deletions nix/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ let
# provide cardano-node command to test suites
unit.build-tools = [ pkgs.cardano-node ];
integration.build-tools = [ pkgs.cardano-node ];
unit.postInstall = exePostInstall;
unit.postInstall = libSodiumPostInstall;
};
packages.cardano-wallet-shelley.components.tests = {
# Only run integration tests on non-PR jobsets. Note that
Expand All @@ -107,9 +107,8 @@ let
# provide cardano-node & cardano-cli to tests
unit.build-tools = [ pkgs.cardano-node pkgs.cardano-cli ];
integration.build-tools = [ pkgs.cardano-node pkgs.cardano-cli ];
unit.postInstall = exePostInstall;
unit.postInstall = libSodiumPostInstall;
};
packages.cardano-wallet-shelley.components.exes.cardano-wallet-shelley.postInstall = exePostInstall;

packages.cardano-wallet-jormungandr.components.tests = {
# Next releases are going to be about cardano-node and we
Expand All @@ -125,10 +124,6 @@ let
unit.build-tools = [ jmPkgs.jormungandr ];
};

# Make sure that libsodium DLLs are available.
packages.cardano-wallet-byron.components.library.postInstall = exePostInstall;
packages.cardano-wallet-shelley.components.library.postInstall = exePostInstall;

# Add jormungandr to the PATH of the latency benchmark
packages.cardano-wallet-jormungandr.components.benchmarks.latency =
lib.optionalAttrs (!stdenv.hostPlatform.isWindows) {
Expand Down Expand Up @@ -164,12 +159,32 @@ let
'';
};


# Make sure that libsodium DLLs and shell completions are available .
packages.cardano-wallet-byron.components.exes.cardano-wallet-byron.postInstall = optparseCompletionPostInstall;
packages.cardano-wallet-shelley.components.exes.cardano-wallet-shelley.postInstall = optparseCompletionPostInstall + libSodiumPostInstall;
packages.cardano-wallet-jormungandr.components.exes.cardano-wallet-jormungandr.postInstall = optparseCompletionPostInstall;

# Workaround for Haskell.nix issue
packages.cardano-wallet-byron.components.all.postInstall = lib.mkForce "";
packages.cardano-wallet-jormungandr.components.all.postInstall = lib.mkForce "";
packages.cardano-wallet-shelley.components.all.postInstall = lib.mkForce "";
}

{
# Add shell completions for tools.
packages.cardano-node.components.exes.cardano-cli.postInstall = optparseCompletionPostInstall + libSodiumPostInstall;
packages.cardano-node.components.exes.cardano-node.postInstall = optparseCompletionPostInstall + libSodiumPostInstall;
packages.cardano-addresses.components.exes.cardano-address.postInstall = optparseCompletionPostInstall;
packages.cardano-transactions.components.exes.cardano-tx.postInstall = optparseCompletionPostInstall;
packages.bech32.components.exes.bech32.postInstall = optparseCompletionPostInstall;
# Workaround for Haskell.nix issue
packages.cardano-node.components.all.postInstall = lib.mkForce "";
packages.cardano-addresses.components.all.postInstall = lib.mkForce "";
packages.cardano-transactions.components.all.postInstall = lib.mkForce "";
packages.bech32.components.all.postInstall = lib.mkForce "";
}

# Provide the swagger file in an environment variable for
# tests because it is located outside of the Cabal package
# source tree.
Expand Down Expand Up @@ -282,9 +297,24 @@ let

# Make sure that the libsodium DLL is available beside the EXEs of
# the windows build.
exePostInstall = lib.optionalString stdenv.hostPlatform.isWindows ''
libSodiumPostInstall = lib.optionalString stdenv.hostPlatform.isWindows ''
ln -s ${pkgs.libsodium}/bin/libsodium-23.dll $out/bin
'';

# This exe component postInstall script adds shell completion
# scripts. These completion
# scripts will be picked up automatically if the resulting
# derivation is installed, e.g. by `nix-env -i`.
optparseCompletionPostInstall = lib.optionalString stdenv.hostPlatform.isUnix ''
exeName=$(ls -1 $out/bin | head -n1) # fixme add $exeName to Haskell.nix
bashCompDir="$out/share/bash-completion/completions"
zshCompDir="$out/share/zsh/vendor-completions"
fishCompDir="$out/share/fish/vendor_completions.d"
mkdir -p "$bashCompDir" "$zshCompDir" "$fishCompDir"
"$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"
'';

in
pkgSet.config.hsPkgs // { _config = pkgSet.config; }

0 comments on commit 6867e29

Please sign in to comment.