From 06ed7fde89587c506bf483e173a0c6d0d79fc07c Mon Sep 17 00:00:00 2001 From: Jonathan Mohrbacher Date: Wed, 2 Dec 2026 15:57:14 -0500 Subject: [PATCH] [NO-JIRA] Restart gclpr-server on home-switch when trusted keys change --- .agents/skills/clipboard/SKILL.md | 13 ++++++++++--- users/dev/home.darwin.nix | 32 +++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/.agents/skills/clipboard/SKILL.md b/.agents/skills/clipboard/SKILL.md index 6d9c3142..ef909103 100644 --- a/.agents/skills/clipboard/SKILL.md +++ b/.agents/skills/clipboard/SKILL.md @@ -75,6 +75,10 @@ hex line each in `.gclpr/trusted` in `users/dev/home.darwin.nix`; `#` lines are Adding or replacing a host key therefore also needs a `home-switch` on the Mac (user config, no root), and on the NixOS host a `nixos-rebuild switch` (refreshes `/run/secrets`) followed by a home-manager switch (re-runs the activation that copies it into `~/.gclpr/key`). +Because `gclpr server` reads `~/.gclpr/trusted` only at startup, `users/dev/home.darwin.nix` +hashes the trusted-keys content into `GCLPR_TRUSTED_SHA256` on the `gclpr-server` launchd +plist so `home-switch` automatically restarts `org.nix-community.home.gclpr-server` +whenever `.gclpr/trusted` changes (after `linkGeneration` updates the symlink). ## Testing @@ -123,10 +127,13 @@ printf '\033]52;c;%s\007' "$(printf 'test-raw' | base64 | tr -d '\n')" 2. Verify the port is listening on the remote host: `netstat -tulpn | grep 2850` 3. Verify the macOS server is running: `launchctl list | grep gclpr` or `lsof -i :2850` on macOS. -**"authentication failed" or "bad signature":** +**"authentication failed", "bad signature", or `*** ERROR: unexpected EOF`:** 1. Verify the private key exists on the remote host: `ls -la ~/.gclpr/key` (should be 64 bytes, mode 400) -2. Verify the public key matches: compare `xxd ~/.gclpr/key.pub` on remote with the hex in `~/.gclpr/trusted` on macOS -3. Re-deploy keys: `nix run home-manager -- switch --flake .#dev` on remote +2. Verify the public key matches: compare `od -An -tx1 ~/.gclpr/key.pub | tr -d ' \n'` on remote with the hex in `~/.gclpr/trusted` on macOS +3. Verify `gclpr server` on macOS started *after* `~/.gclpr/trusted` was updated (`gclpr server` only reads `~/.gclpr/trusted` at startup, and rejects unknown keys by closing the connection, which surfaces on the client as `*** ERROR: unexpected EOF`): + `ps -o pid,lstart,command -p "$(pgrep -f 'gclpr server')"` vs `ls -la ~/.gclpr/trusted`. + If stale, restart it: `launchctl kickstart -k "gui/$(id -u)/org.nix-community.home.gclpr-server"` +4. Re-deploy keys: `nix run home-manager -- switch --flake .#dev` (or `.#cloudbox`) on remote, and `home-switch` on macOS **Clipboard dies for a few minutes, then recovers on its own:** Check `~/Library/Logs/cloudbox-dev-tunnel.err.log` (or `devbox-…`) on the Mac. Repeated diff --git a/users/dev/home.darwin.nix b/users/dev/home.darwin.nix index db775366..ca87550b 100644 --- a/users/dev/home.darwin.nix +++ b/users/dev/home.darwin.nix @@ -214,22 +214,31 @@ let if [ "$delay" -gt 60 ]; then delay=60; fi done ''; + + # gclpr clipboard bridge trusted keys (macOS server). One hex public key + # per line; gclpr skips blank lines and lines starting with '#'. Each + # NixOS host has its own keypair; the private half is gclpr_private_key + # in secrets/.yaml. + # + # Bound here so `~/.gclpr/trusted` and `launchd.agents.gclpr-server` share + # one source: `gclpr server` reads trusted keys only at startup, so hashing + # this string into the plist makes home-manager's `setupLaunchAgents` + # bootout/bootstrap the agent when keys change (after `linkGeneration` has + # updated `~/.gclpr/trusted`) and leave it running on unrelated switches. + gclprTrusted = '' + # cloudbox (assets/gclpr/key.pub) + 482806af5b5b4fefe00021b17761cfb1be4a4b8ccc240ce8ad3d2f981cc61f92 + # devbox (assets/gclpr/devbox.pub) + 131beaeed315f7d7c6a6e34f609af119be894c6c01274be525eccd9f5841c0e3 + ''; in lib.mkIf isDarwin { home.file = { # Darwin common.conf - empty (no special options needed locally) ".gnupg/common.conf".text = ""; - # gclpr clipboard bridge trusted keys (macOS server). One hex public key - # per line; gclpr skips blank lines and lines starting with '#'. Each - # NixOS host has its own keypair; the private half is gclpr_private_key - # in secrets/.yaml. - ".gclpr/trusted".text = '' - # cloudbox (assets/gclpr/key.pub) - 482806af5b5b4fefe00021b17761cfb1be4a4b8ccc240ce8ad3d2f981cc61f92 - # devbox (assets/gclpr/devbox.pub) - 131beaeed315f7d7c6a6e34f609af119be894c6c01274be525eccd9f5841c0e3 - ''; + # gclpr clipboard bridge trusted keys (macOS server) — see `gclprTrusted` above. + ".gclpr/trusted".text = gclprTrusted; }; @@ -1104,6 +1113,9 @@ lib.mkIf isDarwin { HOME = config.home.homeDirectory; LANG = "en_US.UTF-8"; LC_CTYPE = "en_US.UTF-8"; + # gclpr reads ~/.gclpr/trusted only at startup; hashing it into the + # plist triggers setupLaunchAgents to bootout/bootstrap on key changes. + GCLPR_TRUSTED_SHA256 = builtins.hashString "sha256" gclprTrusted; }; RunAtLoad = true; KeepAlive = true;