From 76ef802d3d60cc4d199f19ba69e8bcfe63b88e7b Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Sun, 23 Jun 2019 21:11:49 +0200 Subject: mkShell: compose shellHooks Running the following expression with nix-shell: let pkgs = import {}; shell1 = pkgs.mkShell { shellHook = '' echo shell1 ''; }; shell2 = pkgs.mkShell { shellHook = '' echo shell2 ''; }; shell3 = pkgs.mkShell { inputsFrom = [ shell1 shell2 ]; shellHook = '' echo shell3 ''; }; in shell3 Will now results in: shell2 shell1 shell3 Note that packages in the front of inputsFrom have precedence over packages in the back. The outermost mkShell has precedence over all. --- pkgs/build-support/mkshell/default.nix | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/mkshell/default.nix b/pkgs/build-support/mkshell/default.nix index a98b4affacba..698974590880 100644 --- a/pkgs/build-support/mkshell/default.nix +++ b/pkgs/build-support/mkshell/default.nix @@ -25,6 +25,7 @@ let "nativeBuildInputs" "propagatedBuildInputs" "propagatedNativeBuildInputs" + "shellHook" ]; in @@ -37,6 +38,9 @@ stdenv.mkDerivation ({ propagatedBuildInputs = mergeInputs "propagatedBuildInputs"; propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs"; + shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook" + (lib.reverseList inputsFrom ++ [attrs])); + nobuildPhase = '' echo echo "This derivation is not meant to be built, aborting"; -- cgit 1.4.1 From cee35739ff0800f5738ecbedb43c356a2f06c96f Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Sun, 23 Jun 2019 21:39:29 +0200 Subject: mkshell: improve mergeInputs mergeInputs is now simply defined in terms of `concatLists` and `catAttrs` instead of a more complicated `foldr`. Note that the order of PATH has also changed. For example running the following with nix-shell: let pkgs = import {}; shell1 = pkgs.mkShell { buildInputs = [ pkgs.htop ]; }; shell2 = pkgs.mkShell { buildInputs = [ pkgs.hello ]; }; shell3 = pkgs.mkShell { inputsFrom = [ shell1 shell2 ]; buildInputs = [ pkgs.tree ]; }; in shell3 Results in the following PATH: $ echo $PATH ... /nix/store/yifq4bikf7m07160bpia7z48ciqddbfi-tree-1.8.0/bin: /nix/store/vhxqk81234ivqw1a7j200a1c69k8mywi-htop-2.2.0/bin: /nix/store/n9vm3m58y1n3rg3mlll17wanc9hln58k-hello-2.10/bin ... Previously the order was: /nix/store/n9vm3m58y1n3rg3mlll17wanc9hln58k-hello-2.10/bin /nix/store/vhxqk81234ivqw1a7j200a1c69k8mywi-htop-2.2.0/bin: /nix/store/yifq4bikf7m07160bpia7z48ciqddbfi-tree-1.8.0/bin: I think the new order makes more sense because it allows to override the PATH in the outermost mkShell. --- pkgs/build-support/mkshell/default.nix | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/mkshell/default.nix b/pkgs/build-support/mkshell/default.nix index 698974590880..a70dc0390cb5 100644 --- a/pkgs/build-support/mkshell/default.nix +++ b/pkgs/build-support/mkshell/default.nix @@ -11,13 +11,8 @@ ... }@attrs: let - mergeInputs = name: - let - op = item: sum: sum ++ item."${name}" or []; - nul = []; - list = [attrs] ++ inputsFrom; - in - lib.foldr op nul list; + mergeInputs = name: lib.concatLists (lib.catAttrs name + ([attrs] ++ inputsFrom)); rest = builtins.removeAttrs attrs [ "inputsFrom" -- cgit 1.4.1