From 1891bc8b06adb590cfe8752347ddf54f1948fd53 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Wed, 24 Jul 2024 22:39:23 -0500 Subject: [PATCH] cliphist: support multiple systemdTargets properly Using a space separated list of targets as a single string element in the list doesn't work properly. Change property to support list of targets and backwards compatibility with warning for single string. --- modules/services/cliphist.nix | 24 +++++++++++++------ .../cliphist-multiple-session-targets.nix | 20 ++++++++++++++++ .../cliphist/cliphist-sway-session-target.nix | 10 +++++++- tests/modules/services/cliphist/default.nix | 1 + 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 tests/modules/services/cliphist/cliphist-multiple-session-targets.nix diff --git a/modules/services/cliphist.nix b/modules/services/cliphist.nix index 1877a6de0..eb676be47 100644 --- a/modules/services/cliphist.nix +++ b/modules/services/cliphist.nix @@ -3,6 +3,14 @@ let cfg = config.services.cliphist; in { meta.maintainers = [ lib.hm.maintainers.janik ]; + imports = [ + (lib.mkRenamedOptionModule [ "services" "cliphist" "systemdTarget" ] [ + "services" + "cliphist" + "systemdTargets" + ]) + ]; + options.services.cliphist = { enable = lib.mkEnableOption "cliphist, a clipboard history “manager” for wayland"; @@ -25,16 +33,18 @@ in { ''; }; - systemdTarget = lib.mkOption { - type = lib.types.str; - default = "graphical-session.target"; + systemdTargets = lib.mkOption { + type = with lib.types; either (listOf str) str; + default = [ "graphical-session.target" ]; example = "sway-session.target"; description = '' - The systemd target that will automatically start the cliphist service. + The systemd targets that will automatically start the cliphist service. - When setting this value to `"sway-session.target"`, + When setting this value to `["sway-session.target"]`, make sure to also enable {option}`wayland.windowManager.sway.systemd.enable`, otherwise the service may never be started. + + Note: A single string value is deprecated, please use a list. ''; }; }; @@ -61,7 +71,7 @@ in { Restart = "on-failure"; }; - Install = { WantedBy = [ cfg.systemdTarget ]; }; + Install = { WantedBy = lib.toList cfg.systemdTargets; }; }; systemd.user.services.cliphist-images = lib.mkIf cfg.allowImages { @@ -77,7 +87,7 @@ in { Restart = "on-failure"; }; - Install = { WantedBy = [ cfg.systemdTarget ]; }; + Install = { WantedBy = lib.toList cfg.systemdTargets; }; }; }; } diff --git a/tests/modules/services/cliphist/cliphist-multiple-session-targets.nix b/tests/modules/services/cliphist/cliphist-multiple-session-targets.nix new file mode 100644 index 000000000..e4c0e828c --- /dev/null +++ b/tests/modules/services/cliphist/cliphist-multiple-session-targets.nix @@ -0,0 +1,20 @@ +{ ... }: + +{ + services.cliphist = { + enable = true; + + systemdTargets = [ "sway-session.target" "hyprland-session.target" ]; + }; + + test.stubs = { + cliphist = { }; + wl-clipboard = { }; + }; + + nmt.script = '' + assertFileExists home-files/.config/systemd/user/cliphist.service + assertFileExists home-files/.config/systemd/user/sway-session.target.wants/cliphist.service + assertFileExists home-files/.config/systemd/user/hyprland-session.target.wants/cliphist.service + ''; +} diff --git a/tests/modules/services/cliphist/cliphist-sway-session-target.nix b/tests/modules/services/cliphist/cliphist-sway-session-target.nix index 25da0f137..71171be78 100644 --- a/tests/modules/services/cliphist/cliphist-sway-session-target.nix +++ b/tests/modules/services/cliphist/cliphist-sway-session-target.nix @@ -1,4 +1,4 @@ -{ ... }: +{ lib, options, ... }: { services.cliphist = { @@ -13,5 +13,13 @@ nmt.script = '' assertFileExists home-files/.config/systemd/user/cliphist.service + assertFileExists home-files/.config/systemd/user/sway-session.target.wants/cliphist.service ''; + + test.asserts.warnings.expected = [ + "The option `services.cliphist.systemdTarget' defined in ${ + lib.showFiles options.services.cliphist.systemdTarget.files + } has been renamed to `services.cliphist.systemdTargets'." + ]; + } diff --git a/tests/modules/services/cliphist/default.nix b/tests/modules/services/cliphist/default.nix index d74a469b1..de05e0d00 100644 --- a/tests/modules/services/cliphist/default.nix +++ b/tests/modules/services/cliphist/default.nix @@ -1,4 +1,5 @@ { cliphist-sway-session-target = ./cliphist-sway-session-target.nix; cliphist-extra-options = ./cliphist-extra-options.nix; + cliphist-multiple-session-targets = ./cliphist-multiple-session-targets.nix; }