summary refs log tree commit diff
path: root/pkgs/build-support/mkshell/default.nix
diff options
context:
space:
mode:
authorBas van Dijk <v.dijk.bas@gmail.com>2019-06-23 21:11:49 +0200
committerBas van Dijk <v.dijk.bas@gmail.com>2019-06-23 22:13:57 +0200
commit76ef802d3d60cc4d199f19ba69e8bcfe63b88e7b (patch)
tree69818ff85afb45eb3cdae85f8e3849a0c104be07 /pkgs/build-support/mkshell/default.nix
parentba7e7aed08740f5a33e3ef1fa56e4c591af85dc0 (diff)
downloadnixpkgs-76ef802d3d60cc4d199f19ba69e8bcfe63b88e7b.tar
nixpkgs-76ef802d3d60cc4d199f19ba69e8bcfe63b88e7b.tar.gz
nixpkgs-76ef802d3d60cc4d199f19ba69e8bcfe63b88e7b.tar.bz2
nixpkgs-76ef802d3d60cc4d199f19ba69e8bcfe63b88e7b.tar.lz
nixpkgs-76ef802d3d60cc4d199f19ba69e8bcfe63b88e7b.tar.xz
nixpkgs-76ef802d3d60cc4d199f19ba69e8bcfe63b88e7b.tar.zst
nixpkgs-76ef802d3d60cc4d199f19ba69e8bcfe63b88e7b.zip
mkShell: compose shellHooks
Running the following expression with nix-shell:

  let
    pkgs = import <nixpkgs> {};

    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.
Diffstat (limited to 'pkgs/build-support/mkshell/default.nix')
-rw-r--r--pkgs/build-support/mkshell/default.nix4
1 files changed, 4 insertions, 0 deletions
diff --git a/pkgs/build-support/mkshell/default.nix b/pkgs/build-support/mkshell/default.nix
index a98b4affacb..69897459088 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";