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 attribute set mapping variables to values. It can optionally be a function to
such an attribute set in order to access packages. 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: For example, these can be configured as follows:
```nix ```nix
@ -386,6 +389,7 @@ For example, these can be configured as follows:
''; '';
# Set an environment var. `env` can be an be a function # Set an environment var. `env` can be an be a function
env.TEST_VAR = "test value"; env.TEST_VAR = "test value";
stdenv = pkgs: pkgs.clangStdenv;
}; };
}; };
} }

View File

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

View File

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