Merge multilple shell.nix files using mkShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {} }: | |
pkgs.mkShell { | |
buildInputs = [ | |
pkgs.hello | |
]; | |
shellHook = '' | |
echo env1 | |
''; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {} }: | |
pkgs.mkShell { | |
buildInputs = [ | |
pkgs.vim | |
]; | |
shellHook = '' | |
echo env2 | |
''; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
pkgs = import <nixpkgs> {}; | |
lib = pkgs.lib; | |
env1 = import ./env1-shell.nix { inherit pkgs; }; | |
env2 = import ./env2-shell.nix { inherit pkgs; }; | |
mergeEnvs = envs: pkgs.mkShell (builtins.foldl' (a: v: { | |
buildInputs = a.buildInputs ++ v.buildInputs; | |
nativeBuildInputs = a.nativeBuildInputs ++ v.nativeBuildInputs; | |
propagatedBuildInputs = a.propagatedBuildInputs ++ v.propagatedBuildInputs; | |
propagatedNativeBuildInputs = a.propagatedNativeBuildInputs ++ v.propagatedNativeBuildInputs; | |
shellHook = a.shellHook + "\n" + v.shellHook; | |
}) (pkgs.mkShell {}) envs); | |
in mergeEnvs [ env1 env2 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment