Files
hermes-guest/nix/vfkit-vm.nix
T
dckc 3f9ba54477 feat: Endo-compatible host, downloads folder, Nix tools PATH
- the fake host serves a subset of @endo/agent-mcp-stdio's catalog,
  with its names, schemas and answers; evaluate takes only
  E(name).method(arg, ...), and __getMethodNames__
- demo.py --host endo: a real Endo daemon (endo-but-for-bots, llm),
  its guest served by the package's broker
- a downloads folder: the host writes, Hermes reads at ~/Downloads;
  BindReadOnlyPaths on Linux, a virtiofs share on macOS
- .#demo-tools: Hermes and the checks get their whole PATH from the store
- each run saves its MCP messages and a transcript
- the guide: tools as system calls, names as file descriptors;
  no Linux networking, but WebApps
- grants match a named URL before "download"

Generated-by: Claude Opus 5.5
2026-11-29 23:15:06 -06:00

127 lines
3.7 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. The downloads folder is hostDir/Downloads,
# shared into the VM by virtiofs.
{
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, the two Unix sockets vfkit connects to, and the guest's downloads folder, Downloads.";
};
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";
}
# the downloads folder, which the host writes; the unit binds it
# read-only into Hermes's home
{
tag = "downloads";
source = "${vm.hostDir}/Downloads";
mountPoint = cfg.downloadsDir;
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";
};
}