systemd service: fix issues with escaping when unit name contains '-'

systemd escaping rules translate this into a string containing '\'
which is treated by some code paths as quoted, and by others as unquoted
causing the affected units to fail.

+6 -4
+6 -4
nixos/modules/system/boot/systemd.nix
··· 15 pkgs.runCommand "unit" { preferLocalBuild = true; inherit (unit) text; } 16 '' 17 mkdir -p $out 18 - echo -n "$text" > $out/${name} 19 '' 20 else 21 pkgs.runCommand "unit" { preferLocalBuild = true; } 22 '' 23 mkdir -p $out 24 - ln -s /dev/null $out/${name} 25 ''; 26 27 upstreamSystemUnits = ··· 187 "timers.target" 188 ]; 189 190 makeJobScript = name: text: 191 - let x = pkgs.writeTextFile { name = "unit-script"; executable = true; destination = "/bin/${name}"; inherit text; }; 192 - in "${x}/bin/${name}"; 193 194 unitConfig = { name, config, ... }: { 195 config = {
··· 15 pkgs.runCommand "unit" { preferLocalBuild = true; inherit (unit) text; } 16 '' 17 mkdir -p $out 18 + echo -n "$text" > $out/${shellEscape name} 19 '' 20 else 21 pkgs.runCommand "unit" { preferLocalBuild = true; } 22 '' 23 mkdir -p $out 24 + ln -s /dev/null $out/${shellEscape name} 25 ''; 26 27 upstreamSystemUnits = ··· 187 "timers.target" 188 ]; 189 190 + shellEscape = s: (replaceChars [ "\\" ] [ "\\\\" ] s); 191 + 192 makeJobScript = name: text: 193 + let x = pkgs.writeTextFile { name = "unit-script"; executable = true; destination = "/bin/${shellEscape name}"; inherit text; }; 194 + in "${x}/bin/${shellEscape name}"; 195 196 unitConfig = { name, config, ... }: { 197 config = {