mirror of
https://github.com/nix-community/flakelight.git
synced 2025-02-08 13:39:29 +01:00
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) foldl mapAttrsToList mkOption mkIf recursiveUpdate;
|
||||||
inherit (lib.types) attrs lazyAttrsOf;
|
inherit (lib.types) attrs lazyAttrsOf;
|
||||||
inherit (flakelight) selectAttr;
|
inherit (flakelight) selectAttr;
|
||||||
inherit (flakelight.types) optFunctionTo;
|
inherit (flakelight.types) optCallWith;
|
||||||
|
|
||||||
isHome = x: x ? activationPackage;
|
isHome = x: x ? activationPackage;
|
||||||
|
|
||||||
@ -29,14 +29,12 @@ let
|
|||||||
);
|
);
|
||||||
|
|
||||||
configs = mapAttrs
|
configs = mapAttrs
|
||||||
(name: f:
|
(name: cfg: if isHome cfg then cfg else mkHome name cfg)
|
||||||
let val = f moduleArgs; in
|
|
||||||
if isHome val then val else mkHome name val)
|
|
||||||
config.homeConfigurations;
|
config.homeConfigurations;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.homeConfigurations = mkOption {
|
options.homeConfigurations = mkOption {
|
||||||
type = lazyAttrsOf (optFunctionTo attrs);
|
type = lazyAttrsOf (optCallWith moduleArgs attrs);
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ let
|
|||||||
inherit (lib) foldl mapAttrsToList mkIf mkOption recursiveUpdate;
|
inherit (lib) foldl mapAttrsToList mkIf mkOption recursiveUpdate;
|
||||||
inherit (lib.types) attrs lazyAttrsOf;
|
inherit (lib.types) attrs lazyAttrsOf;
|
||||||
inherit (flakelight) selectAttr;
|
inherit (flakelight) selectAttr;
|
||||||
inherit (flakelight.types) optFunctionTo;
|
inherit (flakelight.types) optCallWith;
|
||||||
|
|
||||||
# Avoid checking if toplevel is a derivation as it causes the nixos modules
|
# Avoid checking if toplevel is a derivation as it causes the nixos modules
|
||||||
# to be evaluated.
|
# to be evaluated.
|
||||||
@ -23,14 +23,12 @@ let
|
|||||||
});
|
});
|
||||||
|
|
||||||
configs = mapAttrs
|
configs = mapAttrs
|
||||||
(hostname: f:
|
(hostname: cfg: if isNixos cfg then cfg else mkNixos hostname cfg)
|
||||||
let val = f moduleArgs; in
|
|
||||||
if isNixos val then val else mkNixos hostname val)
|
|
||||||
config.nixosConfigurations;
|
config.nixosConfigurations;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.nixosConfigurations = mkOption {
|
options.nixosConfigurations = mkOption {
|
||||||
type = lazyAttrsOf (optFunctionTo attrs);
|
type = lazyAttrsOf (optCallWith moduleArgs attrs);
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,6 +92,9 @@ let
|
|||||||
|
|
||||||
optFunctionTo = elemType: coercedTo elemType (x: _: x)
|
optFunctionTo = elemType: coercedTo elemType (x: _: x)
|
||||||
(functionTo elemType);
|
(functionTo elemType);
|
||||||
|
|
||||||
|
optCallWith = args: elemType: coercedTo (functionTo elemType) (x: x args)
|
||||||
|
elemType;
|
||||||
};
|
};
|
||||||
|
|
||||||
supportedSystem = { lib, stdenv, ... }:
|
supportedSystem = { lib, stdenv, ... }:
|
||||||
|
Loading…
Reference in New Issue
Block a user