Files
hermes-guest/nix/llm-proxy.nix
T
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

71 lines
2.0 KiB
Nix

# The inference proxy, socket-activated: one service instance per
# connection on `socket`, holding the API key as a systemd credential.
# Used on a Linux host, and (with launchd in place of systemd) on macOS.
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.hermes-llm-proxy;
proxy = pkgs.writers.writePython3 "llm-proxy" { flakeIgnore = [ "E501" ]; } (
builtins.readFile ../llm-proxy.py
);
in
{
options.services.hermes-llm-proxy = {
enable = lib.mkEnableOption "the inference proxy for a confined Hermes";
socket = lib.mkOption {
type = lib.types.str;
description = "Where to listen.";
};
socketUser = lib.mkOption {
type = lib.types.str;
description = "The one user who may connect.";
};
upstream = lib.mkOption {
type = lib.types.str;
example = "https://openrouter.ai/api/v1";
description = "The OpenAI-compatible base URL to forward to.";
};
keyFile = lib.mkOption {
type = lib.types.str;
description = "The API key, as a runtime path (not a nix path, which would copy it to the store).";
};
};
config = lib.mkIf cfg.enable {
systemd.sockets.hermes-llm = {
wantedBy = [ "sockets.target" ];
listenStreams = [ cfg.socket ];
socketConfig = {
Accept = true;
SocketUser = cfg.socketUser;
SocketMode = "0600";
};
};
systemd.services."hermes-llm@" = {
description = "Hermes inference proxy, one connection";
serviceConfig = {
ExecStart = "${proxy} ${lib.escapeShellArg cfg.upstream} %d/llm-key";
StandardInput = "socket";
StandardOutput = "journal";
LoadCredential = [ "llm-key:${cfg.keyFile}" ];
DynamicUser = true;
ProtectSystem = "strict";
ProtectHome = true;
PrivateTmp = true;
PrivateDevices = true;
NoNewPrivileges = true;
CapabilityBoundingSet = "";
RestrictAddressFamilies = [
"AF_UNIX"
"AF_INET"
"AF_INET6"
];
};
};
};
}