From a211d2bd5946b7cc2db01e2f786cce8c0d7ad4f1 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 20 Nov 2026 01:50:44 +0000 Subject: configs/hermes: run hermes as hermes in a tmux, attach as root The console is root's again. hermes runs as hermes in a tmux started by hermes-tmux.service, and root's login shell attaches to it; detaching gives root's shell back. tmux lets root attach to another user's server. Quitting hermes ends the session, and systemd starts a new one. --- configs/hermes.nix | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'configs/hermes.nix') diff --git a/configs/hermes.nix b/configs/hermes.nix index b963349..2cf40e9 100644 --- a/configs/hermes.nix +++ b/configs/hermes.nix @@ -1,8 +1,9 @@ # Hermes Agent (Nous Research), with its own NixOS module, fitted to this -# guest. Put ANTHROPIC_API_KEY=... into hermes.env in /xchg on the host; -# run hermes on the console. -{ config, lib, ... }: +# guest. Put ANTHROPIC_API_KEY=... into hermes.env in /xchg on the host. +# hermes runs as hermes in a tmux, which root's console opens. +{ config, lib, pkgs, ... }: let + tmux = "${pkgs.tmux}/bin/tmux -S /run/hermes/tmux"; # Not a flake input: flake-compat evaluates hermes-agent's flake, with its # flake.lock, using plain nix. Bump rev and sha256 together. flake-compat = builtins.fetchTarball { @@ -32,10 +33,26 @@ in environmentFiles = [ "/xchg/hermes.env" ]; }; - # The console is hermes', not root's. Its home is stateDir, so hermes - # there uses the service's state at ~/.hermes. - services.getty.autologinUser = lib.mkForce "hermes"; - users.users.hermes.packages = [ config.services.hermes-agent.package ]; + # 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. + 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}"; + Restart = "always"; + }; + }; + # Detaching gets root's shell back. + programs.bash.loginShellInit = '' + if [ "$USER" = root ] && [ -z "$TMUX" ]; then ${tmux} attach -t hermes; fi + ''; # nixos-init doesn't run activation scripts, and that's where the module # creates the state and installs config.yaml and .env. -- cgit v1.3.1