The native hook command reads <data_dir>/auth-token, not the config's bearer_token_file; without it every Hermes event was spooled with a 401. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
390 lines
15 KiB
Nix
390 lines
15 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
inputs,
|
|
...
|
|
}: let
|
|
# Edge TTS: Seraphina — friendly, multilingual German female voice (free, no API key)
|
|
edgeVoice = "de-DE-SeraphinaMultilingualNeural";
|
|
|
|
hermesHome = "${config.services.hermes-agent.stateDir}/.hermes";
|
|
|
|
# Same interpreter env the upstream merge script uses, so no extra
|
|
# closure cost — the derivation is shared.
|
|
yamlPython = pkgs.python3.withPackages (ps: [ps.pyyaml]);
|
|
|
|
# ── ai-memory client (server: ./ai-memory.nix, same host) ─────────────
|
|
# The MCP bridge reads the bearer from [auth].bearer_token_file in the
|
|
# data dir's config.toml; the native `hook` command only looks at
|
|
# <data_dir>/auth-token (what `install-hooks --apply` would seed), so that
|
|
# file is a symlink to the same secret. Neither config.yaml nor the
|
|
# process environment ever carries the token.
|
|
aiMemory = "${config.services.ai-memory.package}/bin/ai-memory";
|
|
aiMemoryUrl = "http://127.0.0.1:${toString (config.m3ta.ports.get "ai-memory")}";
|
|
aiMemoryDataDir = "/var/lib/hermes/.local/share/ai-memory";
|
|
aiMemoryHook = event: [
|
|
{
|
|
command = "${aiMemory} --data-dir ${aiMemoryDataDir} hook --event ${event} --agent hermes --server-url ${aiMemoryUrl}";
|
|
timeout = 20;
|
|
}
|
|
];
|
|
in {
|
|
virtualisation.docker.enable = true;
|
|
|
|
systemd.tmpfiles.rules = [
|
|
"d /var/lib/hermes/.config 0755 hermes hermes -"
|
|
"d /var/lib/hermes/.config/tea 0755 hermes hermes -"
|
|
"d /var/lib/hermes/.local 0755 hermes hermes -"
|
|
"d /var/lib/hermes/.local/share 0755 hermes hermes -"
|
|
"d ${aiMemoryDataDir} 0700 hermes hermes -"
|
|
"L+ ${aiMemoryDataDir}/config.toml - - - - ${pkgs.writeText "ai-memory-hermes-config.toml" ''
|
|
server_url = "${aiMemoryUrl}"
|
|
|
|
[auth]
|
|
bearer_token_file = "${config.age.secrets."ai-memory-hermes-token".path}"
|
|
''}"
|
|
"L+ ${aiMemoryDataDir}/auth-token - - - - ${config.age.secrets."ai-memory-hermes-token".path}"
|
|
# Scope marker: Hermes reports its process directory as cwd, so every
|
|
# assistant session lands in one project of the `home` workspace
|
|
# (coding checkouts below $HOME with their own marker still win).
|
|
"L+ /var/lib/hermes/.ai-memory.toml - - - - ${pkgs.writeText "ai-memory-hermes-marker.toml" ''
|
|
workspace = "home"
|
|
project = "assistant"
|
|
|
|
[capture]
|
|
ignore_paths = ["/run/agenix/**", "**/.env*", "/var/lib/hermes/.hermes/auth*", "/var/lib/hermes/.ssh/**"]
|
|
''}"
|
|
"L+ /var/lib/hermes/.config/tea/yml - - - - ${pkgs.writeText "tea-yml" ''
|
|
logins:
|
|
- name: m3ta
|
|
url: https://code.m3ta.dev
|
|
token:
|
|
ssh_host: code.m3ta.dev
|
|
user: m3ta-chiron
|
|
default: true
|
|
''}"
|
|
];
|
|
|
|
services.hermes-agent = {
|
|
enable = true;
|
|
addToSystemPackages = true;
|
|
# v0.14 lazy-installs heavy optional backends by default. In the sealed
|
|
# Nix package, include the backends this host config actively uses so the
|
|
# gateway, Matrix bridge, memory, web search, TTS, and local STT work
|
|
# without runtime pip/uv mutation.
|
|
extraDependencyGroups = [
|
|
"matrix"
|
|
"exa"
|
|
"edge-tts"
|
|
"voice"
|
|
];
|
|
|
|
extraPackages = with pkgs; [
|
|
agent-lib
|
|
basecamp
|
|
docker
|
|
llm-agents.herdr
|
|
llm-agents.opencode2
|
|
pi-coding-agent
|
|
bun
|
|
git
|
|
curl
|
|
jq
|
|
tea
|
|
nix
|
|
python3Minimal
|
|
llm-agents.qmd
|
|
uv
|
|
];
|
|
|
|
# Secrets via agenix
|
|
environmentFiles = [
|
|
config.age.secrets."hermes-env".path
|
|
config.age.secrets."hermes-cloud-env".path
|
|
config.age.secrets."hermes-api-server-key".path
|
|
];
|
|
|
|
# Non-secret environment variables
|
|
# Git identity is set entirely via env vars (GIT_AUTHOR_*, GIT_COMMITTER_*,
|
|
# GIT_INIT_DEFAULT_BRANCH) — no .gitconfig file needed. Env vars take
|
|
# precedence over any gitconfig, and the hermes gateway injects them into
|
|
# all terminal sessions via .env.
|
|
environment = {
|
|
GLM_BASE_URL = "https://api.z.ai/api/coding/paas/v4/";
|
|
GIT_AUTHOR_NAME = "m3ta-chiron";
|
|
GIT_AUTHOR_EMAIL = "m3ta-chiron@agentmail.to";
|
|
GIT_COMMITTER_NAME = "m3ta-chiron";
|
|
GIT_COMMITTER_EMAIL = "m3ta-chiron@agentmail.to";
|
|
GIT_INIT_DEFAULT_BRANCH = "master";
|
|
|
|
# ── API Server (OpenAI-compatible, for Hermes Desktop App) ─────────
|
|
# Accessible via Netbird mesh VPN — not exposed to the public internet.
|
|
# Bind to 0.0.0.0 so the Netbird interface can reach it.
|
|
API_SERVER_ENABLED = "true";
|
|
API_SERVER_HOST = "0.0.0.0";
|
|
API_SERVER_PORT = toString (config.m3ta.ports.get "hermes-api");
|
|
};
|
|
|
|
mcpServers.ai-memory = {
|
|
command = aiMemory;
|
|
args = ["mcp-bridge" "--no-session-id" "--server-url" "${aiMemoryUrl}/mcp" "--data-dir" aiMemoryDataDir];
|
|
};
|
|
|
|
# ── Container mode (podman) ──────────────────────────────────────────
|
|
container = {
|
|
enable = false;
|
|
backend = "podman";
|
|
extraVolumes = ["/home/m3tam3re/p:/projects:rw"];
|
|
extraOptions = [];
|
|
};
|
|
|
|
settings = {
|
|
# ── Model ──────────────────────────────────────────────────────────
|
|
model = {
|
|
default = "glm-5.3";
|
|
provider = "zai";
|
|
};
|
|
|
|
fallback_providers = [
|
|
{
|
|
provider = "openai-codex";
|
|
model = "gpt-5.5";
|
|
}
|
|
{
|
|
provider = "minimax";
|
|
model = "MiniMax-M3";
|
|
}
|
|
];
|
|
|
|
credential_pool_strategies = {
|
|
zai = "fill_first";
|
|
};
|
|
|
|
toolsets = ["all"];
|
|
|
|
# ── Agent ──────────────────────────────────────────────────────────
|
|
agent = {
|
|
max_turns = 90;
|
|
gateway_timeout = 1800;
|
|
tool_use_enforcement = "auto";
|
|
reasoning_effort = "high";
|
|
};
|
|
|
|
# ── Skills ─────────────────────────────────────────────────────────
|
|
|
|
skills = {
|
|
external_dirs = [
|
|
"~/.agents/skills"
|
|
];
|
|
};
|
|
|
|
# ── Plugins ────────────────────────────────────────────────────────
|
|
# Declared after the 2026-10-04 corruption incident: the runtime had
|
|
# enabled these plugins in config.yaml (via plugin-install), and a
|
|
# runtime bug appended the second entry at mapping-level indent,
|
|
# breaking the whole file. Declaring them here keeps them active even
|
|
# if a corrupt runtime config ever has to be quarantined and
|
|
# regenerated (see hermes-config-quarantine activation snippet below).
|
|
plugins = {
|
|
enabled = [
|
|
"herdr-agent-state"
|
|
"moshi-hooks"
|
|
];
|
|
};
|
|
|
|
# ── Terminal ───────────────────────────────────────────────────────
|
|
terminal = {
|
|
backend = "local";
|
|
modal_mode = "auto";
|
|
cwd = ".";
|
|
timeout = 180;
|
|
persistent_shell = true;
|
|
};
|
|
|
|
# ── Browser ────────────────────────────────────────────────────────
|
|
browser = {
|
|
inactivity_timeout = 120;
|
|
command_timeout = 30;
|
|
cloud_provider = "local";
|
|
};
|
|
|
|
# ── Checkpoints v2 ─────────────────────────────────────────────────
|
|
# v0.13.0: Single-store rewrite with real pruning + disk guardrails.
|
|
checkpoints = {
|
|
enabled = true;
|
|
max_snapshots = 50;
|
|
};
|
|
|
|
file_read_max_chars = 100000;
|
|
|
|
compression = {
|
|
enabled = true;
|
|
threshold = 0.5;
|
|
target_ratio = 0.2;
|
|
protect_last_n = 20;
|
|
};
|
|
|
|
# ── Display ────────────────────────────────────────────────────────
|
|
display = {
|
|
compact = false;
|
|
personality = "kawaii";
|
|
resume_display = "full";
|
|
busy_input_mode = "interrupt";
|
|
inline_diffs = true;
|
|
skin = "default";
|
|
tool_progress = "all";
|
|
};
|
|
|
|
# ── TTS / STT / Voice ──────────────────────────────────────────────
|
|
tts = {
|
|
provider = "edge";
|
|
edge = {
|
|
voice = edgeVoice;
|
|
};
|
|
};
|
|
|
|
stt = {
|
|
enabled = true;
|
|
provider = "local";
|
|
local = {model = "base";};
|
|
};
|
|
|
|
voice = {
|
|
record_key = "ctrl+b";
|
|
max_recording_seconds = 120;
|
|
silence_threshold = 200;
|
|
silence_duration = 3.0;
|
|
};
|
|
|
|
# ── ai-memory hooks ────────────────────────────────────────────────
|
|
# From `ai-memory install-hooks --agent hermes` (3.2.2). ai-memory is
|
|
# the one shared memory for every agent; Honcho was dropped in favour
|
|
# of it (2026-10-25), only Hermes' small built-in notes remain.
|
|
hooks_auto_accept = true;
|
|
hooks = {
|
|
pre_tool_call = aiMemoryHook "pre-tool-use";
|
|
post_tool_call = aiMemoryHook "post-tool-use";
|
|
on_session_start = aiMemoryHook "session-start";
|
|
pre_llm_call = aiMemoryHook "user-prompt-submit";
|
|
on_session_end = aiMemoryHook "stop";
|
|
on_session_finalize = aiMemoryHook "session-end";
|
|
};
|
|
|
|
# ── Memory ─────────────────────────────────────────────────────────
|
|
memory = {
|
|
provider = "builtin";
|
|
memory_enabled = true;
|
|
user_profile_enabled = true;
|
|
memory_char_limit = 2200;
|
|
user_char_limit = 1375;
|
|
};
|
|
|
|
# ── Delegation / Orchestrator ────────────────────────────────────────
|
|
delegation = {
|
|
max_iterations = 50;
|
|
orchestrator_enabled = true;
|
|
max_spawn_depth = 2;
|
|
};
|
|
|
|
# ── Kanban (v0.13.0 — Multi-Agent Board) ──────────────────────────
|
|
# Durable task board with embedded dispatcher in gateway process.
|
|
# Workers are full OS processes with identity, heartbeat, reclaim,
|
|
# zombie detection, and hallucination gate.
|
|
kanban = {
|
|
dispatch_in_gateway = true;
|
|
dispatch_interval_seconds = 60;
|
|
};
|
|
|
|
# ── Matrix ────────────────────────────────────────────────────────
|
|
matrix = {
|
|
homeserver = "https://matrix.m3ta.dev";
|
|
user_id = "@chiron:m3ta.dev";
|
|
allowed_users = ["@m3tam3re:m3ta.dev"];
|
|
encryption = true;
|
|
group_sessions_per_user = true;
|
|
auto_thread = true;
|
|
dm_mention_threads = true;
|
|
};
|
|
|
|
# ── Approvals / Security ───────────────────────────────────────────
|
|
approvals = {
|
|
mode = "manual";
|
|
timeout = 60;
|
|
};
|
|
|
|
security = {
|
|
redact_secrets = true;
|
|
tirith_enabled = true;
|
|
tirith_fail_open = true;
|
|
};
|
|
|
|
# ── Cron / Session ─────────────────────────────────────────────────
|
|
cron = {wrap_response = true;};
|
|
|
|
session_reset = {
|
|
mode = "both";
|
|
idle_minutes = 1440;
|
|
at_hour = 4;
|
|
};
|
|
|
|
# ── Web ────────────────────────────────────────────────────────────
|
|
web = {backend = "exa";};
|
|
};
|
|
};
|
|
|
|
users.users.hermes = {
|
|
isNormalUser = false;
|
|
openssh.authorizedKeys.keys = [
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICAVF7jGP1S6vc5CxeBFD/UxiImHOgbPlKg8WYyNtOA3"
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBZcjCKl0DRuOUOMXbM0GKY5JjvmyFpVZ/tRlTKWu/zp"
|
|
];
|
|
};
|
|
|
|
# ── ai-memory skills ──────────────────────────────────────────────────
|
|
# Hermes ignores MCP server instructions; the routing rules reach the
|
|
# model through these skills in ~/.hermes/skills, refreshed on each boot
|
|
# so they track the installed ai-memory version.
|
|
systemd.services.hermes-ai-memory-skills = {
|
|
description = "Install ai-memory skills for Hermes";
|
|
before = ["hermes-agent.service"];
|
|
wantedBy = ["hermes-agent.service"];
|
|
environment = {
|
|
HOME = "/var/lib/hermes";
|
|
HERMES_HOME = hermesHome;
|
|
};
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
User = "hermes";
|
|
Group = "hermes";
|
|
ExecStart = "${aiMemory} --data-dir ${aiMemoryDataDir} install-skills --scope global --agent hermes";
|
|
};
|
|
};
|
|
|
|
# ── Activation hardening ─────────────────────────────────────────────
|
|
# Upstream (hermes-agent v2026.9.24) deep-merges the Nix settings into
|
|
# the runtime-writable config.yaml via a bare `yaml.safe_load()` with no
|
|
# error handling. The hermes runtime corrupts that file occasionally
|
|
# (2026-10-04: enabling a plugin appended "- moshi-hooks" at
|
|
# mapping-level indent → yaml.parser.ParserError), which made every
|
|
# `nixos-rebuild switch` fail inside the 'hermes-agent-setup' snippet.
|
|
# Quarantine unparsable YAML before the upstream snippet runs so
|
|
# activation regenerates a clean file from Nix settings instead of
|
|
# blocking system updates. The corrupt file is kept next to it for
|
|
# manual recovery of any runtime-added keys.
|
|
system.activationScripts = {
|
|
hermes-config-quarantine = lib.stringAfter ["users"] ''
|
|
if [ -f ${hermesHome}/config.yaml ] && ! ${yamlPython}/bin/python3 -c 'import sys, yaml; yaml.safe_load(open(sys.argv[1]))' ${hermesHome}/config.yaml 2>/dev/null; then
|
|
_quarantined="${hermesHome}/config.yaml.corrupt-$(date +%Y%m%d-%H%M%S)"
|
|
mv ${hermesHome}/config.yaml "$_quarantined"
|
|
chmod 0600 "$_quarantined"
|
|
echo "[hermes-config-quarantine] config.yaml was not valid YAML — moved to $_quarantined; a clean one is regenerated from Nix settings" >&2
|
|
fi
|
|
'';
|
|
|
|
# Order the quarantine before the upstream merge snippet (deps lists
|
|
# concatenate, so this adds to upstream's ["users", "setupSecrets"]).
|
|
hermes-agent-setup.deps = ["hermes-config-quarantine"];
|
|
};
|
|
}
|