clipcat: add module (#6946)

This commit is contained in:
Aguirre Matteo 2025-05-02 13:22:35 +00:00 committed by GitHub
parent c5cad190ba
commit f15be4feb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 263 additions and 0 deletions

View file

@ -333,6 +333,7 @@ let
./services/cachix-agent.nix
./services/caffeine.nix
./services/cbatticon.nix
./services/clipcat.nix
./services/cliphist.nix
./services/clipman.nix
./services/clipmenu.nix

View file

@ -0,0 +1,164 @@
{
lib,
pkgs,
config,
...
}:
let
inherit (lib)
types
mkIf
mkEnableOption
mkPackageOption
mkOption
;
cfg = config.services.clipcat;
formatter = pkgs.formats.toml { };
in
{
meta.maintainers = with lib.hm.maintainers; [ aguirre-matteo ];
options.services.clipcat = {
enable = mkEnableOption "clipcat";
package = mkPackageOption pkgs "clipcat" { };
enableZshIntegration = lib.hm.shell.mkZshIntegrationOption { inherit config; };
enableSystemdUnit = mkOption {
type = types.bool;
default = true;
example = false;
description = ''
Enable clipcat's Systemd Unit.
'';
};
daemonSettings = mkOption {
type = formatter.type;
default = {
daemonize = true;
};
example = ''
{
daemonize = true;
max_history = 50;
history_file_path = "/home/<username>/.cache/clipcat/clipcatd-history";
pid_file = "/run/user/<user-id>/clipcatd.pid";
primary_threshold_ms = 5000;
log = {
file_path = "/path/to/log/file";
emit_journald = true;
emit_stdout = false;
emit_stderr = false;
level = "INFO";
};
}
'';
description = ''
Configuration settings for clipcatd. All available options can be found
here: <https://github.com/xrelkd/clipcat?tab=readme-ov-file#configuration>.
'';
};
ctlSettings = mkOption {
type = formatter.type;
default = { };
example = ''
{
server_endpoint = "/run/user/<user-id>/clipcat/grpc.sock";
log = {
file_path = "/path/to/log/file";
emit_journald = true;
emit_stdout = false;
emit_stderr = false;
level = "INFO";
};
}
'';
description = ''
Configuration settings for clipcatctl. All available options can be found
here: <https://github.com/xrelkd/clipcat?tab=readme-ov-file#configuration>.
'';
};
menuSettings = mkOption {
type = formatter.type;
default = { };
example = ''
{
server_endpoint = "/run/user/<user-id>/clipcat/grpc.sock";
finder = "rofi";
rofi = {
line_length = 100;
menu_length = 30;
menu_prompt = "Clipcat";
extra_arguments = [
"-mesg"
"Please select a clip"
];
};
dmenu = {
line_length = 100;
menu_length = 30;
menu_prompt = "Clipcat";
};
}
'';
description = ''
Configuration settings for clipcat-menu. All available options can be found
here: <https://github.com/xrelkd/clipcat?tab=readme-ov-file#configuration>.
'';
};
};
config = mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "services.clipcat" pkgs lib.platforms.linux)
];
home.packages = [ cfg.package ];
programs.zsh.initContent = mkIf cfg.enableZshIntegration ''
if type clipcat-menu >/dev/null 2>&1; then
alias clipedit=' clipcat-menu --finder=builtin edit'
alias clipdel=' clipcat-menu --finder=builtin remove'
bindkey -s '^\' "^Q clipcat-menu --finder=builtin insert ^J"
bindkey -s '^]' "^Q clipcat-menu --finder=builtin remove ^J"
fi
'';
systemd.user.services.clipcat = mkIf cfg.enableSystemdUnit {
Unit = {
Description = "Clipcat Daemon";
PartOf = "graphical-session.target";
};
Install.WantedBy = [ "graphical-session.target" ];
Service = {
ExecStartPre = "${pkgs.writeShellScript "clipcatd-exec-start-pre" ''
PATH=/run/current-system/sw/bin:
rm -f %t/clipcat/grpc.sock
''}";
ExecStart = "${pkgs.writeShellScript "clipcatd-exec-start" ''
PATH=/run/current-system/sw/bin:
${cfg.package}/bin/clipcatd --no-daemon --replace
''}";
Restart = "on-failure";
Type = "simple";
};
};
xdg.configFile = {
"clipcat/clipcatd.toml" = mkIf (cfg.daemonSettings != { }) {
source = formatter.generate "clipcatd.toml" cfg.daemonSettings;
};
"clipcat/clipcatctl.toml" = mkIf (cfg.ctlSettings != { }) {
source = formatter.generate "clipcatctl.toml" cfg.ctlSettings;
};
"clipcat/clipcat-menu.toml" = mkIf (cfg.menuSettings != { }) {
source = formatter.generate "clipcat-menu.toml" cfg.menuSettings;
};
};
};
}

View file

@ -408,6 +408,7 @@ import nmtSrc {
./modules/services/blanket
./modules/services/borgmatic
./modules/services/cachix-agent
./modules/services/clipcat
./modules/services/cliphist
./modules/services/clipman
./modules/services/clipse

View file

@ -0,0 +1,7 @@
server_endpoint = "/run/user/<user-id>/clipcat/grpc.sock"
[log]
emit_journald = true
emit_stderr = false
emit_stdout = false
file_path = "/path/to/log/file"
level = "INFO"

View file

@ -0,0 +1,12 @@
daemonize = true
history_file_path = "/home/<username>/.cache/clipcat/clipcatd-history"
max_history = 50
pid_file = "/run/user/<user-id>/clipcatd.pid"
primary_threshold_ms = 5000
[log]
emit_journald = true
emit_stderr = false
emit_stdout = false
file_path = "/path/to/log/file"
level = "INFO"

View file

@ -0,0 +1,12 @@
finder = "rofi"
server_endpoint = "/run/user/<user-id>/clipcat/grpc.sock"
[dmenu]
line_length = 100
menu_length = 30
menu_prompt = "Clipcat"
[rofi]
extra_arguments = ["-mesg", "Please select a clip"]
line_length = 100
menu_length = 30
menu_prompt = "Clipcat"

View file

@ -0,0 +1 @@
{ clipcat-example-config = ./example-config.nix; }

View file

@ -0,0 +1,65 @@
{
services.clipcat = {
enable = true;
daemonSettings = {
daemonize = true;
max_history = 50;
history_file_path = "/home/<username>/.cache/clipcat/clipcatd-history";
pid_file = "/run/user/<user-id>/clipcatd.pid";
primary_threshold_ms = 5000;
log = {
file_path = "/path/to/log/file";
emit_journald = true;
emit_stdout = false;
emit_stderr = false;
level = "INFO";
};
};
ctlSettings = {
server_endpoint = "/run/user/<user-id>/clipcat/grpc.sock";
log = {
file_path = "/path/to/log/file";
emit_journald = true;
emit_stdout = false;
emit_stderr = false;
level = "INFO";
};
};
menuSettings = {
server_endpoint = "/run/user/<user-id>/clipcat/grpc.sock";
finder = "rofi";
rofi = {
line_length = 100;
menu_length = 30;
menu_prompt = "Clipcat";
extra_arguments = [
"-mesg"
"Please select a clip"
];
};
dmenu = {
line_length = 100;
menu_length = 30;
menu_prompt = "Clipcat";
};
};
};
nmt.script = ''
assertFileExists home-files/.config/clipcat/clipcatd.toml
assertFileExists home-files/.config/clipcat/clipcatctl.toml
assertFileExists home-files/.config/clipcat/clipcat-menu.toml
assertFileContent home-files/.config/clipcat/clipcatd.toml \
${./cfg/daemon.toml}
assertFileContent home-files/.config/clipcat/clipcatctl.toml \
${./cfg/ctl.toml}
assertFileContent home-files/.config/clipcat/clipcat-menu.toml \
${./cfg/menu.toml}
'';
}