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 65700a4fd1)
This commit is contained in:
Robert Helgesson 2022-12-04 12:12:32 +01:00
parent 6ee09246d9
commit 32c336c767
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
3 changed files with 16 additions and 12 deletions

View file

@ -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 = {

View file

@ -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

View file

@ -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