diff options
Diffstat (limited to 'lib/types.nix')
-rw-r--r-- | lib/types.nix | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/types.nix b/lib/types.nix index f5700ab0269a3..1e7abf36535fb 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -33,9 +33,14 @@ rec { , # Return a flat list of sub-options. Used to generate # documentation. getSubOptions ? prefix: {} + , # List of modules if any, or null if none. + getSubModules ? null + , # Function for building the same option type with a different list of + # modules. + substSubModules ? m: null }: { _type = "option-type"; - inherit name check merge getSubOptions; + inherit name check merge getSubOptions getSubModules substSubModules; }; @@ -110,6 +115,8 @@ rec { elemType.merge (loc ++ ["[${toString n}-${toString m}]"]) [{ inherit (def) file; value = def'; }]) def.value) defs); getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["*"]); + getSubModules = elemType.getSubModules; + substSubModules = m: listOf (elemType.substSubModules m); }; attrsOf = elemType: mkOptionType { @@ -121,6 +128,8 @@ rec { (map (def: listToAttrs (mapAttrsToList (n: def': { name = n; value = { inherit (def) file; value = def'; }; }) def.value)) defs); getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name>"]); + getSubModules = elemType.getSubModules; + substSubModules = m: attrsOf (elemType.substSubModules m); }; # List or attribute set of ... @@ -147,12 +156,16 @@ rec { else false; merge = loc: defs: attrOnly.merge loc (imap convertIfList defs); getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name?>"]); + getSubModules = elemType.getSubModules; + substSubModules = m: loaOf (elemType.substSubModules m); }; uniq = elemType: mkOptionType { inherit (elemType) name check; merge = mergeOneOption; getSubOptions = elemType.getSubOptions; + getSubModules = elemType.getSubModules; + substSubModules = m: uniq (elemType.substSubModules m); }; nullOr = elemType: mkOptionType { @@ -165,14 +178,8 @@ rec { throw "The option `${showOption loc}' is defined both null and not null, in ${showFiles (getFiles defs)}." else elemType.merge loc defs; getSubOptions = elemType.getSubOptions; - }; - - functionTo = elemType: mkOptionType { - name = "function that evaluates to a(n) ${elemType.name}"; - check = isFunction; - merge = loc: defs: - fnArgs: elemType.merge loc (map (fn: { inherit (fn) file; value = fn.value fnArgs; }) defs); - getSubOptions = elemType.getSubOptions; + getSubModules = elemType.getSubModules; + substSubModules = m: nullOr (elemType.substSubModules m); }; submodule = opts: @@ -192,6 +199,8 @@ rec { { modules = opts'; inherit prefix; # FIXME: hack to get shit to evaluate. args = { name = ""; }; }).options; + getSubModules = opts'; + substSubModules = m: submodule m; }; enum = values: mkOptionType { @@ -200,6 +209,12 @@ rec { merge = mergeOneOption; }; + either = t1: t2: mkOptionType { + name = "${t1.name} or ${t2.name}"; + check = x: t1.check x || t2.check x; + merge = mergeOneOption; + }; + # Obsolete alternative to configOf. It takes its option # declarations from the ‘options’ attribute of containing option # declaration. |