mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-26 12:53:59 +03:00
Add heterogeneousAttrsOf option type
It is parameterized by a function that takes a name and evaluates to the option type for the attribute of that name. Together with submoduleWithExtraArgs, this subsumes nixosSubmodule.
This commit is contained in:
parent
8764758044
commit
3f70dabad3
@ -124,6 +124,17 @@ rec {
|
||||
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name>"]);
|
||||
};
|
||||
|
||||
heterogeneousAttrsOf = elemTypeFn: mkOptionType {
|
||||
name = "attribute set of values of many types, including ${(elemTypeFn "<name>").name}";
|
||||
check = x: isAttrs x && all (name: (elemTypeFn name).check (getAttr name x)) (attrNames x);
|
||||
merge = loc: defs:
|
||||
zipAttrsWith (name: (elemTypeFn name).merge (loc ++ [name]))
|
||||
# Push down position info.
|
||||
(map (def: listToAttrs (mapAttrsToList (n: def':
|
||||
{ name = n; value = { inherit (def) file; value = def'; }; }) def.value)) defs);
|
||||
getSubOptions = prefix: (elemTypeFn "<name>").getSubOptions (prefix ++ ["<name>"]);
|
||||
};
|
||||
|
||||
# List or attribute set of ...
|
||||
loaOf = elemType:
|
||||
let
|
||||
@ -198,25 +209,6 @@ rec {
|
||||
|
||||
submodule = submoduleWithExtraArgs {};
|
||||
|
||||
nixosSubmodule = nixos: args: mkOptionType rec {
|
||||
name = "submodule containing a NixOS config";
|
||||
check = x: isAttrs x || isFunction x;
|
||||
merge = loc: defs:
|
||||
let
|
||||
coerce = def: if isFunction def then def else { config = def; };
|
||||
in (import (nixos + "/lib/eval-config.nix") (args // {
|
||||
modules = (args.modules or []) ++
|
||||
map (def: { _file = def.file; imports = [(coerce def.value)]; }) defs;
|
||||
|
||||
prefix = loc;
|
||||
})).config;
|
||||
getSubOptions = prefix: (import (nixos + "/lib/eval-config.nix") (args // {
|
||||
modules = (args.modules or []);
|
||||
|
||||
inherit prefix;
|
||||
})).options;
|
||||
};
|
||||
|
||||
# Obsolete alternative to configOf. It takes its option
|
||||
# declarations from the ‘options’ attribute of containing option
|
||||
# declaration.
|
||||
|
@ -15,7 +15,6 @@ with pkgs.lib;
|
||||
};
|
||||
|
||||
systemd.containers = mkOption {
|
||||
# !!! Should probably use nixosSubmodule here
|
||||
type = types.attrsOf (types.submodule (
|
||||
{ config, options, name, ... }:
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user