From 4a9c962aca26e89621e7859c4465eba2043f89e0 Mon Sep 17 00:00:00 2001 From: illustris Date: Tue, 26 Mar 2024 00:00:46 +0530 Subject: [PATCH 1/2] nixos/systemd-lib: fix restart/reloadTriggers when passing paths When passing a path to restartTriggers or reloadTriggers, X-Restart/Reload-Triggers will get populated by the absolute path of the file on the machine where the config is evaluated. This patch corrects this behavior. --- nixos/doc/manual/release-notes/rl-2405.section.md | 3 +++ nixos/lib/systemd-lib.nix | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/nixos/doc/manual/release-notes/rl-2405.section.md b/nixos/doc/manual/release-notes/rl-2405.section.md index dddb2b9241ad..80b17bd75596 100644 --- a/nixos/doc/manual/release-notes/rl-2405.section.md +++ b/nixos/doc/manual/release-notes/rl-2405.section.md @@ -276,6 +276,9 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m - Ada packages (libraries and tools) have been moved into the `gnatPackages` scope. `gnatPackages` uses the default GNAT compiler, `gnat12Packages` and `gnat13Packages` use the respective matching compiler version. +- Paths provided as `restartTriggers` and `reloadTriggers` for systemd units will now be copied into the nix store to make the behavior consistent. + Previously, `restartTriggers = [ ./config.txt ]` would either always or never trigger a restart when switching to a new configuration, depending on if the source was in a flake or not. + - `spark2014` has been renamed to `gnatprove`. A version of `gnatprove` matching different GNAT versions is available from the different `gnatPackages` sets. - `services.resolved.fallbackDns` can now be used to disable the upstream fallback servers entirely by setting it to an empty list. To get the previous behaviour of the upstream defaults set it to null, the new default, instead. diff --git a/nixos/lib/systemd-lib.nix b/nixos/lib/systemd-lib.nix index 832160111da4..efe58dceb34a 100644 --- a/nixos/lib/systemd-lib.nix +++ b/nixos/lib/systemd-lib.nix @@ -14,10 +14,12 @@ let elem filter filterAttrs + flatten flip head isInt isList + isPath length makeBinPath makeSearchPathOutput @@ -28,6 +30,7 @@ let optional optionalAttrs optionalString + pipe range replaceStrings reverseList @@ -362,9 +365,17 @@ in rec { // optionalAttrs (config.requisite != []) { Requisite = toString config.requisite; } // optionalAttrs (config ? restartTriggers && config.restartTriggers != []) - { X-Restart-Triggers = "${pkgs.writeText "X-Restart-Triggers-${name}" (toString config.restartTriggers)}"; } + { X-Restart-Triggers = "${pkgs.writeText "X-Restart-Triggers-${name}" (pipe config.restartTriggers [ + flatten + (map (x: if isPath x then "${x}" else x)) + toString + ])}"; } // optionalAttrs (config ? reloadTriggers && config.reloadTriggers != []) - { X-Reload-Triggers = "${pkgs.writeText "X-Reload-Triggers-${name}" (toString config.reloadTriggers)}"; } + { X-Reload-Triggers = "${pkgs.writeText "X-Reload-Triggers-${name}" (pipe config.reloadTriggers [ + flatten + (map (x: if isPath x then "${x}" else x)) + toString + ])}"; } // optionalAttrs (config.description != "") { Description = config.description; } // optionalAttrs (config.documentation != []) { From 7862480ab0158cfe577e8b98bb4886b950225d6f Mon Sep 17 00:00:00 2001 From: illustris Date: Sun, 21 Apr 2024 10:27:33 +0530 Subject: [PATCH 2/2] Update nixos/doc/manual/release-notes/rl-2405.section.md Co-authored-by: Ryan Hendrickson --- nixos/doc/manual/release-notes/rl-2405.section.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/doc/manual/release-notes/rl-2405.section.md b/nixos/doc/manual/release-notes/rl-2405.section.md index 80b17bd75596..aa94cd570110 100644 --- a/nixos/doc/manual/release-notes/rl-2405.section.md +++ b/nixos/doc/manual/release-notes/rl-2405.section.md @@ -277,7 +277,7 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m - Ada packages (libraries and tools) have been moved into the `gnatPackages` scope. `gnatPackages` uses the default GNAT compiler, `gnat12Packages` and `gnat13Packages` use the respective matching compiler version. - Paths provided as `restartTriggers` and `reloadTriggers` for systemd units will now be copied into the nix store to make the behavior consistent. - Previously, `restartTriggers = [ ./config.txt ]` would either always or never trigger a restart when switching to a new configuration, depending on if the source was in a flake or not. + Previously, `restartTriggers = [ ./config.txt ]`, if defined in a flake, would trigger a restart when any part of the flake changed; and if not defined in a flake, would never trigger a restart even if the contents of `config.txt` changed. - `spark2014` has been renamed to `gnatprove`. A version of `gnatprove` matching different GNAT versions is available from the different `gnatPackages` sets.