git.iko.soy/typeable/nixpkgs
on master help sign in
lib.types.enum: Improve description for lengths 0 and 1
commit285632320dda85775699eba6b7eedcc47188bd3a authorRobert Hensing <robert@roberthensing.nl> dateTue 25 May 2021, 10:53 (5 years ago) parent9ae7b7e
1 file changed+11−1
lib/types.nix+11−1
lib/types.nix+11−1
@@ -581,7 +581,17 @@ rec {
581581 in
582582 mkOptionType rec {
583583 name = "enum";
584− description = "one of ${concatMapStringsSep ", " show values}";
584+ description =
585+ # Length 0 or 1 enums may occur in a design pattern with type merging
586+ # where an "interface" module declares an empty enum and other modules
587+ # provide implementations, each extending the enum with their own
588+ # identifier.
589+ if values == [] then
590+ "impossible (empty enum)"
591+ else if builtins.length values == 1 then
592+ "value ${show (builtins.head values)} (singular enum)"
593+ else
594+ "one of ${concatMapStringsSep ", " show values}";
585595 check = flip elem values;
586596 merge = mergeEqualOption;
587597 functor = (defaultFunctor name) // { payload = values; binOp = a: b: unique (a ++ b); };