diff options
Diffstat (limited to 'lib/types.nix')
-rw-r--r-- | lib/types.nix | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/types.nix b/lib/types.nix index f47a1f92de7..a0be2ff3a45 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -287,6 +287,13 @@ rec { merge = mergeEqualOption; }; + nonEmptyStr = mkOptionType { + name = "nonEmptyStr"; + description = "non-empty string"; + check = x: str.check x && builtins.match "[ \t\n]*" x == null; + inherit (str) merge; + }; + strMatching = pattern: mkOptionType { name = "strMatching ${escapeNixString pattern}"; description = "string matching the pattern ${pattern}"; @@ -581,7 +588,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); }; |