From 360fd2099de0f6ca84d825eff4e5a1541f233fd5 Mon Sep 17 00:00:00 2001 From: Archit Gupta Date: Sun, 25 Feb 2024 18:40:05 -0800 Subject: [PATCH] Allow devShells to be directly set to derivations --- API_GUIDE.md | 8 ++++---- builtinModules/devShells.nix | 7 +++++-- tests/default.nix | 17 +++++++++++++++-- 3 files changed, 24 insertions(+), 8 deletions(-) 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 ];