diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2015-12-04 07:15:14 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2015-12-04 07:15:14 +0300 |
commit | 363e6978ced1023c6daceaad647155361e3bda9e (patch) | |
tree | 149ecae7c8b9e9c27f397cf9bcb693f606cc5ca0 /lib/types.nix | |
parent | 12de4d5cb3bdd703904cf75aa6ddb9b9eb8f9b68 (diff) |
Allow enum of integers (and any other type)
Closes #9826.
Diffstat (limited to 'lib/types.nix')
-rw-r--r-- | lib/types.nix | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/types.nix b/lib/types.nix index 7276f9af9fee..d750768335ca 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -230,11 +230,18 @@ rec { substSubModules = m: submodule m; }; - enum = values: mkOptionType { - name = "one of ${concatStringsSep ", " values}"; - check = flip elem values; - merge = mergeOneOption; - }; + enum = 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; + merge = mergeOneOption; + }; either = t1: t2: mkOptionType { name = "${t1.name} or ${t2.name}"; |