summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorWill Fancher <elvishjerricco@gmail.com>2023-11-09 16:49:11 -0500
committerGitHub <noreply@github.com>2023-11-09 16:49:11 -0500
commitc20ad5d379dfc0b5c54cc1e0efa12eaaada9c091 (patch)
treeb90ca50dd328cb259b151d6c2e1c7a6ca4d45a73 /nixos
parent1f37660f64a850233baab512c9b9bd83fb72be57 (diff)
parentae0bbc00e82f6dbf83282c787bee50fa3f1914ae (diff)
downloadnixpkgs-c20ad5d379dfc0b5c54cc1e0efa12eaaada9c091.tar
nixpkgs-c20ad5d379dfc0b5c54cc1e0efa12eaaada9c091.tar.gz
nixpkgs-c20ad5d379dfc0b5c54cc1e0efa12eaaada9c091.tar.bz2
nixpkgs-c20ad5d379dfc0b5c54cc1e0efa12eaaada9c091.tar.lz
nixpkgs-c20ad5d379dfc0b5c54cc1e0efa12eaaada9c091.tar.xz
nixpkgs-c20ad5d379dfc0b5c54cc1e0efa12eaaada9c091.tar.zst
nixpkgs-c20ad5d379dfc0b5c54cc1e0efa12eaaada9c091.zip
Merge pull request #266369 from SuperSandro2000/systemd-unit-empty-lines
systemd-lib: cleanup empty lines in unit files
Diffstat (limited to 'nixos')
-rw-r--r--nixos/lib/systemd-lib.nix35
1 files changed, 17 insertions, 18 deletions
diff --git a/nixos/lib/systemd-lib.nix b/nixos/lib/systemd-lib.nix
index 7b600464bb4..820ccbcbf72 100644
--- a/nixos/lib/systemd-lib.nix
+++ b/nixos/lib/systemd-lib.nix
@@ -376,24 +376,23 @@ in rec {
 
   serviceToUnit = name: def:
     { inherit (def) aliases wantedBy requiredBy enable overrideStrategy;
-      text = commonUnitText def +
-        ''
-          [Service]
-          ${let env = cfg.globalEnvironment // def.environment;
-            in concatMapStrings (n:
-              let s = optionalString (env.${n} != null)
-                "Environment=${builtins.toJSON "${n}=${env.${n}}"}\n";
-              # systemd max line length is now 1MiB
-              # https://github.com/systemd/systemd/commit/e6dde451a51dc5aaa7f4d98d39b8fe735f73d2af
-              in if stringLength s >= 1048576 then throw "The value of the environment variable ‘${n}’ in systemd service ‘${name}.service’ is too long." else s) (attrNames env)}
-          ${if def ? reloadIfChanged && def.reloadIfChanged then ''
-            X-ReloadIfChanged=true
-          '' else if (def ? restartIfChanged && !def.restartIfChanged) then ''
-            X-RestartIfChanged=false
-          '' else ""}
-          ${optionalString (def ? stopIfChanged && !def.stopIfChanged) "X-StopIfChanged=false"}
-          ${attrsToSection def.serviceConfig}
-        '';
+      text = commonUnitText def + ''
+        [Service]
+      '' + (let env = cfg.globalEnvironment // def.environment;
+        in concatMapStrings (n:
+          let s = optionalString (env.${n} != null)
+            "Environment=${builtins.toJSON "${n}=${env.${n}}"}\n";
+          # systemd max line length is now 1MiB
+          # https://github.com/systemd/systemd/commit/e6dde451a51dc5aaa7f4d98d39b8fe735f73d2af
+          in if stringLength s >= 1048576 then throw "The value of the environment variable ‘${n}’ in systemd service ‘${name}.service’ is too long." else s) (attrNames env))
+      + (if def ? reloadIfChanged && def.reloadIfChanged then ''
+        X-ReloadIfChanged=true
+      '' else if (def ? restartIfChanged && !def.restartIfChanged) then ''
+        X-RestartIfChanged=false
+      '' else "")
+       + optionalString (def ? stopIfChanged && !def.stopIfChanged) ''
+         X-StopIfChanged=false
+      '' + attrsToSection def.serviceConfig;
     };
 
   socketToUnit = name: def: