From 32c336c767e9f9f378e0bf733ef40be16372ff7f Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 4 Dec 2022 12:12:32 +0100 Subject: [PATCH] polybar: fix restart trigger The old trigger would actually never cause a restart since the path doesn't change. With this change the trigger is now using the actual configuration path in the Nix store, which depends on the content. (cherry picked from commit 65700a4fd10aa20ff4a65cbf0ab8b3dc0c438dcb) --- modules/services/polybar.nix | 24 +++++++++++-------- .../services/polybar/basic-configuration.nix | 2 +- .../services/polybar/empty-configuration.nix | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/services/polybar.nix b/modules/services/polybar.nix index 1ebc04636..d3ac68ded 100644 --- a/modules/services/polybar.nix +++ b/modules/services/polybar.nix @@ -55,11 +55,17 @@ let in "${key}=${value'}"; }; - configFile = pkgs.writeText "polybar.conf" '' - ${toPolybarIni cfg.config} - ${toPolybarIni (mapAttrs convertPolybarSection cfg.settings)} - ${cfg.extraConfig} - ''; + configFile = let + isDeclarativeConfig = cfg.settings != opt.settings.default || cfg.config + != opt.config.default || cfg.extraConfig != opt.extraConfig.default; + in if isDeclarativeConfig then + pkgs.writeText "polybar.conf" '' + ${toPolybarIni cfg.config} + ${toPolybarIni (mapAttrs convertPolybarSection cfg.settings)} + ${cfg.extraConfig} + '' + else + null; in { options = { @@ -202,16 +208,14 @@ in { meta.maintainers = with maintainers; [ h7x4 ]; home.packages = [ cfg.package ]; - xdg.configFile."polybar/config.ini" = let - isDeclarativeConfig = cfg.settings != opt.settings.default || cfg.config - != opt.config.default || cfg.extraConfig != opt.extraConfig.default; - in mkIf isDeclarativeConfig { source = configFile; }; + xdg.configFile."polybar/config.ini" = + mkIf (configFile != null) { source = configFile; }; systemd.user.services.polybar = { Unit = { Description = "Polybar status bar"; PartOf = [ "tray.target" ]; - X-Restart-Triggers = [ "${config.xdg.configHome}/polybar/config.ini" ]; + X-Restart-Triggers = mkIf (configFile != null) "${configFile}"; }; Service = { diff --git a/tests/modules/services/polybar/basic-configuration.nix b/tests/modules/services/polybar/basic-configuration.nix index 43d62fe8f..5d9c8df58 100644 --- a/tests/modules/services/polybar/basic-configuration.nix +++ b/tests/modules/services/polybar/basic-configuration.nix @@ -47,7 +47,7 @@ serviceFile=home-files/.config/systemd/user/polybar.service assertFileExists $serviceFile - assertFileRegex $serviceFile 'X-Restart-Triggers=.*/.config/polybar/config.ini' + assertFileRegex $serviceFile 'X-Restart-Triggers=/nix/store/.*-polybar.conf$' assertFileRegex $serviceFile 'ExecStart=.*/bin/polybar-start' assertFileExists home-files/.config/polybar/config.ini diff --git a/tests/modules/services/polybar/empty-configuration.nix b/tests/modules/services/polybar/empty-configuration.nix index e4f2fb4a0..263509676 100644 --- a/tests/modules/services/polybar/empty-configuration.nix +++ b/tests/modules/services/polybar/empty-configuration.nix @@ -12,7 +12,7 @@ serviceFile=home-files/.config/systemd/user/polybar.service assertFileExists $serviceFile - assertFileRegex $serviceFile 'X-Restart-Triggers=.*/.config/polybar/config.ini' + assertFileNotRegex $serviceFile 'X-Restart-Triggers=/nix/store/.*-polybar.conf$' assertFileRegex $serviceFile 'ExecStart=.*/bin/polybar-start' assertPathNotExists home-files/.config/polybar/config.ini