From a9953635d7f34e7358d5189751110f87e3ac17da Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Tue, 12 Nov 2024 14:13:32 -0600 Subject: [PATCH] mopidy: restart service on config changes Also extend basic configuration test a bit to verify the restart trigger. --- modules/services/mopidy.nix | 2 ++ .../services/mopidy/basic-configuration.nix | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/services/mopidy.nix b/modules/services/mopidy.nix index fc04d3d07..d50a81294 100644 --- a/modules/services/mopidy.nix +++ b/modules/services/mopidy.nix @@ -126,6 +126,8 @@ in { Description = "mopidy music player daemon"; Documentation = [ "https://mopidy.com/" ]; After = [ "network.target" "sound.target" ]; + X-Restart-Triggers = mkIf (cfg.settings != { }) + [ "${config.xdg.configFile."mopidy/mopidy.conf".source}" ]; }; Service = { diff --git a/tests/modules/services/mopidy/basic-configuration.nix b/tests/modules/services/mopidy/basic-configuration.nix index 2bffbd681..99aaeece8 100644 --- a/tests/modules/services/mopidy/basic-configuration.nix +++ b/tests/modules/services/mopidy/basic-configuration.nix @@ -29,7 +29,28 @@ }; nmt.script = '' - assertFileExists home-files/.config/systemd/user/mopidy.service + serviceFile=home-files/.config/systemd/user/mopidy.service + assertFileExists $serviceFile + serviceFile=$(normalizeStorePaths $serviceFile) + assertFileContent $serviceFile \ + ${ + builtins.toFile "expected-mopidy.service" '' + [Install] + WantedBy=default.target + + [Service] + ExecStart=/nix/store/00000000000000000000000000000000-mopidy-with-extensions/bin/mopidy --config /home/hm-user/.config/mopidy/mopidy.conf + Restart=on-failure + + [Unit] + After=network.target + After=sound.target + Description=mopidy music player daemon + Documentation=https://mopidy.com/ + X-Restart-Triggers=/nix/store/00000000000000000000000000000000-mopidy-hm-user + '' + } + assertPathNotExists home-files/.config/systemd/user/mopidy-scan.service assertFileExists home-files/.config/mopidy/mopidy.conf