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:
parent
1d92662d82
commit
f2c32f5a42
@ -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 = { };
|
||||
};
|
||||
|
||||
|
@ -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 = { };
|
||||
};
|
||||
|
||||
|
@ -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, ... }:
|
||||
|
Loading…
Reference in New Issue
Block a user