summary refs log tree commit diff
path: root/lib/types.nix
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2015-12-04 07:15:14 +0300
committerIgor Pashev <pashev.igor@gmail.com>2015-12-04 07:15:14 +0300
commit363e6978ced1023c6daceaad647155361e3bda9e (patch)
tree149ecae7c8b9e9c27f397cf9bcb693f606cc5ca0 /lib/types.nix
parent12de4d5cb3bdd703904cf75aa6ddb9b9eb8f9b68 (diff)
downloadnixlib-363e6978ced1023c6daceaad647155361e3bda9e.tar
nixlib-363e6978ced1023c6daceaad647155361e3bda9e.tar.gz
nixlib-363e6978ced1023c6daceaad647155361e3bda9e.tar.bz2
nixlib-363e6978ced1023c6daceaad647155361e3bda9e.tar.lz
nixlib-363e6978ced1023c6daceaad647155361e3bda9e.tar.xz
nixlib-363e6978ced1023c6daceaad647155361e3bda9e.tar.zst
nixlib-363e6978ced1023c6daceaad647155361e3bda9e.zip
Allow enum of integers (and any other type)
Closes #9826.
Diffstat (limited to 'lib/types.nix')
-rw-r--r--lib/types.nix17
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}";