diff options
author | Robert Hensing <robert@roberthensing.nl> | 2021-05-25 10:53:04 +0200 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2021-05-25 10:53:04 +0200 |
commit | 285632320dda85775699eba6b7eedcc47188bd3a (patch) | |
tree | 7c8be73f1b05cb7abe066abd0387d1aae58b02de /lib | |
parent | 9ae7b7e70622afc6148fbbf045a8867d496b3f6d (diff) | |
download | nixpkgs-285632320dda85775699eba6b7eedcc47188bd3a.tar nixpkgs-285632320dda85775699eba6b7eedcc47188bd3a.tar.gz nixpkgs-285632320dda85775699eba6b7eedcc47188bd3a.tar.bz2 nixpkgs-285632320dda85775699eba6b7eedcc47188bd3a.tar.lz nixpkgs-285632320dda85775699eba6b7eedcc47188bd3a.tar.xz nixpkgs-285632320dda85775699eba6b7eedcc47188bd3a.tar.zst nixpkgs-285632320dda85775699eba6b7eedcc47188bd3a.zip |
lib.types.enum: Improve description for lengths 0 and 1
Diffstat (limited to 'lib')
-rw-r--r-- | lib/types.nix | 12 |
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); }; |