From 3877267e67eeceb1a20190c429b7cb29364566f7 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Mon, 20 Jan 2025 17:53:34 -0500 Subject: [PATCH 1/5] Reload instead of restart the service if only the config changes --- build/package/nix/tgstation-server.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/build/package/nix/tgstation-server.nix b/build/package/nix/tgstation-server.nix index 745391341a..0cd74937ef 100644 --- a/build/package/nix/tgstation-server.nix +++ b/build/package/nix/tgstation-server.nix @@ -124,6 +124,7 @@ in systemd.services.tgstation-server = { description = "tgstation-server"; + reloadTriggers = cfg.production-appsettings; serviceConfig = { User = cfg.username; Type = "notify-reload"; From 2dc04551477b220605a43337d05b69d20d1fe5fc Mon Sep 17 00:00:00 2001 From: Lorwp Date: Tue, 21 Jan 2025 10:52:21 +1100 Subject: [PATCH 2/5] Add EnvironmentFile option to nix package --- build/package/nix/tgstation-server.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/build/package/nix/tgstation-server.nix b/build/package/nix/tgstation-server.nix index 0cd74937ef..b1d80d2bba 100644 --- a/build/package/nix/tgstation-server.nix +++ b/build/package/nix/tgstation-server.nix @@ -91,6 +91,14 @@ in Extra PATH entries to add to the TGS process ''; }; + + environmentFile = lib.mkOption { + type = lib.types.nullOr lib.types.path; + default = null; + description = '' + Environment file as defined in {manpage}`systemd.exec(5)` + ''; + }; }; }; @@ -126,6 +134,7 @@ in description = "tgstation-server"; reloadTriggers = cfg.production-appsettings; serviceConfig = { + EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile; User = cfg.username; Type = "notify-reload"; NotifyAccess = "all"; From 5a0f6fea02cee550e3f0c8f9b6e0e022f43a770f Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Mon, 20 Jan 2025 19:52:05 -0500 Subject: [PATCH 3/5] Try this --- build/package/nix/tgstation-server.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build/package/nix/tgstation-server.nix b/build/package/nix/tgstation-server.nix index b1d80d2bba..1d9577bcc7 100644 --- a/build/package/nix/tgstation-server.nix +++ b/build/package/nix/tgstation-server.nix @@ -132,7 +132,6 @@ in systemd.services.tgstation-server = { description = "tgstation-server"; - reloadTriggers = cfg.production-appsettings; serviceConfig = { EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile; User = cfg.username; @@ -148,6 +147,10 @@ in WatchdogSignal = "SIGTERM"; LogsDirectory = "tgstation-server"; }; + reloadTriggers = [ + (lib.mkIf (cfg.environmentFile != null) [ cfg.environmentFile ]) + "/etc/tgstation.server.d/appsettings.Production.yml" + ]; wantedBy = [ "multi-user.target" ]; }; }; From 8a5a13718e6dc8d682bc81e1d2eae82d51fb3473 Mon Sep 17 00:00:00 2001 From: Lorwp Date: Tue, 21 Jan 2025 12:41:30 +1100 Subject: [PATCH 4/5] Use a path for appsettings instead of a string --- build/package/nix/tgstation-server.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/package/nix/tgstation-server.nix b/build/package/nix/tgstation-server.nix index 1d9577bcc7..6515edb0e2 100644 --- a/build/package/nix/tgstation-server.nix +++ b/build/package/nix/tgstation-server.nix @@ -77,10 +77,10 @@ in }; production-appsettings = lib.mkOption { - type = lib.types.lines; + type = lib.types.path; default = ''''; description = '' - The contents of appsettings.Production.yml in the /etc/tgstation-server.d directory. + A formatted appsettings.Production.yml file. ''; }; @@ -119,7 +119,7 @@ in mode = "0644"; }; "tgstation-server.d/appsettings.Production.yml" = { - text = cfg.production-appsettings; + source = cfg.production-appsettings; group = cfg.groupname; mode = "0640"; }; From 854c8048a8c38c884f97119f3ad259e14a5e2ff7 Mon Sep 17 00:00:00 2001 From: Lorwp Date: Thu, 23 Jan 2025 10:30:37 +1100 Subject: [PATCH 5/5] Set restartIfChanged on the TGS nix module's service, to ensure it doesn't get restarted and boots players --- build/package/nix/tgstation-server.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/build/package/nix/tgstation-server.nix b/build/package/nix/tgstation-server.nix index 6515edb0e2..f0feeab66f 100644 --- a/build/package/nix/tgstation-server.nix +++ b/build/package/nix/tgstation-server.nix @@ -151,6 +151,7 @@ in (lib.mkIf (cfg.environmentFile != null) [ cfg.environmentFile ]) "/etc/tgstation.server.d/appsettings.Production.yml" ]; + restartIfChanged = false; # So that the TGS service doesn't just get restarted whenever it's updated, and boots players wantedBy = [ "multi-user.target" ]; }; };