diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 68e0760df..8458e42bb 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -263,6 +263,9 @@ Makefile @thiagokokada /modules/programs/pls.nix @arjan-s /tests/modules/programs/pls @arjan-s +/modules/programs/polybar.nix @h7x4 +/tests/modules/programs/polybar @h7x4 + /modules/programs/powerline-go.nix @DamienCassou /modules/programs/pubs.nix @loicreynier diff --git a/modules/services/polybar.nix b/modules/services/polybar.nix index da0c617e2..1ebc04636 100644 --- a/modules/services/polybar.nix +++ b/modules/services/polybar.nix @@ -1,10 +1,11 @@ -{ config, lib, pkgs, ... }: +{ config, options, lib, pkgs, ... }: with lib; let cfg = config.services.polybar; + opt = options.services.polybar; eitherStrBoolIntList = with types; either str (either bool (either int (listOf str))); @@ -198,15 +199,19 @@ in { lib.platforms.linux) ]; + meta.maintainers = with maintainers; [ h7x4 ]; + home.packages = [ cfg.package ]; - xdg.configFile."polybar/config.ini".source = configFile; + 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; }; systemd.user.services.polybar = { Unit = { Description = "Polybar status bar"; PartOf = [ "tray.target" ]; - X-Restart-Triggers = - [ "${config.xdg.configFile."polybar/config.ini".source}" ]; + X-Restart-Triggers = [ "${config.xdg.configHome}/polybar/config.ini" ]; }; Service = { diff --git a/tests/modules/services/polybar/basic-configuration.nix b/tests/modules/services/polybar/basic-configuration.nix index e5bb3f388..43d62fe8f 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=.*polybar\.conf' + assertFileRegex $serviceFile 'X-Restart-Triggers=.*/.config/polybar/config.ini' assertFileRegex $serviceFile 'ExecStart=.*/bin/polybar-start' assertFileExists home-files/.config/polybar/config.ini diff --git a/tests/modules/services/polybar/default.nix b/tests/modules/services/polybar/default.nix index 94d5d3cde..b5594d247 100644 --- a/tests/modules/services/polybar/default.nix +++ b/tests/modules/services/polybar/default.nix @@ -1 +1,4 @@ -{ polybar-basic-configuration = ./basic-configuration.nix; } +{ + polybar-basic-configuration = ./basic-configuration.nix; + polybar-empty-configuration = ./empty-configuration.nix; +} diff --git a/tests/modules/services/polybar/empty-configuration.nix b/tests/modules/services/polybar/empty-configuration.nix new file mode 100644 index 000000000..e4f2fb4a0 --- /dev/null +++ b/tests/modules/services/polybar/empty-configuration.nix @@ -0,0 +1,21 @@ +{ config, pkgs, ... }: + +{ + config = { + services.polybar = { + enable = true; + package = config.lib.test.mkStubPackage { }; + script = "polybar bar &"; + }; + + nmt.script = '' + serviceFile=home-files/.config/systemd/user/polybar.service + + assertFileExists $serviceFile + assertFileRegex $serviceFile 'X-Restart-Triggers=.*/.config/polybar/config.ini' + assertFileRegex $serviceFile 'ExecStart=.*/bin/polybar-start' + + assertPathNotExists home-files/.config/polybar/config.ini + ''; + }; +}