Allow devShell to be set to a package definition

This commit is contained in:
Archit Gupta 2023-12-05 19:44:12 -08:00
parent b094ced95d
commit 8f3bfc39aa
3 changed files with 56 additions and 38 deletions

View File

@ -371,6 +371,9 @@ such an attribute set in order to access packages.
`devShell.stdenv` allows changing the stdenv used for the shell. It is a `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. function that takes the package set and returns the stdenv to use.
`devShell` can alternatively be set to a package definition, which is then used
as the default shell, overriding the above options.
For example, these can be configured as follows: For example, these can be configured as follows:
```nix ```nix
@ -397,7 +400,7 @@ For example, these can be configured as follows:
The above exports `devShells.${system}.default` outputs. The above exports `devShells.${system}.default` outputs.
To add build inputs of one of your packages, you can do as follows: To add the build inputs of one of your packages, you can do as follows:
```nix ```nix
{ {

View File

@ -5,17 +5,12 @@
{ config, lib, flakelight, ... }: { config, lib, flakelight, ... }:
let let
inherit (lib) filterAttrs mapAttrs mkDefault mkIf mkMerge mkOption; inherit (lib) filterAttrs mapAttrs mkDefault mkIf mkMerge mkOption;
inherit (lib.types) functionTo lazyAttrsOf lines listOf nullOr package str inherit (lib.types) coercedTo functionTo lazyAttrsOf lines listOf nullOr
submodule; package str submodule;
inherit (flakelight) supportedSystem; inherit (flakelight) supportedSystem;
inherit (flakelight.types) optFunctionTo packageDef; inherit (flakelight.types) optFunctionTo packageDef;
in
{ devShellModule.options = {
options = {
devShell = mkOption {
default = null;
type = nullOr (submodule {
options = {
inputsFrom = mkOption { inputsFrom = mkOption {
type = functionTo (listOf package); type = functionTo (listOf package);
default = _: [ ]; default = _: [ ];
@ -40,8 +35,21 @@ in
type = functionTo package; type = functionTo package;
default = pkgs: pkgs.stdenv; default = pkgs: pkgs.stdenv;
}; };
overrideShell = mkOption {
type = nullOr packageDef;
internal = true;
default = null;
}; };
}); };
in
{
options = {
devShell = mkOption {
default = null;
type = nullOr (coercedTo packageDef
(x: { overrideShell = x; })
(submodule devShellModule));
}; };
devShells = mkOption { devShells = mkOption {
@ -53,12 +61,13 @@ in
config = mkMerge [ config = mkMerge [
(mkIf (config.devShell != null) { (mkIf (config.devShell != null) {
devShells.default = mkDefault ({ pkgs, mkShell }: devShells.default = mkDefault ({ pkgs, mkShell }:
mkShell.override { stdenv = config.devShell.stdenv pkgs; } let cfg = mapAttrs (_: v: v pkgs) config.devShell; in
((config.devShell.env pkgs) // { mkShell.override { inherit (cfg) stdenv; }
inputsFrom = config.devShell.inputsFrom pkgs; (cfg.env // { inherit (cfg) inputsFrom packages shellHook; }));
packages = config.devShell.packages pkgs; })
shellHook = config.devShell.shellHook pkgs;
})); (mkIf (config.devShell.overrideShell or null != null) {
devShells.default = config.devShell.overrideShell;
}) })
(mkIf (config.devShells != { }) { (mkIf (config.devShells != { }) {

View File

@ -298,7 +298,7 @@ in
devShell-override = test devShell-override = test
(flakelight ./empty { (flakelight ./empty {
devShells.default = { mkShell }: mkShell { }; devShell = { mkShell }: mkShell { };
}) })
(f: f ? devShells.x86_64-linux.default); (f: f ? devShells.x86_64-linux.default);
@ -314,6 +314,12 @@ in
&& (f ? devShells.x86_64-linux.shell1) && (f ? devShells.x86_64-linux.shell1)
&& (f ? devShells.x86_64-linux.shell2)); && (f ? devShells.x86_64-linux.shell2));
devShells-override = test
(flakelight ./empty {
devShells.default = { mkShell }: mkShell { };
})
(f: f ? devShells.x86_64-linux.default);
overlay = test overlay = test
(flakelight ./empty { (flakelight ./empty {
overlay = final: prev: { testValue = "hello"; }; overlay = final: prev: { testValue = "hello"; };