diff --git a/API_GUIDE.md b/API_GUIDE.md index b6fde0d..ecb9a3b 100644 --- a/API_GUIDE.md +++ b/API_GUIDE.md @@ -439,7 +439,7 @@ To use the first example, but manually specify the package name: ``` Type: - devShell: Cfg | (Pkgs -> Cfg) | PackageDef + devShell: Cfg | (Pkgs -> Cfg) | PackageDef | Derivation | (Pkgs -> Derivation) Cfg.packages: [Derivation] | (Pkgs -> [Derivation]) Cfg.inputsFrom: [Derivation] | (Pkgs -> [Derivation]) Cfg.shellHook: Str | (Pkgs -> Str) @@ -451,11 +451,11 @@ The devshell options allow you to configure `devShells.${system}.default`. It is split up into options in order to enable multiple modules to contribute to its configuration. -`devShell` can alternatively be set to a package definition, which is then used -as the default shell, overriding other options. +`devShell` can alternatively be set to a package definition or derivation, which +is then used as the default shell, overriding other options. `devShell` can also be set to a function that takes the package set and returns -an attrSet of the devShell configuration options. +an attrSet of the devShell configuration options or a derivation. The options available are as follows: diff --git a/builtinModules/devShells.nix b/builtinModules/devShells.nix index 751e02e..7c07655 100644 --- a/builtinModules/devShells.nix +++ b/builtinModules/devShells.nix @@ -47,10 +47,13 @@ let let val = pkgs.callPackage fn { }; in if (functionArgs fn == { }) || !(package.check val) then fn pkgs - else { overrideShell = val; }; + else val; + + packageOverride = p: { overrideShell = p; }; devShellType = coercedTo function wrapFn - (optFunctionTo (submodule devShellModule)); + (optFunctionTo (coercedTo package packageOverride + (submodule devShellModule))); genDevShell = pkgs: cfg: if cfg.overrideShell != null then cfg.overrideShell diff --git a/tests/default.nix b/tests/default.nix index eab35f8..bd773d1 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -324,13 +324,13 @@ in }) (f: lib.isDerivation f.devShells.x86_64-linux.default); - devShell-override = test + devShell-pkgDef = test (flakelight ./empty { devShell = { mkShell }: mkShell { }; }) (f: lib.isDerivation f.devShells.x86_64-linux.default); - devShell-override-empty = test + devShell-pkgDef-empty = test (flakelight ./empty { disabledModules = [ "builtinFormatters.nix" ]; devShell = { mkShell }: mkShell { }; @@ -365,6 +365,19 @@ in }) (f: lib.isDerivation f.devShells.x86_64-linux.default); + devShell-pkg = test + (flakelight ./empty ({ inputs, ... }: { + systems = [ "x86_64-linux" ]; + devShell = inputs.nixpkgs.legacyPackages.x86_64-linux.hello; + })) + (f: lib.isDerivation f.devShells.x86_64-linux.default); + + devShell-pkg-fn = test + (flakelight ./empty { + devShell = pkgs: pkgs.hello; + }) + (f: lib.isDerivation f.devShells.x86_64-linux.default); + devShells = test (flakelight ./empty { devShell.inputsFrom = pkgs: [ pkgs.emacs ];