From b3f3f50f9e83a22f70dd033fa7d598deaf607f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 18 Sep 2023 15:20:32 +0300 Subject: [PATCH] pasystray: add `extraOptions` Allows a user to, for example, add the `-g` option. Also add a basic test case. --- modules/services/pasystray.nix | 21 +++++++++++++++---- tests/default.nix | 1 + tests/modules/services/pasystray/default.nix | 1 + .../services/pasystray/expected.service | 13 ++++++++++++ tests/modules/services/pasystray/service.nix | 19 +++++++++++++++++ 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 tests/modules/services/pasystray/default.nix create mode 100644 tests/modules/services/pasystray/expected.service create mode 100644 tests/modules/services/pasystray/service.nix diff --git a/modules/services/pasystray.nix b/modules/services/pasystray.nix index 32922ad0f..4ea340d21 100644 --- a/modules/services/pasystray.nix +++ b/modules/services/pasystray.nix @@ -2,14 +2,26 @@ with lib; -{ +let cfg = config.services.pasystray; + +in { meta.maintainers = [ hm.maintainers.pltanton ]; options = { - services.pasystray = { enable = mkEnableOption "PulseAudio system tray"; }; + services.pasystray = { + enable = mkEnableOption "PulseAudio system tray"; + + extraOptions = mkOption { + type = types.listOf types.str; + default = [ ]; + description = '' + Extra command-line arguments to pass to {command}`pasystray`. + ''; + }; + }; }; - config = mkIf config.services.pasystray.enable { + config = mkIf cfg.enable { assertions = [ (hm.assertions.assertPlatform "services.pasystray" pkgs platforms.linux) ]; @@ -28,7 +40,8 @@ with lib; Environment = let toolPaths = makeBinPath [ pkgs.paprefs pkgs.pavucontrol ]; in [ "PATH=${toolPaths}" ]; - ExecStart = "${pkgs.pasystray}/bin/pasystray"; + ExecStart = escapeShellArgs + ([ "${pkgs.pasystray}/bin/pasystray" ] ++ cfg.extraOptions); }; }; }; diff --git a/tests/default.nix b/tests/default.nix index ecbbd726c..a13e66cd4 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -223,6 +223,7 @@ import nmt { ./modules/services/pantalaimon ./modules/services/parcellite ./modules/services/pass-secret-service + ./modules/services/pasystray ./modules/services/pbgopy ./modules/services/picom ./modules/services/playerctld diff --git a/tests/modules/services/pasystray/default.nix b/tests/modules/services/pasystray/default.nix new file mode 100644 index 000000000..0c0f31c5f --- /dev/null +++ b/tests/modules/services/pasystray/default.nix @@ -0,0 +1 @@ +{ pasystray-service = ./service.nix; } diff --git a/tests/modules/services/pasystray/expected.service b/tests/modules/services/pasystray/expected.service new file mode 100644 index 000000000..b2c23c518 --- /dev/null +++ b/tests/modules/services/pasystray/expected.service @@ -0,0 +1,13 @@ +[Install] +WantedBy=graphical-session.target + +[Service] +Environment=PATH=@paprefs@/bin:@pavucontrol@/bin +ExecStart='@pasystray@/bin/pasystray' '-g' + +[Unit] +After=graphical-session-pre.target +After=tray.target +Description=PulseAudio system tray +PartOf=graphical-session.target +Requires=tray.target diff --git a/tests/modules/services/pasystray/service.nix b/tests/modules/services/pasystray/service.nix new file mode 100644 index 000000000..5b8548c8b --- /dev/null +++ b/tests/modules/services/pasystray/service.nix @@ -0,0 +1,19 @@ +{ ... }: + +{ + services.pasystray = { + enable = true; + extraOptions = [ "-g" ]; + }; + + test.stubs = { + pasystray = { }; + paprefs = { }; + pavucontrol = { }; + }; + + nmt.script = '' + serviceFile=$(normalizeStorePaths home-files/.config/systemd/user/pasystray.service) + assertFileContent "$serviceFile" ${./expected.service} + ''; +}