summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2021-07-18 19:08:49 +0200
committerGitHub <noreply@github.com>2021-07-18 19:08:49 +0200
commit6d29becbd3f181b4efbf05bab466e272a7beabc1 (patch)
tree1ff8fa7c328b938558d84d7daef67ae2ca13c219 /lib
parent03a17d756a6c9097f04c082fe7ce05d6079fbc89 (diff)
parent285632320dda85775699eba6b7eedcc47188bd3a (diff)
downloadnixpkgs-6d29becbd3f181b4efbf05bab466e272a7beabc1.tar
nixpkgs-6d29becbd3f181b4efbf05bab466e272a7beabc1.tar.gz
nixpkgs-6d29becbd3f181b4efbf05bab466e272a7beabc1.tar.bz2
nixpkgs-6d29becbd3f181b4efbf05bab466e272a7beabc1.tar.lz
nixpkgs-6d29becbd3f181b4efbf05bab466e272a7beabc1.tar.xz
nixpkgs-6d29becbd3f181b4efbf05bab466e272a7beabc1.tar.zst
nixpkgs-6d29becbd3f181b4efbf05bab466e272a7beabc1.zip
Merge pull request #124353 from hercules-ci/small-enum-description
lib.types.enum: Improve description for lengths 0 and 1
Diffstat (limited to 'lib')
-rw-r--r--lib/types.nix12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/types.nix b/lib/types.nix
index f47a1f92de7..c35f055e17f 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -581,7 +581,17 @@ rec {
       in
       mkOptionType rec {
         name = "enum";
-        description = "one of ${concatMapStringsSep ", " show values}";
+        description =
+          # Length 0 or 1 enums may occur in a design pattern with type merging
+          # where an "interface" module declares an empty enum and other modules
+          # provide implementations, each extending the enum with their own
+          # identifier.
+          if values == [] then
+            "impossible (empty enum)"
+          else if builtins.length values == 1 then
+            "value ${show (builtins.head values)} (singular enum)"
+          else
+            "one of ${concatMapStringsSep ", " show values}";
         check = flip elem values;
         merge = mergeEqualOption;
         functor = (defaultFunctor name) // { payload = values; binOp = a: b: unique (a ++ b); };