| author | |
| committer | |
| log | b70609bde48d15ac1c36df711fdce8684046a60e |
| tree | 19f7272788fe384c6eebbbccb500b8fa0cadc02f |
| parent | 085ea170bbcce8135162d4871c2d078642e347cf |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
Rachel never used the guest, so it is wiped and reprovisioned for Clover:
account snow, owned by her dashboard account, reachable only with
config/admin.pub through Snow Globe. The host relay user, her keys and the
internet-facing port 2223 go away. Apollo streams to Moonlight on the LAN
through DNAT of its stream ports; the router forwards none of them.
The 3090 is no longer claimed by vfio-pci at boot: libvirt moves it to the
guest when it starts and back to nvidia when it stops, so local AI is
enabled again and shares the card with the guest.
Assisted-by: claude-opus-5.58 files changed, 161 insertions(+), 210 deletions(-)
config/ext-rachel.json deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 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 | } | ||
config/win11-gaming.json created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | { | ||
| 2 | "dataset": "work/win11-gaming", | ||
| 3 | "root": "/srv/win11-gaming", | ||
| 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 | "cpus": "3-7,19-23" | ||
| 9 | } | ||
nixos/ext-rachel.nix deleted-150| ... | @@ -1,150 +0,0 @@ | ||
| 1 | { lib, pkgs, ... }: | ||
| 2 | let | ||
| 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 | ''; | ||
| 17 | in | ||
| 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-info ext-rachel >/dev/null 2>&1 || 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+3-3| ... | @@ -15,7 +15,7 @@ let | ... | @@ -15,7 +15,7 @@ let |
| 15 | ''; | 15 | ''; |
| 16 | run = "${podman}/bin/knife-linux-podman"; | 16 | run = "${podman}/bin/knife-linux-podman"; |
| 17 | cpus = "8-15,24-31"; | 17 | cpus = "8-15,24-31"; |
| 18 | extRachel = builtins.fromJSON (builtins.readFile ../config/ext-rachel.json); | 18 | win11Gaming = builtins.fromJSON (builtins.readFile ../config/win11-gaming.json); |
| 19 | checkWork = pkgs.writeShellScript "check-knife-work" '' | 19 | checkWork = pkgs.writeShellScript "check-knife-work" '' |
| 20 | test "$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE --mountpoint /srv/work)" = work | 20 | test "$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE --mountpoint /srv/work)" = work |
| 21 | ''; | 21 | ''; |
| ... | @@ -74,12 +74,12 @@ in | ... | @@ -74,12 +74,12 @@ in |
| 74 | "--device=/dev/kvm" | 74 | "--device=/dev/kvm" |
| 75 | "localhost/knife-linux" | 75 | "localhost/knife-linux" |
| 76 | ]; | 76 | ]; |
| 77 | # Agents get 8 cores to themselves, ext-rachel 5 and the host keeps three. A partition | 77 | # Agents get 8 cores to themselves, win11-gaming 5 and the host keeps three. A partition |
| 78 | # rather than a CPU quota: an exhausted quota freezes the Knife server with the builds. | 78 | # rather than a CPU quota: an exhausted quota freezes the Knife server with the builds. |
| 79 | ExecStartPost = "-" + pkgs.writeShellScript "knife-linux-cpus" '' | 79 | ExecStartPost = "-" + pkgs.writeShellScript "knife-linux-cpus" '' |
| 80 | set -e | 80 | set -e |
| 81 | scope=/sys/fs/cgroup$(${run} inspect --format '{{.State.CgroupPath}}' knife-linux) | 81 | scope=/sys/fs/cgroup$(${run} inspect --format '{{.State.CgroupPath}}' knife-linux) |
| 82 | echo ${cpus},${extRachel.cpus} > /sys/fs/cgroup/machine.slice/cpuset.cpus.exclusive | 82 | echo ${cpus},${win11Gaming.cpus} > /sys/fs/cgroup/machine.slice/cpuset.cpus.exclusive |
| 83 | echo ${cpus} > $scope/cpuset.cpus.exclusive | 83 | echo ${cpus} > $scope/cpuset.cpus.exclusive |
| 84 | echo ${cpus} > $scope/cpuset.cpus | 84 | echo ${cpus} > $scope/cpuset.cpus |
| 85 | echo root > $scope/cpuset.cpus.partition | 85 | echo root > $scope/cpuset.cpus.partition |
nixos/snowglobe.nix+3-4| ... | @@ -8,7 +8,6 @@ let | ... | @@ -8,7 +8,6 @@ let |
| 8 | irohNetwork = builtins.fromJSON (builtins.readFile ../service/iroh-relay/network.json); | 8 | irohNetwork = builtins.fromJSON (builtins.readFile ../service/iroh-relay/network.json); |
| 9 | spacebarVoice = builtins.fromJSON (builtins.readFile ../service/spacebar/voice-network.json); | 9 | spacebarVoice = builtins.fromJSON (builtins.readFile ../service/spacebar/voice-network.json); |
| 10 | extMantikafasi = builtins.fromJSON (builtins.readFile ../config/ext-mantikafasi.json); | 10 | extMantikafasi = builtins.fromJSON (builtins.readFile ../config/ext-mantikafasi.json); |
| 11 | extRachel = builtins.fromJSON (builtins.readFile ../config/ext-rachel.json); | ||
| 12 | udpPorts = xmppUDPPorts ++ [ irohNetwork.quic spacebarVoice.media spacebarVoice.nativeMedia ]; | 11 | udpPorts = xmppUDPPorts ++ [ irohNetwork.quic spacebarVoice.media spacebarVoice.nativeMedia ]; |
| 13 | encryptionRoots = { | 12 | encryptionRoots = { |
| 14 | clover = "clover"; | 13 | clover = "clover"; |
| ... | @@ -19,7 +18,7 @@ let | ... | @@ -19,7 +18,7 @@ let |
| 19 | }; | 18 | }; |
| 20 | in | 19 | in |
| 21 | { | 20 | { |
| 22 | imports = [ ./snowglobe-network.nix ./mac-studio-sandbox.nix ./knife-linux.nix ./adb.nix ./mac-vm.nix ./ext-mantikafasi.nix ./ext-rachel.nix ./vm-disks.nix ./zfs-read-cache.nix ./gpu-unlock.nix ]; | 21 | imports = [ ./snowglobe-network.nix ./mac-studio-sandbox.nix ./knife-linux.nix ./adb.nix ./mac-vm.nix ./ext-mantikafasi.nix ./win11-gaming.nix ./vm-disks.nix ./zfs-read-cache.nix ./gpu-unlock.nix ]; |
| 23 | 22 | ||
| 24 | networking.hostName = "snowglobe"; | 23 | networking.hostName = "snowglobe"; |
| 25 | environment.etc."machine-info".text = '' | 24 | environment.etc."machine-info".text = '' |
| ... | @@ -88,7 +87,7 @@ in | ... | @@ -88,7 +87,7 @@ in |
| 88 | script = '' | 87 | script = '' |
| 89 | description="$(${pkgs.python3}/bin/python3 ${./upnp-discover.py} ${lib.escapeShellArg config.networking.defaultGateway.address})" | 88 | description="$(${pkgs.python3}/bin/python3 ${./upnp-discover.py} ${lib.escapeShellArg config.networking.defaultGateway.address})" |
| 90 | exec ${pkgs.miniupnpc}/bin/upnpc -u "$description" -e "Snow Globe services" -r \ | 89 | exec ${pkgs.miniupnpc}/bin/upnpc -u "$description" -e "Snow Globe services" -r \ |
| 91 | ${lib.concatMapStringsSep " " (port: "${toString port} TCP") (xmppTCPPorts ++ [ extMantikafasi.sshPort extMantikafasi.vncPort extRachel.sshPort ])} \ | 90 | ${lib.concatMapStringsSep " " (port: "${toString port} TCP") (xmppTCPPorts ++ [ extMantikafasi.sshPort extMantikafasi.vncPort ])} \ |
| 92 | ${lib.concatMapStringsSep " " (port: "${toString port} UDP") (udpPorts ++ lib.range xmppNetwork.relay_first xmppNetwork.relay_last)} | 91 | ${lib.concatMapStringsSep " " (port: "${toString port} UDP") (udpPorts ++ lib.range xmppNetwork.relay_first xmppNetwork.relay_last)} |
| 93 | ''; | 92 | ''; |
| 94 | }; | 93 | }; |
| ... | @@ -149,7 +148,7 @@ in | ... | @@ -149,7 +148,7 @@ in |
| 149 | }; | 148 | }; |
| 150 | environment.variables.SNOWGLOBE_POOL = pool; | 149 | environment.variables.SNOWGLOBE_POOL = pool; |
| 151 | environment.variables.SNOWGLOBE_DOMAIN = "paperclover.net"; | 150 | environment.variables.SNOWGLOBE_DOMAIN = "paperclover.net"; |
| 152 | environment.variables.SNOWGLOBE_LOCAL_AI = "false"; | 151 | environment.variables.SNOWGLOBE_LOCAL_AI = "true"; |
| 153 | 152 | ||
| 154 | system.stateVersion = "26.05"; | 153 | system.stateVersion = "26.05"; |
| 155 | } | 154 | } |
nixos/win11-gaming.nix created+113| ... | @@ -0,0 +1,113 @@ | ||
| 1 | { lib, pkgs, ... }: | ||
| 2 | let | ||
| 3 | box = builtins.fromJSON (builtins.readFile ../config/win11-gaming.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 | # Apollo's Moonlight ports; its web UI (47990) stays reachable only from Snow Globe. | ||
| 6 | streamTCP = [ 47984 47989 48010 ]; | ||
| 7 | streamUDP = [ 47998 47999 48000 48002 48010 ]; | ||
| 8 | # Open forwarding: libvirt adds no firewall rules, so the rules below are the whole policy. | ||
| 9 | network = pkgs.writeText "win11-gaming-network.xml" '' | ||
| 10 | <network> | ||
| 11 | <name>win11-gaming</name> | ||
| 12 | <forward mode='open'/> | ||
| 13 | <bridge name='${box.bridge}' stp='on' delay='0'/> | ||
| 14 | <dns><forwarder addr='1.1.1.1'/></dns> | ||
| 15 | <ip address='${box.gatewayAddress}' netmask='255.255.255.0'> | ||
| 16 | <dhcp><host mac='${box.mac}' ip='${box.guestAddress}'/><range start='10.101.0.100' end='10.101.0.120'/></dhcp> | ||
| 17 | </ip> | ||
| 18 | </network> | ||
| 19 | ''; | ||
| 20 | in | ||
| 21 | { | ||
| 22 | # libvirt moves the 3090 between nvidia and vfio-pci when the guest starts and stops; the daemon would hold it open. | ||
| 23 | hardware.nvidia.nvidiaPersistenced = lib.mkForce false; | ||
| 24 | |||
| 25 | systemd.services.win11-gaming-storage = { | ||
| 26 | wantedBy = [ "multi-user.target" ]; | ||
| 27 | before = [ "libvirtd.service" ]; | ||
| 28 | requires = [ "zfs-import-work.service" ]; | ||
| 29 | after = [ "zfs-import-work.service" "zfs-mount.service" ]; | ||
| 30 | serviceConfig = { Type = "oneshot"; RemainAfterExit = true; }; | ||
| 31 | script = '' | ||
| 32 | if ! ${pkgs.zfs}/bin/zfs list -H -o name ${box.dataset} >/dev/null 2>&1; then | ||
| 33 | ${pkgs.zfs}/bin/zfs create -o mountpoint=${box.root} -o compression=lz4 -o atime=off -o recordsize=64K ${box.dataset} | ||
| 34 | fi | ||
| 35 | ${pkgs.zfs}/bin/zfs set quota=560G ${box.dataset} | ||
| 36 | test "$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE --mountpoint ${box.root})" = ${box.dataset} | ||
| 37 | chmod 0700 ${box.root} | ||
| 38 | ''; | ||
| 39 | }; | ||
| 40 | |||
| 41 | systemd.services.win11-gaming-network = { | ||
| 42 | wantedBy = [ "multi-user.target" ]; | ||
| 43 | requires = [ "libvirtd.service" ]; | ||
| 44 | after = [ "libvirtd.service" ]; | ||
| 45 | before = [ "libvirt-guests.service" ]; | ||
| 46 | serviceConfig = { Type = "oneshot"; RemainAfterExit = true; }; | ||
| 47 | path = [ pkgs.libvirt ]; | ||
| 48 | script = '' | ||
| 49 | virsh net-info win11-gaming >/dev/null 2>&1 || virsh net-define ${network} | ||
| 50 | virsh net-autostart win11-gaming | ||
| 51 | virsh net-info win11-gaming | grep -q '^Active:.*yes' || virsh net-start win11-gaming | ||
| 52 | ''; | ||
| 53 | }; | ||
| 54 | |||
| 55 | # Pinned vCPUs alone would still share those cores with host processes. | ||
| 56 | virtualisation.libvirtd.hooks.qemu.win11-gaming-cpus = pkgs.writeShellScript "win11-gaming-cpus" '' | ||
| 57 | test "$1" = win11-gaming -a "$2" = started || exit 0 | ||
| 58 | # The guest may start before knife-linux reserves its own CPUs here. | ||
| 59 | reserved=$(cat /sys/fs/cgroup/machine.slice/cpuset.cpus.exclusive) | ||
| 60 | echo "''${reserved:+$reserved,}${box.cpus}" > /sys/fs/cgroup/machine.slice/cpuset.cpus.exclusive | ||
| 61 | for scope in /sys/fs/cgroup/machine.slice/machine-qemu*win11\\x2dgaming.scope; do | ||
| 62 | echo ${box.cpus} > $scope/cpuset.cpus.exclusive | ||
| 63 | echo ${box.cpus} > $scope/cpuset.cpus | ||
| 64 | echo root > $scope/cpuset.cpus.partition | ||
| 65 | done | ||
| 66 | ''; | ||
| 67 | |||
| 68 | # libvirt-guests suspends guests at host shutdown, which fails with a passed-through GPU. | ||
| 69 | systemd.services.win11-gaming-shutdown = { | ||
| 70 | wantedBy = [ "multi-user.target" ]; | ||
| 71 | after = [ "libvirt-guests.service" ]; | ||
| 72 | # Stopping this unit shuts the guest down; a changed unit must not do that on switch. | ||
| 73 | restartIfChanged = false; | ||
| 74 | serviceConfig = { Type = "oneshot"; RemainAfterExit = true; TimeoutStopSec = 300; }; | ||
| 75 | path = [ pkgs.libvirt ]; | ||
| 76 | script = "true"; | ||
| 77 | preStop = '' | ||
| 78 | virsh shutdown win11-gaming 2>/dev/null || exit 0 | ||
| 79 | for _ in $(seq 1 120); do | ||
| 80 | virsh domstate win11-gaming | grep -q 'shut off' && exit 0 | ||
| 81 | sleep 2 | ||
| 82 | done | ||
| 83 | ''; | ||
| 84 | }; | ||
| 85 | |||
| 86 | # The router forwards none of these ports, so only the LAN reaches the stream. | ||
| 87 | networking.nat = { | ||
| 88 | enable = true; | ||
| 89 | externalInterface = "enp4s0"; | ||
| 90 | internalInterfaces = [ box.bridge ]; | ||
| 91 | forwardPorts = | ||
| 92 | map (port: { sourcePort = port; destination = "${box.guestAddress}:${toString port}"; proto = "tcp"; }) streamTCP | ||
| 93 | ++ map (port: { sourcePort = port; destination = "${box.guestAddress}:${toString port}"; proto = "udp"; }) streamUDP; | ||
| 94 | }; | ||
| 95 | |||
| 96 | networking.firewall.extraCommands = '' | ||
| 97 | iptables -N win11-gaming 2>/dev/null || iptables -F win11-gaming | ||
| 98 | iptables -A win11-gaming -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT | ||
| 99 | ${lib.concatMapStringsSep "\n" (range: "iptables -A win11-gaming -d ${range} -j DROP") privateRanges} | ||
| 100 | iptables -A win11-gaming -p tcp --dport 25 -j DROP | ||
| 101 | iptables -A win11-gaming -j ACCEPT | ||
| 102 | iptables -I FORWARD -i ${box.bridge} -j win11-gaming | ||
| 103 | iptables -I nixos-fw 1 -i ${box.bridge} -j DROP | ||
| 104 | iptables -I nixos-fw 1 -i ${box.bridge} -p udp -m multiport --dports 53,67 -j ACCEPT | ||
| 105 | iptables -I nixos-fw 1 -i ${box.bridge} -p tcp --dport 53 -j ACCEPT | ||
| 106 | iptables -I nixos-fw 1 -i ${box.bridge} -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT | ||
| 107 | ''; | ||
| 108 | networking.firewall.extraStopCommands = '' | ||
| 109 | iptables -D FORWARD -i ${box.bridge} -j win11-gaming 2>/dev/null || true | ||
| 110 | iptables -F win11-gaming 2>/dev/null || true | ||
| 111 | iptables -X win11-gaming 2>/dev/null || true | ||
| 112 | ''; | ||
| 113 | } | ||
tools/ext-rachel.md deleted-33| ... | @@ -1,33 +0,0 @@ | ||
| 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 | ||
| 4 | dashboard user `rachel`, with the RTX 3090 passed through. Its 500 GB disk is a standalone qcow2 on the `work` | ||
| 5 | NVMe 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 | ``` | ||
| 9 | internet ──UPnP──> Snow Globe :2223 ─DNAT─> 10.101.0.2:22 (Windows OpenSSH, PowerShell) | ||
| 10 | internet ──> Snow Globe :22 as rachel ─ForceCommand ssh─> 10.101.0.2:22 | ||
| 11 | dashboard console / Computer MCP ─── libvirt VNC + guest agent (owner rachel) | ||
| 12 | guest ── 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/win11-gaming.md created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | # win11-gaming | ||
| 2 | |||
| 3 | `win11-gaming` is Clover's Windows 11 Pro libvirt guest for games (`windows-11-pro-v2` preset, 10 vCPU, | ||
| 4 | 40 GiB, account `snow`), with the RTX 3090 passed through. Its 500 GB disk is a standalone qcow2 on the `work` | ||
| 5 | NVMe pool (`work/win11-gaming` at `/srv/win11-gaming`); NVRAM, seed, `domain.xml`, `access.json` and | ||
| 6 | `apollo.json` stay in `/srv/vm/win11-gaming`. `config/win11-gaming.json` and `nixos/win11-gaming.nix` own the | ||
| 7 | host side. | ||
| 8 | |||
| 9 | ``` | ||
| 10 | LAN ── Snow Globe 10.0.0.1 :47984,47989,48010/tcp :47998-48002,48010/udp ─DNAT─> Apollo (Moonlight host) | ||
| 11 | Snow Globe ── ssh snow@10.101.0.2 (config/admin.pub only) / Apollo web API :47990 | ||
| 12 | dashboard console / Computer MCP ─── libvirt VNC + guest agent (owner Clover) | ||
| 13 | guest ── virbr-ext (forward mode='open') ── MASQUERADE ── internet only | ||
| 14 | ``` | ||
| 15 | |||
| 16 | - **GPU:** the 3090 serves either this guest or local AI, chosen with the dashboard's Games/AI switch. The | ||
| 17 | domain's `managed='yes'` hostdevs make libvirt move both functions to vfio-pci at start and back to nvidia at | ||
| 18 | shut off; `nvidia-persistenced` stays off so nothing holds the device. Windows Update is barred from driver | ||
| 19 | updates (`ExcludeWUDriversInQualityUpdate`); install GeForce drivers with `-s -n`. | ||
| 20 | - **Streaming:** Apollo 0.4.6 (a Sunshine fork) encodes HEVC on NVENC and creates a SudoVDA virtual display at | ||
| 21 | each client's resolution, so no monitor or dummy plug is needed. `sg game` on the Mac pairs and streams with | ||
| 22 | Moonlight; another client (the Apple TV) shows a PIN for `sg game pin <PIN>`. Apollo's web login is in | ||
| 23 | `apollo.json`; its UI only answers Snow Globe. The router forwards none of the stream ports. | ||
| 24 | - **Isolation:** libvirt adds no rules for an open network; the `win11-gaming` chain drops new connections to | ||
| 25 | private, CGNAT and link-local ranges and port 25. From the guest, Snow Globe answers only DHCP and DNS. | ||
| 26 | Snow Globe and the forwarded stream ports can still reach into the guest. | ||
| 27 | - **CPUs and memory:** vCPUs are pinned 1:1 to cores 3-7 and their siblings 19-23, which a libvirt hook makes an | ||
| 28 | exclusive cpuset partition beside `knife-linux` (8 cores); the host keeps 0-2 and 16-18. VFIO pins all 40 GiB, so | ||
| 29 | the ZFS ARC floor is 16 GiB and `knife-linux` is capped at 72 GiB to leave headroom. | ||
| 30 | - **OpenSSH:** the Windows `OpenSSH.Server` capability, key-only, PowerShell as the shell: | ||
| 31 | `ssh -J root@10.0.0.1 snow@10.101.0.2`. | ||
| 32 | - **Shutdown:** `win11-gaming-shutdown` shuts the guest down before `libvirt-guests`, whose managed save cannot | ||
| 33 | capture a VFIO device. | ||