From fad475553ae2de3ba1dbcab980698ac070d04e72 Mon Sep 17 00:00:00 2001
From: David Baynard <git@baynard.dev>
Date: Fri, 7 Jul 2023 23:08:00 +0100
Subject: [PATCH] imapnotify: use direct nix store path for config
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

As pointed out in #3291, using the XDG symlink means the agent/unit
files don’t change when the contents of the config changes, and so the
service will not be restarted.
---
 modules/services/imapnotify.nix                   | 13 +++++--------
 tests/modules/programs/goimapnotify/launchd.nix   |  5 +++--
 tests/modules/programs/goimapnotify/launchd.plist |  2 +-
 3 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/modules/services/imapnotify.nix b/modules/services/imapnotify.nix
index 048e80974..bc595ca95 100644
--- a/modules/services/imapnotify.nix
+++ b/modules/services/imapnotify.nix
@@ -21,10 +21,9 @@ let
         Unit = { Description = "imapnotify for ${name}"; };
 
         Service = {
+          # Use the nix store path for config to ensure service restarts when it changes
           ExecStart =
-            "${getExe cfg.package} -conf '${config.xdg.configHome}/imapnotify/${
-              configName account
-            }'";
+            "${getExe cfg.package} -conf '${genAccountConfig account}'";
           Restart = "always";
           RestartSec = 30;
           Type = "simple";
@@ -44,11 +43,9 @@ let
       value = {
         enable = true;
         config = {
-          ProgramArguments = [
-            "${getExe cfg.package}"
-            "-conf"
-            "${config.xdg.configHome}/imapnotify/${configName account}"
-          ];
+          # Use the nix store path for config to ensure service restarts when it changes
+          ProgramArguments =
+            [ "${getExe cfg.package}" "-conf" "${genAccountConfig account}" ];
           KeepAlive = true;
           ThrottleInterval = 30;
           ExitTimeOut = 0;
diff --git a/tests/modules/programs/goimapnotify/launchd.nix b/tests/modules/programs/goimapnotify/launchd.nix
index 3d4eca244..5502ebbfc 100644
--- a/tests/modules/programs/goimapnotify/launchd.nix
+++ b/tests/modules/programs/goimapnotify/launchd.nix
@@ -33,8 +33,9 @@ with lib;
   nmt.script = let
     serviceFileName = "org.nix-community.home.imapnotify-hm-example.com.plist";
   in ''
-    serviceFile=LaunchAgents/${serviceFileName}
+    serviceFile="LaunchAgents/${serviceFileName}"
+    serviceFileNormalized="$(normalizeStorePaths "$serviceFile")"
     assertFileExists $serviceFile
-    assertFileContent $serviceFile ${./launchd.plist}
+    assertFileContent $serviceFileNormalized ${./launchd.plist}
   '';
 }
diff --git a/tests/modules/programs/goimapnotify/launchd.plist b/tests/modules/programs/goimapnotify/launchd.plist
index f8e45e8a3..75009bb67 100644
--- a/tests/modules/programs/goimapnotify/launchd.plist
+++ b/tests/modules/programs/goimapnotify/launchd.plist
@@ -19,7 +19,7 @@
 	<array>
 		<string>@goimapnotify@/bin/goimapnotify</string>
 		<string>-conf</string>
-		<string>/home/hm-user/.config/imapnotify/imapnotify-hm-example.com-config.json</string>
+		<string>/nix/store/00000000000000000000000000000000-imapnotify-hm-example.com-config.json</string>
 	</array>
 	<key>RunAtLoad</key>
 	<true/>