Allow configuring the stdenv for devShell

This commit is contained in:
Archit Gupta 2023-12-05 01:00:35 -08:00
parent 366733be87
commit a4e4a341f2
3 changed files with 26 additions and 13 deletions

View File

@ -368,6 +368,9 @@ access packages.
attribute set mapping variables to values. It can optionally be a function to
such an attribute set in order to access packages.
`devShell.stdenv` allows changing the stdenv used for the shell. It is a
function that takes the package set and returns the stdenv to use.
For example, these can be configured as follows:
```nix
@ -386,6 +389,7 @@ For example, these can be configured as follows:
'';
# Set an environment var. `env` can be an be a function
env.TEST_VAR = "test value";
stdenv = pkgs: pkgs.clangStdenv;
};
};
}

View File

@ -35,6 +35,11 @@ in
(optFunctionTo (lazyAttrsOf str));
default = null;
};
stdenv = mkOption {
type = nullOr (functionTo package);
default = null;
};
};
devShells = mkOption {
@ -45,19 +50,22 @@ in
config = mkMerge [
(mkIf (any (x: x != null) (attrValues config.devShell)) {
devShells.default = mkDefault ({ pkgs, mkShell }: mkShell (
optionalAttrs (config.devShell.env != null)
(config.devShell.env pkgs)
// optionalAttrs (config.devShell.inputsFrom != null) {
inputsFrom = config.devShell.inputsFrom pkgs;
}
// optionalAttrs (config.devShell.packages != null) {
packages = config.devShell.packages pkgs;
}
// optionalAttrs (config.devShell.shellHook != null) {
shellHook = config.devShell.shellHook pkgs;
}
));
devShells.default = mkDefault ({ pkgs, mkShell }: mkShell.override
(if config.devShell.stdenv == null then { }
else { stdenv = config.devShell.stdenv pkgs; })
(
optionalAttrs (config.devShell.env != null)
(config.devShell.env pkgs)
// optionalAttrs (config.devShell.inputsFrom != null) {
inputsFrom = config.devShell.inputsFrom pkgs;
}
// optionalAttrs (config.devShell.packages != null) {
packages = config.devShell.packages pkgs;
}
// optionalAttrs (config.devShell.shellHook != null) {
shellHook = config.devShell.shellHook pkgs;
}
));
})
(mkIf (config.devShells != { }) {

View File

@ -284,6 +284,7 @@ in
echo Welcome to example shell!
'';
env.TEST_VAR = "test value";
stdenv = pkgs: pkgs.clangStdenv;
};
})
(f: lib.isDerivation f.devShells.x86_64-linux.default);