# 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. # 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 { url = "https://github.com/edolstra/flake-compat/archive/5edf11c44bc78a0d334f6334cdaf7d60d732daab.tar.gz"; sha256 = "0yqfa6rx8md81bcn4szfp0hjq2f3h9i8zjzhqqyfqdkrj5559nmw"; }; hermes-agent = (import flake-compat { src = builtins.fetchTarball { url = "https://github.com/NousResearch/hermes-agent/archive/9f47677483d1b4de4d1a88d37b3b7ca18b18b215.tar.gz"; sha256 = "1xpvwgmn5slmfc2zsr5bfgywz1c6dqx3i5qy6ppbdvg1j2vngx71"; }; }).defaultNix; in { imports = [ hermes-agent.nixosModules.default ]; services.hermes-agent = { enable = true; # /var is a tmpfs. This is on the only drive that can outlive a boot, # like nix's database, see /nix/var. stateDir = "/nix/.rw-store/hermes"; settings.model = { provider = "anthropic"; default = "claude-opus-5-5"; }; # Read at boot; a missing file only gets a warning. environmentFiles = [ "/xchg/hermes.env" ]; }; # 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. systemd.services.hermes-agent-setup = { requiredBy = [ "hermes-agent.service" ]; before = [ "hermes-agent.service" ]; serviceConfig.Type = "oneshot"; serviceConfig.RemainAfterExit = true; script = config.system.activationScripts.hermes-agent-setup.text; }; # users.manageLingering is off here. Without a user manager, hermes' # cron can't run jobs; nothing else needs one. users.users.hermes.linger = null; }