From 5ce2352f8baf7ff1a8d8fa1edb6a41cd56330f7f Mon Sep 17 00:00:00 2001 From: Ryan Trinkle Date: Sat, 2 Dec 2017 13:04:16 -0500 Subject: [PATCH] nixpkgs.lib: Add types.strMatching (cherry picked from commit 83048c4fe02d69a4f0d7e832fbca30d21813ece3) --- lib/types.nix | 7 +++++++ nixos/doc/manual/development/option-types.xml | 6 ++++++ 2 files changed, 13 insertions(+) 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. +