diff --git a/API_GUIDE.md b/API_GUIDE.md index 8616b85..eaecd26 100644 --- a/API_GUIDE.md +++ b/API_GUIDE.md @@ -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; }; }; } diff --git a/builtinModules/devShells.nix b/builtinModules/devShells.nix index a554d87..395590c 100644 --- a/builtinModules/devShells.nix +++ b/builtinModules/devShells.nix @@ -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 != { }) { diff --git a/tests/default.nix b/tests/default.nix index eaf9ec7..365f83a 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -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);