authoravatarclover caruso<git@paperclover.net>2026-11-23 19:50:11-08:00
committeravatarclover caruso<git@paperclover.net>2026-11-30 03:08:43-08:00
logaef167536486f4539104b503ed9986cd979a3ebc
tree98b9708a24fffeb385e1c694b1cea9e182e2d4fc
parent549c61ff5443c3f252970d4dfe51658649f13491
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

ext-rachel: Windows 11 guest with the 3090 passed through, reachable over SSH

Local AI is off while the GPU belongs to the guest. The guest gets 10 vCPUs on an exclusive cpuset partition carved from knife-linux and 40 GiB of pinned memory; the ZFS ARC floor and knife-linux's memory limit shrink to make room. Port 22 as rachel relays into the guest through a host account with a ForceCommand, key-only and without forwarding. Assisted-by: claude-opus-5.5

7 files changed, 214 insertions(+), 9 deletions(-)

config/ext-rachel.json created+20
......@@ -0,0 +1,20 @@
1{
2 "dataset": "work/ext-rachel",
3 "root": "/srv/ext-rachel",
4 "bridge": "virbr-ext",
5 "mac": "52:54:00:e7:00:02",
6 "gatewayAddress": "10.101.0.1",
7 "guestAddress": "10.101.0.2",
8 "sshPort": 2223,
9 "cpus": "3-7,19-23",
10 "gpu": [
11 "10de:2204",
12 "10de:1aef"
13 ],
14 "authorizedKeys": [
15 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBFQ8bkawCPFLOdVbUs/tf19bFflcal4Ss3BwjGa6mun",
16 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJVKqjtc1WZyfyQZIZzbNvZ7L2yEYh6rn7k7uGpiuNwP",
17 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOihVPOrOuT79omYc+AJYkmZceaAphi+7vOnhaYi87Hx",
18 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMpxNpkRLTUijhd3HSaOvKYn2MWXEY+YEFdsPNZhBROn"
19 ]
20}
nixos/ext-rachel.nix created+150
......@@ -0,0 +1,150 @@
1{ lib, pkgs, ... }:
2let
3 box = builtins.fromJSON (builtins.readFile ../config/ext-rachel.json);
4 privateRanges = [ "10.0.0.0/8" "172.16.0.0/12" "192.168.0.0/16" "100.64.0.0/10" "169.254.0.0/16" ];
5 # Open forwarding: libvirt adds no firewall rules, so the rules below are the whole policy.
6 network = pkgs.writeText "ext-rachel-network.xml" ''
7 <network>
8 <name>ext-rachel</name>
9 <forward mode='open'/>
10 <bridge name='${box.bridge}' stp='on' delay='0'/>
11 <dns><forwarder addr='1.1.1.1'/></dns>
12 <ip address='${box.gatewayAddress}' netmask='255.255.255.0'>
13 <dhcp><host mac='${box.mac}' ip='${box.guestAddress}'/><range start='10.101.0.100' end='10.101.0.120'/></dhcp>
14 </ip>
15 </network>
16 '';
17in
18{
19 # The 3090 belongs to the guest; vfio-pci claims it before nvidia can.
20 boot.initrd.kernelModules = [ "vfio_pci" "vfio" "vfio_iommu_type1" ];
21 boot.kernelParams = [ "vfio-pci.ids=${lib.concatStringsSep "," box.gpu}" ];
22 hardware.nvidia.nvidiaPersistenced = lib.mkForce false;
23
24 systemd.services.ext-rachel-storage = {
25 wantedBy = [ "multi-user.target" ];
26 before = [ "libvirtd.service" ];
27 requires = [ "zfs-import-work.service" ];
28 after = [ "zfs-import-work.service" "zfs-mount.service" ];
29 serviceConfig = { Type = "oneshot"; RemainAfterExit = true; };
30 script = ''
31 if ! ${pkgs.zfs}/bin/zfs list -H -o name ${box.dataset} >/dev/null 2>&1; then
32 ${pkgs.zfs}/bin/zfs create -o mountpoint=${box.root} -o compression=lz4 -o atime=off -o recordsize=64K ${box.dataset}
33 fi
34 ${pkgs.zfs}/bin/zfs set quota=560G ${box.dataset}
35 test "$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE --mountpoint ${box.root})" = ${box.dataset}
36 chmod 0700 ${box.root}
37 '';
38 };
39
40 systemd.services.ext-rachel-network = {
41 wantedBy = [ "multi-user.target" ];
42 requires = [ "libvirtd.service" ];
43 after = [ "libvirtd.service" ];
44 before = [ "libvirt-guests.service" ];
45 serviceConfig = { Type = "oneshot"; RemainAfterExit = true; };
46 path = [ pkgs.libvirt ];
47 script = ''
48 virsh net-define ${network}
49 virsh net-autostart ext-rachel
50 virsh net-info ext-rachel | grep -q '^Active:.*yes' || virsh net-start ext-rachel
51 '';
52 };
53
54 # Pinned vCPUs alone would still share those cores with host processes.
55 virtualisation.libvirtd.hooks.qemu.ext-rachel-cpus = pkgs.writeShellScript "ext-rachel-cpus" ''
56 test "$1" = ext-rachel -a "$2" = started || exit 0
57 # The guest may start before knife-linux reserves its own CPUs here.
58 reserved=$(cat /sys/fs/cgroup/machine.slice/cpuset.cpus.exclusive)
59 echo "''${reserved:+$reserved,}${box.cpus}" > /sys/fs/cgroup/machine.slice/cpuset.cpus.exclusive
60 for scope in /sys/fs/cgroup/machine.slice/machine-qemu*ext\\x2drachel.scope; do
61 echo ${box.cpus} > $scope/cpuset.cpus.exclusive
62 echo ${box.cpus} > $scope/cpuset.cpus
63 echo root > $scope/cpuset.cpus.partition
64 done
65 '';
66
67 # libvirt-guests suspends guests at host shutdown, which fails with a passed-through GPU.
68 systemd.services.ext-rachel-shutdown = {
69 wantedBy = [ "multi-user.target" ];
70 after = [ "libvirt-guests.service" ];
71 # Stopping this unit shuts the guest down; a changed unit must not do that on switch.
72 restartIfChanged = false;
73 serviceConfig = { Type = "oneshot"; RemainAfterExit = true; TimeoutStopSec = 300; };
74 path = [ pkgs.libvirt ];
75 script = "true";
76 preStop = ''
77 virsh shutdown ext-rachel 2>/dev/null || exit 0
78 for _ in $(seq 1 120); do
79 virsh domstate ext-rachel | grep -q 'shut off' && exit 0
80 sleep 2
81 done
82 '';
83 };
84
85 # Port 22 is the host's sshd, so the host account `rachel` only relays into the guest with its own key.
86 users.users.rachel = {
87 isSystemUser = true;
88 group = "rachel";
89 home = "/var/lib/ext-rachel-relay";
90 createHome = true;
91 shell = pkgs.bash;
92 openssh.authorizedKeys.keys = box.authorizedKeys;
93 };
94 users.groups.rachel = { };
95 systemd.services.ext-rachel-relay-key = {
96 wantedBy = [ "multi-user.target" ];
97 serviceConfig = { Type = "oneshot"; RemainAfterExit = true; User = "rachel"; };
98 script = ''
99 test -f ~/id_ed25519 || ${pkgs.openssh}/bin/ssh-keygen -q -t ed25519 -N "" -C ext-rachel-relay -f ~/id_ed25519
100 '';
101 };
102 services.openssh.extraConfig = let
103 relay = pkgs.writeShellScript "ext-rachel-relay" ''
104 ssh() { exec ${pkgs.openssh}/bin/ssh -F /dev/null -e none -o BatchMode=yes -i ~/id_ed25519 \
105 -o UserKnownHostsFile=~/known_hosts -o StrictHostKeyChecking=accept-new "$@" rachel@${box.guestAddress} "''${cmd[@]}"; }
106 case "$SSH_ORIGINAL_COMMAND" in
107 "") cmd=(); [ -t 0 ] && ssh -t || ssh ;;
108 *sftp-server) cmd=(sftp); ssh -s ;;
109 *) cmd=("$SSH_ORIGINAL_COMMAND"); [ -t 0 ] && ssh -t || ssh ;;
110 esac
111 '';
112 in ''
113 Match User rachel
114 ForceCommand ${relay}
115 PasswordAuthentication no
116 KbdInteractiveAuthentication no
117 AllowTcpForwarding no
118 AllowAgentForwarding no
119 AllowStreamLocalForwarding no
120 PermitTunnel no
121 X11Forwarding no
122 '';
123
124 networking.nat = {
125 enable = true;
126 externalInterface = "enp4s0";
127 internalInterfaces = [ box.bridge ];
128 forwardPorts = [
129 { sourcePort = box.sshPort; destination = "${box.guestAddress}:22"; proto = "tcp"; }
130 ];
131 };
132
133 networking.firewall.extraCommands = ''
134 iptables -N ext-rachel 2>/dev/null || iptables -F ext-rachel
135 iptables -A ext-rachel -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
136 ${lib.concatMapStringsSep "\n" (range: "iptables -A ext-rachel -d ${range} -j DROP") privateRanges}
137 iptables -A ext-rachel -p tcp --dport 25 -j DROP
138 iptables -A ext-rachel -j ACCEPT
139 iptables -I FORWARD -i ${box.bridge} -j ext-rachel
140 iptables -I nixos-fw 1 -i ${box.bridge} -j DROP
141 iptables -I nixos-fw 1 -i ${box.bridge} -p udp -m multiport --dports 53,67 -j ACCEPT
142 iptables -I nixos-fw 1 -i ${box.bridge} -p tcp --dport 53 -j ACCEPT
143 iptables -I nixos-fw 1 -i ${box.bridge} -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
144 '';
145 networking.firewall.extraStopCommands = ''
146 iptables -D FORWARD -i ${box.bridge} -j ext-rachel 2>/dev/null || true
147 iptables -F ext-rachel 2>/dev/null || true
148 iptables -X ext-rachel 2>/dev/null || true
149 '';
150}
nixos/knife-linux.nix+5-4
......@@ -14,7 +14,8 @@ let
1414 exec ${pkgs.podman}/bin/podman --root=${root}/containers/storage --runroot=/run/knife-linux/containers "$@"
1515 '';
1616 run = "${podman}/bin/knife-linux-podman";
17 cpus = "3-15,19-31";
17 cpus = "8-15,24-31";
18 extRachel = builtins.fromJSON (builtins.readFile ../config/ext-rachel.json);
1819 checkWork = pkgs.writeShellScript "check-knife-work" ''
1920 test "$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE --mountpoint /srv/work)" = work
2021 '';
......@@ -66,19 +67,19 @@ in
6667 run "run --rm --replace --name=knife-linux --pull=never"
6768 "--sdnotify=conmon --cgroups=no-conmon --log-driver=journald --init --hostname=knife-linux"
6869 "--user=${uid}:${gid} --umask=0077 --cap-drop=ALL --security-opt=no-new-privileges"
69 "--memory=96g --pids-limit=32768 --shm-size=2g --network=podman"
70 "--memory=72g --pids-limit=32768 --shm-size=2g --network=podman"
7071 "--volume=${root}/home:/home/clo"
7172 "--volume=/srv/work:/work"
7273 "--volume=/opt/studio-project-store/current/bin/jj-real:/usr/local/bin/jj:ro"
7374 "--device=/dev/kvm"
7475 "localhost/knife-linux"
7576 ];
76 # Agents get 13 cores to themselves and the host keeps three. A partition
77 # Agents get 8 cores to themselves, ext-rachel 5 and the host keeps three. A partition
7778 # rather than a CPU quota: an exhausted quota freezes the Knife server with the builds.
7879 ExecStartPost = "-" + pkgs.writeShellScript "knife-linux-cpus" ''
7980 set -e
8081 scope=/sys/fs/cgroup$(${run} inspect --format '{{.State.CgroupPath}}' knife-linux)
81 echo ${cpus} > /sys/fs/cgroup/machine.slice/cpuset.cpus.exclusive
82 echo ${cpus},${extRachel.cpus} > /sys/fs/cgroup/machine.slice/cpuset.cpus.exclusive
8283 echo ${cpus} > $scope/cpuset.cpus.exclusive
8384 echo ${cpus} > $scope/cpuset.cpus
8485 echo root > $scope/cpuset.cpus.partition
nixos/snowglobe.nix+4-3
......@@ -8,6 +8,7 @@ let
88 irohNetwork = builtins.fromJSON (builtins.readFile ../service/iroh-relay/network.json);
99 spacebarVoice = builtins.fromJSON (builtins.readFile ../service/spacebar/voice-network.json);
1010 extMantikafasi = builtins.fromJSON (builtins.readFile ../config/ext-mantikafasi.json);
11 extRachel = builtins.fromJSON (builtins.readFile ../config/ext-rachel.json);
1112 udpPorts = xmppUDPPorts ++ [ irohNetwork.quic spacebarVoice.media spacebarVoice.nativeMedia ];
1213 encryptionRoots = {
1314 clover = "clover";
......@@ -18,7 +19,7 @@ let
1819 };
1920in
2021{
21 imports = [ ./snowglobe-network.nix ./mac-studio-sandbox.nix ./knife-linux.nix ./mac-vm.nix ./ext-mantikafasi.nix ./vm-disks.nix ./zfs-read-cache.nix ./gpu-unlock.nix ];
22 imports = [ ./snowglobe-network.nix ./mac-studio-sandbox.nix ./knife-linux.nix ./mac-vm.nix ./ext-mantikafasi.nix ./ext-rachel.nix ./vm-disks.nix ./zfs-read-cache.nix ./gpu-unlock.nix ];
2223
2324 networking.hostName = "snowglobe";
2425 environment.etc."machine-info".text = ''
......@@ -87,7 +88,7 @@ in
8788 script = ''
8889 description="$(${pkgs.python3}/bin/python3 ${./upnp-discover.py} ${lib.escapeShellArg config.networking.defaultGateway.address})"
8990 exec ${pkgs.miniupnpc}/bin/upnpc -u "$description" -e "Snow Globe services" -r \
90 ${lib.concatMapStringsSep " " (port: "${toString port} TCP") (xmppTCPPorts ++ [ extMantikafasi.sshPort extMantikafasi.vncPort ])} \
91 ${lib.concatMapStringsSep " " (port: "${toString port} TCP") (xmppTCPPorts ++ [ extMantikafasi.sshPort extMantikafasi.vncPort extRachel.sshPort ])} \
9192 ${lib.concatMapStringsSep " " (port: "${toString port} UDP") (udpPorts ++ lib.range xmppNetwork.relay_first xmppNetwork.relay_last)}
9293 '';
9394 };
......@@ -148,7 +149,7 @@ in
148149 };
149150 environment.variables.SNOWGLOBE_POOL = pool;
150151 environment.variables.SNOWGLOBE_DOMAIN = "paperclover.net";
151 environment.variables.SNOWGLOBE_LOCAL_AI = "true";
152 environment.variables.SNOWGLOBE_LOCAL_AI = "false";
152153
153154 system.stateVersion = "26.05";
154155}
nixos/zfs-read-cache.nix+1-1
......@@ -7,7 +7,7 @@ let
77in
88{
99 # Reclaim pressure otherwise shrinks the ARC to a few GiB with most memory free.
10 boot.kernelParams = [ "zfs.zfs_arc_min=${toString (32 * 1024 * 1024 * 1024)}" ];
10 boot.kernelParams = [ "zfs.zfs_arc_min=${toString (16 * 1024 * 1024 * 1024)}" ];
1111
1212 systemd.services.snowglobe-zfs-read-cache = {
1313 wantedBy = [ "multi-user.target" ];
tools/ext-rachel.md created+33
......@@ -0,0 +1,33 @@
1# ext-rachel
2
3`ext-rachel` is a Windows 11 Pro libvirt guest (`windows-11-pro-v2` preset, 10 vCPU, 40 GiB) owned by the
4dashboard user `rachel`, with the RTX 3090 passed through. Its 500 GB disk is a standalone qcow2 on the `work`
5NVMe pool (`work/ext-rachel` at `/srv/ext-rachel`); the creation artifacts, seed and `access.json` stay in
6`/srv/vm/ext-rachel`. `config/ext-rachel.json` and `nixos/ext-rachel.nix` own the host side.
7
8```
9internet ──UPnP──> Snow Globe :2223 ─DNAT─> 10.101.0.2:22 (Windows OpenSSH, PowerShell)
10internet ──> Snow Globe :22 as rachel ─ForceCommand ssh─> 10.101.0.2:22
11dashboard console / Computer MCP ─── libvirt VNC + guest agent (owner rachel)
12guest ── virbr-ext (forward mode='open') ── MASQUERADE ── internet only
13```
14
15- **GPU:** `vfio-pci.ids` claims both 3090 functions at boot, so local AI is off (`SNOWGLOBE_LOCAL_AI=false`)
16 and `nvidia-persistenced` is disabled. The guest uses the GeForce driver; the emulated VGA stays the primary
17 display so the dashboard console and Computer MCP keep working. Games pick the 3090 in Windows' Graphics
18 settings ("High performance"). Restoring local AI means removing the import, a reboot, and redeploying.
19- **Isolation:** libvirt adds no rules for an open network; `ext-rachel` drops new connections to private,
20 CGNAT and link-local ranges and port 25. From the guest, Snow Globe answers only DHCP and DNS.
21 Snow Globe itself can still connect into the guest.
22- **CPUs and memory:** vCPUs are pinned 1:1 to cores 3-7 and their siblings 19-23, which a libvirt hook makes an
23 exclusive cpuset partition beside `knife-linux` (8 cores); the host keeps 0-2 and 16-18. VFIO pins all 40 GiB, so
24 the ZFS ARC floor is 16 GiB and `knife-linux` is capped at 72 GiB to leave headroom.
25- **OpenSSH:** the guest runs the Win32-OpenSSH MSI. The Windows `OpenSSH.Server` capability was removed because its
26 servicing deleted the MSI's `sshd` service; `msiexec /fa <product code>` restores it.
27- **Shutdown:** `ext-rachel-shutdown` shuts the guest down before `libvirt-guests`, whose managed save cannot
28 capture a VFIO device.
29- **Access:** account `rachel`, password in `/srv/vm/ext-rachel/access.json`.
30 `ssh rachel@snowglobe.paperclover.net` takes only the keys in `config/ext-rachel.json`; the host account
31 relays shells, commands and sftp/scp into the guest with `/var/lib/ext-rachel-relay/id_ed25519`, whose public
32 half must be in the guest's `administrators_authorized_keys`. Port 2223 also takes the password. MCP: `https://snowglobe.paperclover.net/mcp/computer`,
33 signed in as `rachel`; MCP grants only reach VMs the connection's own account owns.
tools/knife-linux.md+1-1
......@@ -4,7 +4,7 @@
44agents directly beside ZFS. [knife-linux.nix](../nixos/knife-linux.nix) builds it
55from [knife-linux.Containerfile](../nixos/knife-linux.Containerfile) on each start
66and runs it as the `knife-linux` system service: uid 3000 (`clo`), no
7capabilities, 13 cores (26 threads) to itself, a 96 GiB memory limit, `/dev/kvm`, and Podman's NAT network.
7capabilities, 8 cores (16 threads) to itself, a 72 GiB memory limit, `/dev/kvm`, and Podman's NAT network.
88Knife listens on container loopback port 3773; devices reach it through the mesh
99as `snowglobe` (device `4b85ee48…`). User namespaces work inside, but Podman's
1010seccomp filter blocks the `chroot` Chromium-based sandboxes need, so Chromium,