git.iko.soy/typeable/nixpkgs
on master help sign in
nixpkgs.lib: Add types.strMatching
commit83048c4fe02d69a4f0d7e832fbca30d21813ece3 authorRyan Trinkle <ryan.trinkle@gmail.com> dateSat 2 Dec 2017, 13:04 (9 years ago) parent6281eb1
2 files changed+13
lib/types.nix+7 nixos/doc/manual/development/option-types.xml+6
lib/types.nix+7
@@ -174,6 +174,13 @@ rec {
174174 merge = mergeOneOption;
175175 };
176176
177+ strMatching = pattern: mkOptionType {
178+ name = "strMatching ${escapeNixString pattern}";
179+ description = "string matching the pattern ${pattern}";
180+ check = x: str.check x && builtins.match pattern x != null;
181+ inherit (str) merge;
182+ };
183+
177184 # Merge multiple definitions by concatenating them (with the given
178185 # separator between the values).
179186 separatedString = sep: mkOptionType rec {
nixos/doc/manual/development/option-types.xml+6
@@ -110,6 +110,12 @@
110110 <listitem><para>A string. Multiple definitions are concatenated with a
111111 collon <literal>":"</literal>.</para></listitem>
112112 </varlistentry>
113+ <varlistentry>
114+ <term><varname>types.strMatching</varname></term>
115+ <listitem><para>A string matching a specific regular expression. Multiple
116+ definitions cannot be merged. The regular expression is processed using
117+ <literal>builtins.match</literal>.</para></listitem>
118+ </varlistentry>
113119</variablelist>
114120
115121 </section>