From a6068061f81df251fbf94ac417bf8b83fdcead41 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 20 Nov 2026 16:56:19 +0000 Subject: configs/hermes: socket-activate hermes' tmux, clean plugin copies hermes-tmux.service started at boot and restarted hermes whenever it quit, and as its RuntimeDirectory, /run/hermes went away whenever it stopped, so attaching failed with "error creating /run/hermes/tmux". Now hermes-tmux.socket holds /run/hermes/tmux, and the first client starts tmux (-D, on systemd's socket), whose config starts hermes in session hermes. Quitting hermes ends the session, and with exit-empty the server and the service, until the next client. Detaching doesn't. Hermes imports provider plugins from copies under ~/.hermes/runtime/provider-plugins, a set per process, reclaimed by later processes. Copies of the read-only plugin from before couldn't be removed, and crashes leave theirs: remove them all at boot, before any Hermes runs. --- configs/hermes.nix | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'configs/hermes.nix') diff --git a/configs/hermes.nix b/configs/hermes.nix index ab04b15..93dbfbf 100644 --- a/configs/hermes.nix +++ b/configs/hermes.nix @@ -138,19 +138,27 @@ in nixpkgs.config.allowUnfreePredicate = pkg: lib.getName pkg == "claude-code"; # hermes' home is stateDir, so this uses the service's state at ~/.hermes. - # tmux lets root attach to it. Quitting hermes ends the session, and - # systemd starts a new one. + # tmux lets root attach to it. Socket-activated: the first client + # starts the server, whose config starts hermes, and quitting hermes + # ends the session and the server (exit-empty), until the next client. + systemd.sockets.hermes-tmux = { + wantedBy = [ "sockets.target" ]; + socketConfig = { + ListenStream = "/run/hermes/tmux"; + SocketUser = "hermes"; + SocketMode = "0600"; + }; + }; systemd.services.hermes-tmux = { - wantedBy = [ "multi-user.target" ]; requires = [ "hermes-agent-setup.service" ]; after = [ "hermes-agent-setup.service" ]; - before = [ "serial-getty@ttyS0.service" ]; serviceConfig = { - Type = "forking"; User = "hermes"; - RuntimeDirectory = "hermes"; - ExecStart = "${tmux} new-session -d -s hermes ${lib.getExe config.services.hermes-agent.package} --tui"; - Restart = "always"; + # -D: in the foreground, on the socket from systemd. + ExecStart = "${pkgs.tmux}/bin/tmux -D -f ${pkgs.writeText "hermes-tmux.conf" '' + set -s exit-empty on + new-session -d -s hermes ${lib.getExe config.services.hermes-agent.package} --tui + ''}"; }; inherit (config.systemd.services.hermes-agent) path; }; @@ -186,6 +194,12 @@ in cp -r --no-preserve=mode ${claude-subscription-directsdk} "$p" chown -R hermes:hermes "$p" + # Hermes imports provider plugins from copies under runtime, one set + # per process, reclaimed by later processes when nothing holds them. + # Copies of a read-only plugin couldn't be removed, and a crash + # leaves its own; no Hermes runs yet, so none is in use. + rm -rf ${config.services.hermes-agent.stateDir}/.hermes/runtime/provider-plugins + # Writable for hermes, too, see HERMES_MANAGED below. chmod 0660 ${config.services.hermes-agent.stateDir}/.hermes/config.yaml ''; -- cgit v1.3.1