From f69bf670d29d3921e00cc626d174654769d743c6 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 5 May 2024 15:37:54 +0800 Subject: [PATCH] cliphist: add extraOptions option Add an extraOptions option that would be appended to the cliphist command. --- modules/services/cliphist.nix | 15 +++++++++--- .../cliphist/cliphist-extra-options.nix | 24 +++++++++++++++++++ tests/modules/services/cliphist/default.nix | 5 +++- 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 tests/modules/services/cliphist/cliphist-extra-options.nix diff --git a/modules/services/cliphist.nix b/modules/services/cliphist.nix index 504b519a4..3599557f0 100644 --- a/modules/services/cliphist.nix +++ b/modules/services/cliphist.nix @@ -17,6 +17,14 @@ in { ''; }; + extraOptions = lib.mkOption { + type = with lib.types; listOf str; + default = [ "-max-dedupe-search" "10" "-max-items" "500" ]; + description = '' + Flags to append to the cliphist command. + ''; + }; + systemdTarget = lib.mkOption { type = lib.types.str; default = "graphical-session.target"; @@ -31,7 +39,8 @@ in { }; }; - config = lib.mkIf cfg.enable { + config = let extraOptionsStr = lib.escapeShellArgs cfg.extraOptions; + in lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.cliphist" pkgs lib.platforms.linux) @@ -48,7 +57,7 @@ in { Service = { Type = "simple"; ExecStart = - "${pkgs.wl-clipboard}/bin/wl-paste --watch ${cfg.package}/bin/cliphist store"; + "${pkgs.wl-clipboard}/bin/wl-paste --watch ${cfg.package}/bin/cliphist ${extraOptionsStr} store"; Restart = "on-failure"; }; @@ -64,7 +73,7 @@ in { Service = { Type = "simple"; ExecStart = - "${pkgs.wl-clipboard}/bin/wl-paste --type image --watch ${cfg.package}/bin/cliphist store"; + "${pkgs.wl-clipboard}/bin/wl-paste --type image --watch ${cfg.package}/bin/cliphist ${extraOptionsStr} store"; Restart = "on-failure"; }; diff --git a/tests/modules/services/cliphist/cliphist-extra-options.nix b/tests/modules/services/cliphist/cliphist-extra-options.nix new file mode 100644 index 000000000..65d4fdca1 --- /dev/null +++ b/tests/modules/services/cliphist/cliphist-extra-options.nix @@ -0,0 +1,24 @@ +{ ... }: { + services.cliphist = { + enable = true; + allowImages = true; + extraOptions = [ "-max-dedupe-search" "10" "-max-items" "500" ]; + }; + + test.stubs = { + cliphist = { }; + wl-clipboard = { }; + }; + + nmt.script = '' + servicePath=home-files/.config/systemd/user + + assertFileExists $servicePath/cliphist.service + assertFileExists $servicePath/cliphist-images.service + + assertFileRegex $servicePath/cliphist.service " '-max-dedupe-search' '10' " + assertFileRegex $servicePath/cliphist.service " '-max-items' '500' " + assertFileRegex $servicePath/cliphist-images.service " '-max-dedupe-search' '10' " + assertFileRegex $servicePath/cliphist-images.service " '-max-items' '500' " + ''; +} diff --git a/tests/modules/services/cliphist/default.nix b/tests/modules/services/cliphist/default.nix index 011013322..d74a469b1 100644 --- a/tests/modules/services/cliphist/default.nix +++ b/tests/modules/services/cliphist/default.nix @@ -1 +1,4 @@ -{ cliphist-sway-session-target = ./cliphist-sway-session-target.nix; } +{ + cliphist-sway-session-target = ./cliphist-sway-session-target.nix; + cliphist-extra-options = ./cliphist-extra-options.nix; +}