2023-10-15 14:03:18 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let cfg = config.services.cliphist;
|
|
|
|
in {
|
2025-01-30 12:19:52 -06:00
|
|
|
meta.maintainers = [ lib.hm.maintainers.janik lib.maintainers.khaneliman ];
|
2023-10-15 14:03:18 +02:00
|
|
|
|
2025-01-29 12:26:13 -06:00
|
|
|
imports = [
|
|
|
|
(lib.mkRenamedOptionModule [ "services" "cliphist" "systemdTarget" ] [
|
|
|
|
"services"
|
|
|
|
"cliphist"
|
|
|
|
"systemdTargets"
|
|
|
|
])
|
|
|
|
];
|
|
|
|
|
2023-10-15 14:03:18 +02:00
|
|
|
options.services.cliphist = {
|
|
|
|
enable =
|
|
|
|
lib.mkEnableOption "cliphist, a clipboard history “manager” for wayland";
|
|
|
|
|
|
|
|
package = lib.mkPackageOption pkgs "cliphist" { };
|
|
|
|
|
2024-04-28 23:51:59 +02:00
|
|
|
allowImages = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Store images in clipboard history.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-05 15:37:54 +08:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2025-01-29 12:26:13 -06:00
|
|
|
systemdTargets = lib.mkOption {
|
|
|
|
type = with lib.types; either (listOf str) str;
|
|
|
|
default = [ "graphical-session.target" ];
|
2023-10-15 14:03:18 +02:00
|
|
|
example = "sway-session.target";
|
|
|
|
description = ''
|
2025-01-29 12:26:13 -06:00
|
|
|
The systemd targets that will automatically start the cliphist service.
|
2023-10-15 14:03:18 +02:00
|
|
|
|
2025-01-29 12:26:13 -06:00
|
|
|
When setting this value to `["sway-session.target"]`,
|
2023-10-15 14:03:18 +02:00
|
|
|
make sure to also enable {option}`wayland.windowManager.sway.systemd.enable`,
|
|
|
|
otherwise the service may never be started.
|
2025-01-29 12:26:13 -06:00
|
|
|
|
|
|
|
Note: A single string value is deprecated, please use a list.
|
2023-10-15 14:03:18 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-05 15:37:54 +08:00
|
|
|
config = let extraOptionsStr = lib.escapeShellArgs cfg.extraOptions;
|
|
|
|
in lib.mkIf cfg.enable {
|
2023-10-15 14:03:18 +02:00
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "services.cliphist" pkgs
|
|
|
|
lib.platforms.linux)
|
|
|
|
];
|
|
|
|
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
|
|
|
systemd.user.services.cliphist = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Clipboard management daemon";
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
Type = "simple";
|
|
|
|
ExecStart =
|
2024-05-05 15:37:54 +08:00
|
|
|
"${pkgs.wl-clipboard}/bin/wl-paste --watch ${cfg.package}/bin/cliphist ${extraOptionsStr} store";
|
2023-10-15 14:03:18 +02:00
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
|
2025-01-29 12:26:13 -06:00
|
|
|
Install = { WantedBy = lib.toList cfg.systemdTargets; };
|
2023-10-15 14:03:18 +02:00
|
|
|
};
|
2024-04-28 23:51:59 +02:00
|
|
|
|
|
|
|
systemd.user.services.cliphist-images = lib.mkIf cfg.allowImages {
|
|
|
|
Unit = {
|
|
|
|
Description = "Clipboard management daemon - images";
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
Type = "simple";
|
|
|
|
ExecStart =
|
2024-05-05 15:37:54 +08:00
|
|
|
"${pkgs.wl-clipboard}/bin/wl-paste --type image --watch ${cfg.package}/bin/cliphist ${extraOptionsStr} store";
|
2024-04-28 23:51:59 +02:00
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
|
2025-01-29 12:26:13 -06:00
|
|
|
Install = { WantedBy = lib.toList cfg.systemdTargets; };
|
2024-04-28 23:51:59 +02:00
|
|
|
};
|
2023-10-15 14:03:18 +02:00
|
|
|
};
|
|
|
|
}
|