diff options
author | Jan Malakhovski <oxij@oxij.org> | 2015-08-17 17:55:35 +0000 |
---|---|---|
committer | Jan Malakhovski <oxij@oxij.org> | 2015-09-18 18:48:49 +0000 |
commit | 33ae3f2fe4baeb4db19d3c90dbb6cd35b9373004 (patch) | |
tree | 3315c48510babeec50d8ca84acb41689546e7acd /lib/types.nix | |
parent | c8ea6c07c655ba70cf46c52063276bfcfa5b1643 (diff) |
nixos,lib: move environment generation related copy-paste to lib
Diffstat (limited to 'lib/types.nix')
-rw-r--r-- | lib/types.nix | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/types.nix b/lib/types.nix index a7f9bf1946e6..7276f9af9fee 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -6,7 +6,7 @@ with import ./attrsets.nix; with import ./options.nix; with import ./trivial.nix; with import ./strings.nix; -with {inherit (import ./modules.nix) mergeDefinitions; }; +with {inherit (import ./modules.nix) mergeDefinitions filterOverrides; }; rec { @@ -166,6 +166,23 @@ rec { substSubModules = m: loaOf (elemType.substSubModules m); }; + # List or element of ... + loeOf = elemType: mkOptionType { + name = "element or list of ${elemType.name}s"; + check = x: isList x || elemType.check x; + merge = loc: defs: + let + defs' = filterOverrides defs; + res = (head defs').value; + in + if isList res then concatLists (getValues defs') + else if lessThan 1 (length defs') then + throw "The option `${showOption loc}' is defined multiple times, in ${showFiles (getFiles defs)}." + else if !isString res then + throw "The option `${showOption loc}' does not have a string value, in ${showFiles (getFiles defs)}." + else res; + }; + uniq = elemType: mkOptionType { inherit (elemType) name check; merge = mergeOneOption; |