diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2022-01-21 17:39:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-21 17:39:13 +0100 |
commit | c4a5efa9652a2d482a1c669d6e7120a635ea6660 (patch) | |
tree | 5cb58fab8eded7e6f8a8f56eab10876627511d6f /lib | |
parent | 2be8dd990833dc07e338bc27489a211347bf94b9 (diff) | |
parent | 1394bfc32a7f2398815b000ad11812f2da7ea2d5 (diff) | |
download | nixlib-c4a5efa9652a2d482a1c669d6e7120a635ea6660.tar nixlib-c4a5efa9652a2d482a1c669d6e7120a635ea6660.tar.gz nixlib-c4a5efa9652a2d482a1c669d6e7120a635ea6660.tar.bz2 nixlib-c4a5efa9652a2d482a1c669d6e7120a635ea6660.tar.lz nixlib-c4a5efa9652a2d482a1c669d6e7120a635ea6660.tar.xz nixlib-c4a5efa9652a2d482a1c669d6e7120a635ea6660.tar.zst nixlib-c4a5efa9652a2d482a1c669d6e7120a635ea6660.zip |
Merge pull request #155522 from Julow/single_line_str
types.singleLineStr: strings that don't contain '\n'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/types.nix | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/types.nix b/lib/types.nix index 244cbb6b5354..cc3ac5fdf6fb 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -300,6 +300,19 @@ rec { inherit (str) merge; }; + # Allow a newline character at the end and trim it in the merge function. + singleLineStr = + let + inherit (strMatching "[^\n\r]*\n?") check merge; + in + mkOptionType { + name = "singleLineStr"; + description = "(optionally newline-terminated) single-line string"; + inherit check; + merge = loc: defs: + lib.removeSuffix "\n" (merge loc defs); + }; + strMatching = pattern: mkOptionType { name = "strMatching ${escapeNixString pattern}"; description = "string matching the pattern ${pattern}"; |