mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 03:23:29 +03:00
types.listOf: Use mergeDefinitions to handle each element
This simplifies typechecking and allows properties to be used inside the lists
This commit is contained in:
parent
9255c48a06
commit
e4bc2592f3
1 changed files with 10 additions and 5 deletions
|
@ -7,7 +7,9 @@ with import ./options.nix;
|
||||||
with import ./trivial.nix;
|
with import ./trivial.nix;
|
||||||
with import ./strings.nix;
|
with import ./strings.nix;
|
||||||
|
|
||||||
rec {
|
let
|
||||||
|
inherit (import ./modules.nix) mergeDefinitions;
|
||||||
|
in rec {
|
||||||
|
|
||||||
isType = type: x: (x._type or "") == type;
|
isType = type: x: (x._type or "") == type;
|
||||||
|
|
||||||
|
@ -109,11 +111,14 @@ rec {
|
||||||
|
|
||||||
listOf = elemType: mkOptionType {
|
listOf = elemType: mkOptionType {
|
||||||
name = "list of ${elemType.name}s";
|
name = "list of ${elemType.name}s";
|
||||||
check = value: isList value && all elemType.check value;
|
check = isList;
|
||||||
merge = loc: defs:
|
merge = loc: defs:
|
||||||
concatLists (imap (n: def: imap (m: def':
|
map (x: x.value) (filter (x: x ? value) (concatLists (imap (n: def: imap (m: def':
|
||||||
elemType.merge (loc ++ ["[${toString n}-${toString m}]"])
|
let
|
||||||
[{ inherit (def) file; value = def'; }]) def.value) defs);
|
inherit (mergeDefinitions (loc ++ ["[definition ${toString n}-entry ${toString m}]"])
|
||||||
|
elemType [{ inherit (def) file; value = def'; }]
|
||||||
|
) defsFinal mergedValue;
|
||||||
|
in if defsFinal == [] then {} else { value = mergedValue; }) def.value) defs)));
|
||||||
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["*"]);
|
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["*"]);
|
||||||
getSubModules = elemType.getSubModules;
|
getSubModules = elemType.getSubModules;
|
||||||
substSubModules = m: listOf (elemType.substSubModules m);
|
substSubModules = m: listOf (elemType.substSubModules m);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue