From 210a2607359bc79c5ee2435833287dc89cfb4d19 Mon Sep 17 00:00:00 2001 From: alexion Date: Wed, 22 Jul 2026 19:05:33 -0400 Subject: [PATCH] feat(desktop): add clipboard history (task 0027) Add a clipboard module to the desktop group, enabled through the aggregator. Home-manager's services.cliphist runs the text and image watchers as systemd user services bound to the graphical-session target, and a rofi-dmenu picker recalls history on Super+Shift+V. wl-clipboard is on PATH so the shell can pipe to and from the clipboard. --- .../tasks/0027-cliphist-clipboard-history.md | 22 +++++++-- modules/desktop/clipboard.nix | 48 +++++++++++++++++++ modules/desktop/desktop.nix | 1 + 3 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 modules/desktop/clipboard.nix diff --git a/.claude/tasks/0027-cliphist-clipboard-history.md b/.claude/tasks/0027-cliphist-clipboard-history.md index 41df264..f19c0cd 100644 --- a/.claude/tasks/0027-cliphist-clipboard-history.md +++ b/.claude/tasks/0027-cliphist-clipboard-history.md @@ -12,7 +12,21 @@ Bind the picker on `Super+Shift+V`. ## Acceptance criteria -- [ ] A cliphist module (with wl-clipboard) exists in the desktop group and is enabled by the aggregator. -- [ ] Text and image copies are recorded to history. -- [ ] The history is picked through rofi and bound on `Super+Shift+V`. -- [ ] neogaia builds green under `nix flake check`. +- [x] A cliphist module (with wl-clipboard) exists in the desktop group and is enabled by the aggregator. +- [x] Text and image copies are recorded to history. +- [x] The history is picked through rofi and bound on `Super+Shift+V`. +- [x] neogaia builds green under `nix flake check`. + +## Implementation Notes + +- The module is named `clipboard`, not `cliphist`: cliphist is the tool it is built on, but the option a host enables names the capability. +- The two clipboard watchers are not hand-written: home-manager's `services.cliphist` module runs them as a pair of systemd user services, one for text and one for `--type image`. + `allowImages` defaults true, so enabling the service alone records both kinds. +- That module installs only `cliphist` on PATH and reaches `wl-clipboard` by store path, so `wl-copy`/`wl-paste` are added to `home.packages` here. + The spec asks for the module "with wl-clipboard", and a keyboard-driven session wants the two commands for piping to and from the clipboard. +- The services bind to `graphical-session.target`, which uwsm starts, matching how mako and hypridle attach to the session on this host. + No `systemdTargets` override is needed, since the module's default already resolves to that target. +- The picker is a small shell script over the same themed rofi the launcher uses (`cliphist list | rofi -dmenu | cliphist decode | wl-copy`), so history looks like every other menu. + Its keybind lives in this module rather than in `hyprland.nix`, contributed through `settings.bind`, keeping the command next to its binding and referenced by store path. +- No Waybar `window-rewrite` icon mapping was added: the watchers are headless daemons and the picker is a rofi layer surface, so nothing new ever appears as a tiled window on the workspace indicator the convention governs. +- Image entries render as a `[[ binary data … ]]` placeholder line in the rofi list rather than a thumbnail, but selecting one still decodes and re-copies the real image, so both kinds are retrievable. diff --git a/modules/desktop/clipboard.nix b/modules/desktop/clipboard.nix new file mode 100644 index 0000000..d993abf --- /dev/null +++ b/modules/desktop/clipboard.nix @@ -0,0 +1,48 @@ +{ + config, + lib, + pkgs, + ... +}: +# Clipboard history: cliphist records every copy, picked back through rofi. +let + cfg = config.modules.desktop.clipboard; + user = config.user.name; + + cliphist = "${pkgs.cliphist}/bin/cliphist"; + rofi = "${pkgs.rofi}/bin/rofi"; + wl-copy = "${pkgs.wl-clipboard}/bin/wl-copy"; + + # The picker reuses the themed rofi, so history looks like every other menu + # the launcher drives. + # decode is needed because list emits id-prefixed lines rather than the copied + # bytes, so the chosen id has to be resolved back before it can be re-copied. + picker = pkgs.writeShellScript "clipboard-picker" '' + ${cliphist} list \ + | ${rofi} -dmenu -i -p Clipboard \ + | ${cliphist} decode \ + | ${wl-copy} + ''; +in +{ + options.modules.desktop.clipboard.enable = lib.mkEnableOption "cliphist clipboard history"; + + config = lib.mkIf cfg.enable { + home-manager.users.${user} = { + # wl-copy and wl-paste on PATH, so the shell can pipe into and out of the + # clipboard. + # The watchers and picker above reach wl-clipboard by store path, so this + # is for interactive use alone. + home.packages = [ pkgs.wl-clipboard ]; + + # Two watchers record text and images to history, bound to the graphical + # session so uwsm starts and stops them with it. + services.cliphist.enable = true; + + # $mod is defined by the compositor config these binds share. + wayland.windowManager.hyprland.settings.bind = [ + "$mod SHIFT, V, exec, ${picker}" + ]; + }; + }; +} diff --git a/modules/desktop/desktop.nix b/modules/desktop/desktop.nix index e2dd2b3..18c9235 100644 --- a/modules/desktop/desktop.nix +++ b/modules/desktop/desktop.nix @@ -9,6 +9,7 @@ in # Each piece is turned on at default priority, so a host can still override # any one of them while the single flag above enables the whole desktop. config = lib.mkIf cfg.enable { + modules.desktop.clipboard.enable = lib.mkDefault true; modules.desktop.hyprland.enable = lib.mkDefault true; modules.desktop.hyprlock.enable = lib.mkDefault true; modules.desktop.hypridle.enable = lib.mkDefault true;