mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-06-05 21:03:40 +00:00
nixos/lib/systemd-lib: make unitNameType work with e.g. Rust regex
The unitNameType regex currently makes the Tvix CI (and likely Snix in the future) fail since "sysroot-nix-.ro\\x2dstore.mount" will fail the check since it doesn't interpret the single backslash as part of the bracket expression. POSIX doesn't require escaping the backslash in bracket exprs: > The special characters '.', '*', '[', and '\\' ( <period>, <asterisk>, > <left-square-bracket>, and <backslash>, respectively) shall lose their > special meaning within a bracket expression. However, Rust uses the backslash for escaping in bracket exprs, so it also needs to be escaped: > [\[\]] Escaping in character classes (matching [ or ]) Making the Regex work with both POSIX-like regexes and Rust's regex syntax is possible in this case, so let's do it.
This commit is contained in:
@@ -67,7 +67,9 @@ rec {
|
||||
mkPathSafeName = replaceStrings [ "@" ":" "\\" "[" "]" ] [ "-" "-" "-" "" "" ];
|
||||
|
||||
# a type for options that take a unit name
|
||||
unitNameType = types.strMatching "[a-zA-Z0-9@%:_.\\-]+[.](service|socket|device|mount|automount|swap|target|path|timer|scope|slice)";
|
||||
# note: redundantly escaping backslash in the bracket expression makes the regex
|
||||
# slightly more portable even though POSIX doesn't require it.
|
||||
unitNameType = types.strMatching "[a-zA-Z0-9@%:_.\\\\-]+[.](service|socket|device|mount|automount|swap|target|path|timer|scope|slice)";
|
||||
|
||||
makeUnit =
|
||||
name: unit:
|
||||
|
||||
Reference in New Issue
Block a user