Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Merge multilple shell.nix files using mkShell
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = [
pkgs.hello
];
shellHook = ''
echo env1
'';
}
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = [
pkgs.vim
];
shellHook = ''
echo env2
'';
}
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
You can’t perform that action at this time.