1
1
forked from extern/flakelight

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
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:
```nix
@ -397,7 +400,7 @@ For example, these can be configured as follows:
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
{

View File

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

View File

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