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
118 lines
3.3 KiB
Nix
118 lines
3.3 KiB
Nix
# On macOS: a NixOS microVM (vfkit) that runs the same confined unit.
|
|
# Inside the VM, systemd serves Hermes's two sockets too; each connection
|
|
# is relayed over vsock to the host (CID 2), where vfkit connects it to a
|
|
# Unix socket in hostDir. So the host's listeners on those two paths
|
|
# decide what Hermes can reach.
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.services.hermes-guest;
|
|
vm = cfg.vm;
|
|
|
|
# a socket unit at `path` in the VM, relaying each connection to vsock `port`
|
|
relay = name: path: port: {
|
|
sockets."hermes-${name}-relay" = {
|
|
wantedBy = [ "sockets.target" ];
|
|
listenStreams = [ path ];
|
|
socketConfig = {
|
|
Accept = true;
|
|
SocketUser = config.services.hermes-agent.user;
|
|
SocketMode = "0600";
|
|
};
|
|
};
|
|
services."hermes-${name}-relay@" = {
|
|
serviceConfig = {
|
|
ExecStart = "${pkgs.socat}/bin/socat STDIO VSOCK-CONNECT:2:${toString port}";
|
|
StandardInput = "socket";
|
|
StandardOutput = "socket";
|
|
DynamicUser = true;
|
|
RestrictAddressFamilies = [ "AF_VSOCK" ];
|
|
};
|
|
};
|
|
};
|
|
in
|
|
{
|
|
imports = [ ./hermes-guest.nix ];
|
|
|
|
options.services.hermes-guest.vm = {
|
|
hostDir = lib.mkOption {
|
|
type = lib.types.str;
|
|
example = "/Users/me/.local/state/hermes-guest";
|
|
description = "The host directory with the VM's state image, and the two Unix sockets vfkit connects to.";
|
|
};
|
|
hostPort = lib.mkOption {
|
|
type = lib.types.port;
|
|
default = 5000;
|
|
};
|
|
llmPort = lib.mkOption {
|
|
type = lib.types.port;
|
|
default = 5001;
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
system.stateVersion = "25.11";
|
|
networking.hostName = "hermes-guest";
|
|
|
|
microvm = {
|
|
hypervisor = "vfkit";
|
|
vcpu = 2;
|
|
mem = 4096;
|
|
# no network interface at all
|
|
interfaces = [ ];
|
|
# the host's /nix/store, read-only, as on a Linux host (where
|
|
# ProtectSystem=strict leaves the store readable): no store image to
|
|
# rebuild on each change. The store holds no secrets, as long as
|
|
# none is ever written as a nix path.
|
|
shares = [
|
|
{
|
|
tag = "ro-store";
|
|
source = "/nix/store";
|
|
mountPoint = "/nix/.ro-store";
|
|
proto = "virtiofs";
|
|
}
|
|
];
|
|
volumes = [
|
|
{
|
|
image = "${vm.hostDir}/hermes-state.img";
|
|
mountPoint = "/var/lib/hermes";
|
|
size = 8192;
|
|
}
|
|
];
|
|
# microvm.vsock.cid is not implemented for vfkit, so the devices go
|
|
# straight to vfkit: a guest connect to (2, port) makes vfkit connect
|
|
# to socketURL on the host.
|
|
vfkit.extraArgs = [
|
|
"--device"
|
|
"virtio-vsock,port=${toString vm.hostPort},socketURL=${vm.hostDir}/host.sock"
|
|
"--device"
|
|
"virtio-vsock,port=${toString vm.llmPort},socketURL=${vm.hostDir}/llm.sock"
|
|
];
|
|
};
|
|
|
|
systemd = lib.mkMerge [
|
|
(relay "host" cfg.hostSocket vm.hostPort)
|
|
(relay "llm" cfg.llmSocket vm.llmPort)
|
|
{
|
|
services.hermes-agent = {
|
|
after = [
|
|
"hermes-host-relay.socket"
|
|
"hermes-llm-relay.socket"
|
|
];
|
|
requires = [
|
|
"hermes-host-relay.socket"
|
|
"hermes-llm-relay.socket"
|
|
];
|
|
};
|
|
}
|
|
];
|
|
|
|
# the console is the operator's way in, for debugging
|
|
services.getty.autologinUser = "root";
|
|
};
|
|
}
|