cliphist: add maxDedupeSearch and maxItems options

Add the maxDedupeSearch and maxItems options that correspond to
cliphist's -max-dedupe-search and -max-items flags respectively.
This commit is contained in:
ErrorNoInternet 2024-05-01 13:02:57 +08:00
parent 6d3b6dc922
commit 3489474672
No known key found for this signature in database
GPG Key ID: 2486BFB7B1E6A4A3
3 changed files with 54 additions and 4 deletions

View File

@ -17,6 +17,22 @@ in {
'';
};
maxDedupeSearch = lib.mkOption {
type = lib.types.int;
default = 100;
description = ''
Maximum number of last items to look through when finding duplicates.
'';
};
maxItems = lib.mkOption {
type = lib.types.int;
default = 750;
description = ''
Maximum number of items to store.
'';
};
systemdTarget = lib.mkOption {
type = lib.types.str;
default = "graphical-session.target";
@ -31,7 +47,11 @@ in {
};
};
config = lib.mkIf cfg.enable {
config = let
cliphistFlags =
"-max-dedupe-search ${builtins.toString cfg.maxDedupeSearch} "
+ "-max-items ${builtins.toString cfg.maxItems}";
in lib.mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "services.cliphist" pkgs
lib.platforms.linux)
@ -48,7 +68,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 ${cliphistFlags} store";
Restart = "on-failure";
};
@ -64,7 +84,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 ${cliphistFlags} store";
Restart = "on-failure";
};

View File

@ -0,0 +1,27 @@
{ ... }:
{
services.cliphist = {
enable = true;
allowImages = true;
maxDedupeSearch = 10;
maxItems = 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 '
'';
}

View File

@ -1 +1,4 @@
{ cliphist-sway-session-target = ./cliphist-sway-session-target.nix; }
{
cliphist-sway-session-target = ./cliphist-sway-session-target.nix;
cliphist-extra-flags = ./cliphist-extra-flags.nix;
}