Files
dckc e38d681a9e feat: Hermes confined to act only as an Endo guest
A NixOS module (nix/hermes-guest.nix) layers confinement on upstream's
services.hermes-agent: no network (PrivateNetwork), an empty /run with
two Unix sockets bound back in, and no user manager. Hermes reaches the
world through host.sock, the guest's Endo methods (listMessages,
request, lookup, reply, ...) as MCP, and llm.sock, an inference proxy
that holds the API key.

The same unit runs on a Linux host (nix/linux-host.nix) and in a vfkit
microVM on macOS (nix/vfkit-vm.nix), where systemd relays the two
sockets over vsock to launchd on the host (nix/darwin-host.nix).

test/demo.py runs unmodified Hermes against a fake host and a scripted
model, and checks what the host received.

Generated-by: Claude Opus 5.5
2026-11-29 16:34:39 -06:00

142 lines
4.7 KiB
Nix

# Hermes, confined to act only as one Endo guest (of toybox, or of an Endo daemon).
#
# This module is what ports: the same unit runs on a Linux host and inside
# the macOS VM (./vfkit-vm.nix). It reaches the world through exactly two
# Unix sockets, and whatever imports it decides what serves them:
#
# hostSocket the guest's methods (listMessages, request, resolve,
# lookup, ...) as an MCP server, bound to one guest agent
# llmSocket model inference, through a proxy that holds the API key
#
# The service has no network of its own (PrivateNetwork), and sees no
# other Unix sockets on the machine.
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.hermes-guest;
hermes = config.services.hermes-agent;
socketDir = "/run/hermes-guest";
in
{
options.services.hermes-guest = {
enable = lib.mkEnableOption "Hermes as a confined Endo guest";
hostSocket = lib.mkOption {
type = lib.types.str;
default = "${socketDir}/host.sock";
description = "The Unix socket where the guest's MCP methods are served.";
};
llmSocket = lib.mkOption {
type = lib.types.str;
default = "${socketDir}/llm.sock";
description = "The Unix socket of the inference proxy, an OpenAI-compatible endpoint.";
};
llmPort = lib.mkOption {
type = lib.types.port;
default = 8080;
description = "The loopback port, inside Hermes's own network namespace, that forwards to llmSocket.";
};
model = lib.mkOption {
type = lib.types.str;
description = "The model name, as the proxy's upstream knows it.";
};
};
config = lib.mkIf cfg.enable {
services.hermes-agent = {
enable = true;
addToSystemPackages = false;
settings = {
model = {
provider = "custom";
default = cfg.model;
base_url = "http://127.0.0.1:${toString cfg.llmPort}/v1";
# the proxy adds the real key; Hermes never holds it
api_key = "held-by-proxy";
};
terminal.backend = "local";
# the guest's methods are its whole world: offer them to the model
# directly, not behind tool_search/tool_call
tools.tool_search.enabled = "off";
};
mcpServers.host = {
command = "${pkgs.socat}/bin/socat";
args = [
"STDIO"
"UNIX-CONNECT:${cfg.hostSocket}"
];
};
};
# Upstream lingers the hermes uid so cron jobs can `systemd-run --user`.
# A user manager starts units outside this sandbox, so: no linger, and
# no /run/user (below). Cron jobs then fail closed.
users.users.${hermes.user}.linger = lib.mkForce false;
systemd.services.hermes-agent = {
after = [ "hermes-llm-bridge.service" ];
requires = [ "hermes-llm-bridge.service" ];
serviceConfig = {
PrivateNetwork = true;
IPAddressDeny = "any";
IPAddressAllow = "localhost";
RestrictAddressFamilies = [
"AF_UNIX"
"AF_INET"
"AF_INET6"
];
# Path-named Unix sockets ignore network namespaces: hide them all,
# then put back the two this service may use. (/var/run is a
# symlink to /run, so it's covered too.)
TemporaryFileSystem = [ "/run" ];
BindReadOnlyPaths = [
cfg.hostSocket
cfg.llmSocket
];
ProtectHome = lib.mkForce true;
PrivateDevices = true;
PrivateIPC = true;
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
ProtectClock = true;
ProtectHostname = true;
RestrictNamespaces = true;
RestrictSUIDSGID = true;
LockPersonality = true;
CapabilityBoundingSet = "";
SystemCallArchitectures = "native";
};
};
# Hermes's client wants a TCP base_url. This joins Hermes's network
# namespace and forwards its loopback port to llmSocket.
systemd.services.hermes-llm-bridge = {
description = "Hermes's loopback port to the inference proxy";
unitConfig.JoinsNamespaceOf = "hermes-agent.service";
partOf = [ "hermes-agent.service" ];
serviceConfig = {
User = hermes.user;
Group = hermes.group;
PrivateNetwork = true;
ExecStart = lib.escapeShellArgs [
"${pkgs.socat}/bin/socat"
"TCP-LISTEN:${toString cfg.llmPort},bind=127.0.0.1,fork,reuseaddr"
"UNIX-CONNECT:${cfg.llmSocket}"
];
ProtectSystem = "strict";
ProtectHome = true;
PrivateTmp = true;
NoNewPrivileges = true;
CapabilityBoundingSet = "";
};
};
systemd.tmpfiles.rules = [ "d ${socketDir} 0755 root root -" ];
};
}