1
1
forked from extern/flakelight

Add optCallWith type for optional calling

optFunctionTo results in a function which needs to be called when using
the option value. This is needed when the argument is not known when
building types (such as with pkgs). When the args are known (for
example, moduleArgs), this leads to more complex code than just calling
the function and resulting in the target type. optCallWith does the
latter.
This commit is contained in:
Archit Gupta 2024-01-14 19:05:39 -08:00
parent 1d92662d82
commit f2c32f5a42
3 changed files with 9 additions and 10 deletions

View File

@ -8,7 +8,7 @@ let
inherit (lib) foldl mapAttrsToList mkOption mkIf recursiveUpdate;
inherit (lib.types) attrs lazyAttrsOf;
inherit (flakelight) selectAttr;
inherit (flakelight.types) optFunctionTo;
inherit (flakelight.types) optCallWith;
isHome = x: x ? activationPackage;
@ -29,14 +29,12 @@ let
);
configs = mapAttrs
(name: f:
let val = f moduleArgs; in
if isHome val then val else mkHome name val)
(name: cfg: if isHome cfg then cfg else mkHome name cfg)
config.homeConfigurations;
in
{
options.homeConfigurations = mkOption {
type = lazyAttrsOf (optFunctionTo attrs);
type = lazyAttrsOf (optCallWith moduleArgs attrs);
default = { };
};

View File

@ -8,7 +8,7 @@ let
inherit (lib) foldl mapAttrsToList mkIf mkOption recursiveUpdate;
inherit (lib.types) attrs lazyAttrsOf;
inherit (flakelight) selectAttr;
inherit (flakelight.types) optFunctionTo;
inherit (flakelight.types) optCallWith;
# Avoid checking if toplevel is a derivation as it causes the nixos modules
# to be evaluated.
@ -23,14 +23,12 @@ let
});
configs = mapAttrs
(hostname: f:
let val = f moduleArgs; in
if isNixos val then val else mkNixos hostname val)
(hostname: cfg: if isNixos cfg then cfg else mkNixos hostname cfg)
config.nixosConfigurations;
in
{
options.nixosConfigurations = mkOption {
type = lazyAttrsOf (optFunctionTo attrs);
type = lazyAttrsOf (optCallWith moduleArgs attrs);
default = { };
};

View File

@ -92,6 +92,9 @@ let
optFunctionTo = elemType: coercedTo elemType (x: _: x)
(functionTo elemType);
optCallWith = args: elemType: coercedTo (functionTo elemType) (x: x args)
elemType;
};
supportedSystem = { lib, stdenv, ... }: