Merge branch 'master' of git://github.com/ip1981/nixpkgs

Allow enum of integers (and any other type)
This commit is contained in:
Shea Levy 2015-12-04 07:16:15 -05:00
commit 3c05019af6

View File

@ -193,9 +193,9 @@ rec {
nullOr = elemType: mkOptionType { nullOr = elemType: mkOptionType {
name = "null or ${elemType.name}"; name = "null or ${elemType.name}";
check = x: builtins.isNull x || elemType.check x; check = x: x == null || elemType.check x;
merge = loc: defs: merge = loc: defs:
let nrNulls = count (def: isNull def.value) defs; in let nrNulls = count (def: def.value == null) defs; in
if nrNulls == length defs then null if nrNulls == length defs then null
else if nrNulls != 0 then else if nrNulls != 0 then
throw "The option `${showOption loc}' is defined both null and not null, in ${showFiles (getFiles defs)}." throw "The option `${showOption loc}' is defined both null and not null, in ${showFiles (getFiles defs)}."
@ -230,11 +230,18 @@ rec {
substSubModules = m: submodule m; substSubModules = m: submodule m;
}; };
enum = values: mkOptionType { enum = values:
name = "one of ${concatStringsSep ", " values}"; let
check = flip elem values; show = v:
merge = mergeOneOption; if builtins.isString v then ''"${v}"''
}; else if builtins.isInt v then builtins.toString v
else ''<${builtins.typeOf v}>'';
in
mkOptionType {
name = "one of ${concatMapStringsSep ", " show values}";
check = flip elem values;
merge = mergeOneOption;
};
either = t1: t2: mkOptionType { either = t1: t2: mkOptionType {
name = "${t1.name} or ${t2.name}"; name = "${t1.name} or ${t2.name}";