From 83048c4fe02d69a4f0d7e832fbca30d21813ece3 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 --- 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 46ed05d288f2..88fc90d05970 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 83dcf0232d9d..ec940d5d2b86 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. +