Merge branch 'master' of git://github.com/ip1981/nixpkgs
Allow enum of integers (and any other type)
This commit is contained in:
commit
3c05019af6
@ -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,8 +230,15 @@ rec {
|
|||||||
substSubModules = m: submodule m;
|
substSubModules = m: submodule m;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum = values: mkOptionType {
|
enum = values:
|
||||||
name = "one of ${concatStringsSep ", " values}";
|
let
|
||||||
|
show = v:
|
||||||
|
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;
|
check = flip elem values;
|
||||||
merge = mergeOneOption;
|
merge = mergeOneOption;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user