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