From fad475553ae2de3ba1dbcab980698ac070d04e72 Mon Sep 17 00:00:00 2001 From: David Baynard Date: Fri, 7 Jul 2023 23:08:00 +0100 Subject: [PATCH 1/2] 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 048e80974045..bc595ca9549b 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 3d4eca244138..5502ebbfc09f 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 f8e45e8a32a1..75009bb6777d 100644 --- a/tests/modules/programs/goimapnotify/launchd.plist +++ b/tests/modules/programs/goimapnotify/launchd.plist @@ -19,7 +19,7 @@ @goimapnotify@/bin/goimapnotify -conf - /home/hm-user/.config/imapnotify/imapnotify-hm-example.com-config.json + /nix/store/00000000000000000000000000000000-imapnotify-hm-example.com-config.json RunAtLoad From b70db52ff06f30e3de7f21b6ea47e75baa0c46f6 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 9 Jul 2023 09:34:18 +0200 Subject: [PATCH 2/2] imapnotify: move test Also add test for the systemd service. --- tests/default.nix | 3 +- .../modules/programs/goimapnotify/default.nix | 1 - .../services/imapnotify-darwin/default.nix | 1 + .../imapnotify-darwin}/launchd.nix | 0 .../imapnotify-darwin}/launchd.plist | 0 tests/modules/services/imapnotify/default.nix | 1 + .../services/imapnotify/imapnotify.nix | 39 +++++++++++++++++++ .../services/imapnotify/imapnotify.service | 12 ++++++ 8 files changed, 55 insertions(+), 2 deletions(-) delete mode 100644 tests/modules/programs/goimapnotify/default.nix create mode 100644 tests/modules/services/imapnotify-darwin/default.nix rename tests/modules/{programs/goimapnotify => services/imapnotify-darwin}/launchd.nix (100%) rename tests/modules/{programs/goimapnotify => services/imapnotify-darwin}/launchd.plist (100%) create mode 100644 tests/modules/services/imapnotify/default.nix create mode 100644 tests/modules/services/imapnotify/imapnotify.nix create mode 100644 tests/modules/services/imapnotify/imapnotify.service diff --git a/tests/default.nix b/tests/default.nix index 2fe309895d0f..890264030354 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -146,8 +146,8 @@ import nmt { ./modules/xresources ] ++ lib.optionals isDarwin [ ./modules/launchd + ./modules/services/imapnotify-darwin ./modules/targets-darwin - ./modules/programs/goimapnotify ] ++ lib.optionals isLinux [ ./modules/config/i18n ./modules/i18n/input-method @@ -205,6 +205,7 @@ import nmt { ./modules/services/gpg-agent ./modules/services/gromit-mpx ./modules/services/home-manager-auto-upgrade + ./modules/services/imapnotify ./modules/services/kanshi ./modules/services/lieer ./modules/services/mopidy diff --git a/tests/modules/programs/goimapnotify/default.nix b/tests/modules/programs/goimapnotify/default.nix deleted file mode 100644 index a2adc553d44e..000000000000 --- a/tests/modules/programs/goimapnotify/default.nix +++ /dev/null @@ -1 +0,0 @@ -{ goimapnotify-launchd = ./launchd.nix; } diff --git a/tests/modules/services/imapnotify-darwin/default.nix b/tests/modules/services/imapnotify-darwin/default.nix new file mode 100644 index 000000000000..a722604d7b37 --- /dev/null +++ b/tests/modules/services/imapnotify-darwin/default.nix @@ -0,0 +1 @@ +{ imapnotify-launchd = ./launchd.nix; } diff --git a/tests/modules/programs/goimapnotify/launchd.nix b/tests/modules/services/imapnotify-darwin/launchd.nix similarity index 100% rename from tests/modules/programs/goimapnotify/launchd.nix rename to tests/modules/services/imapnotify-darwin/launchd.nix diff --git a/tests/modules/programs/goimapnotify/launchd.plist b/tests/modules/services/imapnotify-darwin/launchd.plist similarity index 100% rename from tests/modules/programs/goimapnotify/launchd.plist rename to tests/modules/services/imapnotify-darwin/launchd.plist diff --git a/tests/modules/services/imapnotify/default.nix b/tests/modules/services/imapnotify/default.nix new file mode 100644 index 000000000000..f3a725dd09f1 --- /dev/null +++ b/tests/modules/services/imapnotify/default.nix @@ -0,0 +1 @@ +{ imapnotify = ./imapnotify.nix; } diff --git a/tests/modules/services/imapnotify/imapnotify.nix b/tests/modules/services/imapnotify/imapnotify.nix new file mode 100644 index 000000000000..c607c042c2d6 --- /dev/null +++ b/tests/modules/services/imapnotify/imapnotify.nix @@ -0,0 +1,39 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + accounts.email.accounts = { + "hm@example.com" = { + notmuch.enable = true; + imap.port = 993; + + imapnotify = { + enable = true; + boxes = [ "Inbox" ]; + onNotify = '' + ${pkgs.notmuch}/bin/notmuch new + ''; + }; + }; + }; + + services.imapnotify = { + enable = true; + package = (config.lib.test.mkStubPackage { + name = "goimapnotify"; + outPath = "@goimapnotify@"; + }); + }; + + test.stubs.notmuch = { }; + + nmt.script = '' + serviceFile="home-files/.config/systemd/user/imapnotify-hm-example.com.service" + serviceFileNormalized="$(normalizeStorePaths "$serviceFile")" + assertFileExists $serviceFile + assertFileContent $serviceFileNormalized ${./imapnotify.service} + ''; +} diff --git a/tests/modules/services/imapnotify/imapnotify.service b/tests/modules/services/imapnotify/imapnotify.service new file mode 100644 index 000000000000..3e3bd9ff60f2 --- /dev/null +++ b/tests/modules/services/imapnotify/imapnotify.service @@ -0,0 +1,12 @@ +[Install] +WantedBy=default.target + +[Service] +Environment=NOTMUCH_CONFIG=/home/hm-user/.config/notmuch/default/config +ExecStart=@goimapnotify@/bin/goimapnotify -conf '/nix/store/00000000000000000000000000000000-imapnotify-hm-example.com-config.json' +Restart=always +RestartSec=30 +Type=simple + +[Unit] +Description=imapnotify for hm-example.com