Skip to content

Commit

Permalink
mkshell: improve mergeInputs
Browse files Browse the repository at this point in the history
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 <nixpkgs> {};

    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.

(cherry picked from commit cee3573)
  • Loading branch information
basvandijk committed Jun 24, 2019
1 parent 53346d7 commit e65b6ff
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions pkgs/build-support/mkshell/default.nix
Expand Up @@ -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"
Expand Down

0 comments on commit e65b6ff

Please sign in to comment.