Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Commit

Permalink
mkShell: compose shellHooks
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit 76ef802)
  • Loading branch information
basvandijk committed Jun 24, 2019
1 parent e65b6ff commit 0004631
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkgs/build-support/mkshell/default.nix
Expand Up @@ -20,6 +20,7 @@ let
"nativeBuildInputs"
"propagatedBuildInputs"
"propagatedNativeBuildInputs"
"shellHook"
];
in

Expand All @@ -32,6 +33,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";
Expand Down

0 comments on commit 0004631

Please sign in to comment.