From 363e6978ced1023c6daceaad647155361e3bda9e Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Fri, 4 Dec 2015 07:15:14 +0300 Subject: [PATCH] Allow enum of integers (and any other type) Closes #9826. --- lib/types.nix | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index 7276f9af9fe..d750768335c 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}";