diff --git a/lib/types.nix b/lib/types.nix index 46ed05d288f..88fc90d0597 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -174,6 +174,13 @@ rec { merge = mergeOneOption; }; + strMatching = pattern: mkOptionType { + name = "strMatching ${escapeNixString pattern}"; + description = "string matching the pattern ${pattern}"; + check = x: str.check x && builtins.match pattern x != null; + inherit (str) merge; + }; + # Merge multiple definitions by concatenating them (with the given # separator between the values). separatedString = sep: mkOptionType rec { diff --git a/nixos/doc/manual/development/option-types.xml b/nixos/doc/manual/development/option-types.xml index 83dcf0232d9..ec940d5d2b8 100644 --- a/nixos/doc/manual/development/option-types.xml +++ b/nixos/doc/manual/development/option-types.xml @@ -110,6 +110,12 @@ A string. Multiple definitions are concatenated with a collon ":". + + types.strMatching + A string matching a specific regular expression. Multiple + definitions cannot be merged. The regular expression is processed using + builtins.match. +