packages: implement projectShells option, convert devShells to projectShells

This commit is contained in:
Max Headroom 2022-07-31 15:42:56 +02:00
parent 1b40e420a3
commit a7a03c254e
3 changed files with 71 additions and 41 deletions

View file

@ -1,34 +0,0 @@
{ inputs', pkgs, ... }:
let
inherit (inputs'.devshell.legacyPackages) mkShell;
wrapInAttrs = value: if builtins.isAttrs value then value else { inherit value; };
wrapPackage = package: { inherit package; };
injectAttrName = name: value: { inherit name; } // wrapInAttrs value;
mkNamedAttrs = builtins.mapAttrs injectAttrName;
attrsToNamedList = attrs: builtins.attrValues (mkNamedAttrs attrs);
in
{
packages ? [],
tools ? [],
commands ? {},
env ? {},
config ? {}
}:
mkShell {
imports = [
config
{
commands = map wrapPackage tools;
}
{
inherit packages;
commands = attrsToNamedList commands;
env = attrsToNamedList env;
}
];
}

View file

@ -0,0 +1,67 @@
{ lib, config, inputs', ... }:
with lib;
let
inherit (inputs'.devshell.legacyPackages) mkShell;
wrapInAttrs = value: if builtins.isAttrs value then value else { inherit value; };
wrapPackage = package: { inherit package; };
injectAttrName = name: value: { inherit name; } // wrapInAttrs value;
mkNamedAttrs = builtins.mapAttrs injectAttrName;
attrsToNamedList = attrs: builtins.attrValues (mkNamedAttrs attrs);
mkProjectShell =
{
packages ? [],
tools ? [],
commands ? {},
env ? {},
config ? {}
}:
mkShell {
imports = [
config
{
commands = map wrapPackage tools;
}
{
inherit packages;
commands = attrsToNamedList commands;
env = attrsToNamedList env;
}
];
};
in {
options.projectShells = mkOption {
default = {};
type = types.attrsOf (types.submodule {
options = {
packages = mkOption {
default = [];
type = types.listOf types.package;
};
tools = mkOption {
default = [];
type = types.listOf types.package;
};
commands = mkOption {
default = {};
type = types.attrsOf types.package;
};
env = mkOption {
default = {};
type = with types; attrsOf (oneOf [ attrs str ] );
};
config = mkOption {
default = {};
type = types.anything;
};
};
});
};
config.devShells = mapAttrs (_: mkProjectShell) config.projectShells;
}

View file

@ -19,14 +19,11 @@
defaultPoetryOverrides = prev.defaultPoetryOverrides.extend (import ./poetry2nix-overrides);
});
mkShell = import lib/devshell.nix {
inherit inputs' pkgs;
};
in
{
imports = [
./tests
./modules/devshell.nix
];
packages = filters.doFilter filters.packages rec {
ghost = let
@ -84,10 +81,10 @@
stevenblack-hosts = pkgs.callPackage ./data/stevenblack { inherit pins; };
};
devShells = {
projectShells = {
default = let
flakePkgs = self'.packages;
in mkShell {
in {
tools = with flakePkgs; [
agenix
deploy-rs
@ -99,7 +96,7 @@
};
reflex-cache = let
inherit (self'.packages) reflex-cache;
in mkShell {
in {
packages = [
reflex-cache.dependencyEnv
];