Skip to content

Instantly share code, notes, and snippets.

@adisbladis
Created July 17, 2019 11:53
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
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