diff --git a/lib/types.nix b/lib/types.nix index 62c6a978af90..70cd410b3128 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -121,6 +121,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 7b86e518aaf1..b8c2dd7cb4d1 100644 --- a/nixos/doc/manual/development/option-types.xml +++ b/nixos/doc/manual/development/option-types.xml @@ -62,6 +62,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. +