# Setting up a node A node is set up by the **owner of the build machine**, on that machine. One command does it, and the same command updates it later. ## What you get - a user `midas-node` that runs the node — never your own account; - a firewall on your machine that keeps the node off your home network and off the machine itself (it may reach the hub, the resolvers your machine used when it was set up, and the internet), in force from boot; - the node itself: a rootless container (Linux) or a virtual machine (Mac), started at boot, limited in memory and CPUs; - a small service, as root, that sends the hub what the machine's chip draws once a minute — one per machine, whichever nodes it has (see [Power](#power)). The node registers itself with the hub; nobody copies keys around. ## Before you start - **The hub knows the node.** An agent or the workspace's operator adds it, with your machine's WireGuard address: ```bash midas nodes add box-1 --machine box --address 10.44.0.3 [--gpu] ``` - **WireGuard comes up at boot without anyone logging in** (the node waits for it), and survives your public address changing: - wg-quick: `sudo systemctl enable wg-quick@wg0`, and `PersistentKeepalive = 25` under `[Peer]` in `/etc/wireguard/wg0.conf`. - NetworkManager: by default it keeps the private key in *your* keyring, so the tunnel cannot come up before you log in, nor from `sudo` (`Secrets were required, but not provided`). Store the key with the connection, let it start on its own and give it the route to the workspace's network: ```bash sudo nmcli connection modify wg0 wireguard.private-key-flags 0 \ wireguard.private-key "$(sudo wg show wg0 private-key)" \ connection.autoconnect yes connection.permissions "" \ +ipv4.routes 10.44.0.0/24 ``` then add `persistent-keepalive=25` under `[wireguard-peer.…]` in `/etc/NetworkManager/system-connections/wg0.nmconnection` and `sudo nmcli connection reload && sudo nmcli connection up wg0`. - **The tunnel passes traffic** — see [Check the tunnel](#check-the-tunnel). Every `setup` starts by asking the hub over it. - **Linux:** rootless podman and nftables. **Mac:** see [macos-nodes.md](macos-nodes.md) (Tart, Packer). ### Check the tunnel The hub is `10.44.0.1`; your machine has its own address on the same network (the one the node was added with). Four checks, in order — each one's failure is a different fault: ```bash sudo wg show # 1. "latest handshake" under two minutes old ip route get 10.44.0.1 # 2. must say "dev wg0", not your LAN's interface ping -c3 10.44.0.1 # 3. answers curl -m5 http://10.44.0.1:4791/v1/health # 4. {"ok":true,…} ``` | fails at | what it means | fix | |---|---|---| | 1, handshake hours old | your public address changed and nothing sent since, or UDP 51820 out is blocked | the keepalive above, then `ping` once to wake it | | 1, `Secrets were required` from `nmcli … up` | the key is in your keyring, not with the connection | the NetworkManager step above | | 1, a peer with no `endpoint` or `allowed ips`; 3 says `Required key not available` | the connection knows the hub's key and nothing else, so nothing is routed to it — `nmcli` still says `activated` | `sudo nmcli connection modify wg0 wireguard.peers " endpoint=:51820 allowed-ips=10.44.0.0/24 persistent-keepalive=25"`, then `sudo nmcli connection up wg0` | | 2, a route via `wlan0`/`eth0` | the tunnel is up but nothing routes into it (an address shown with `noprefixroute`) | `sudo ip route add 10.44.0.0/24 dev wg0` now; `+ipv4.routes` above for good | | 3 or 4 with 1 and 2 fine | the hub's side | ask the workspace's operator; on the hub `sudo wg show` names your peer and when it last heard from you | `connection refused` from setup usually means the address after `--hub` is your own machine's, not the hub's. ## 1. Build and install midas Build it yourself, from a commit you have read — that binary is the only midas code that ever runs on your machine: ```bash git clone && cd midas cargo build --release ``` The page the hub serves is not needed here; a build without Bun is fine. **On SteamOS**, build inside a distrobox (the distrobox shares your home) and run setup outside it, where sudo reaches the system: ```bash distrobox enter arch sudo pacman -S --needed rustup git && rustup default stable cd ~/midas && cargo build --release exit ``` ## 2. Set it up ```bash sudo target/release/midas setup box-1 --hub 10.44.0.1:4791 ``` `box-1` stands for your node's name as the hub knows it, and `10.44.0.1:4791` is the hub, never your own machine's address. The hub's address is needed the first time only. Setup copies the binary it runs from to `/var/lib/midas/bin/midas` — where only root can change it, because root runs it; writable on SteamOS, whose `/usr` is not — and runs from there on. Setup also makes `midas` a command: `/etc/profile.d/midas.sh` puts `/var/lib/midas/bin` on every login shell's PATH (log in again, or `. /etc/profile.d/midas.sh` in the shell you have), and a link `/usr/local/bin/midas` lets `sudo midas …` find it. Where `/usr` is read-only (SteamOS) there is no link, and setup says so: with `sudo`, keep giving the full path there. Options, all remembered: | option | default | |---|---| | `--memory` | `10g` (Mac: `24g`) | | `--cpus` | `6` | | `--gpu` | `/dev/dri/renderD128`, or `none` | | `--mount HOST_DIR:/CONTAINER_DIR` | — (read-only; e.g. an Android NDK) | | `--user` | `midas-node` | It ends with `registered with the hub`. The hub's warmer then builds the node up, and it joins the pool with its first heartbeat. **GPU machines, optional:** to cap the GPU's own memory as well (an AMD handheld's shared memory is guarded either way), let systemd hand the `dmem` controller to users — a file `/etc/systemd/system/user@.service.d/dmem.conf` with `[Service]` and `DelegateControllers=cpu memory pids dmem` — reboot, and run setup again. `midas check` says whether the cap is in force. **A render node without a GPU:** QEMU's 3D virtio-gpu (what a guest's Vulkan goes through, Venus) needs a GL context, which in a container only a render node gives. A machine with no GPU (the VPS) gets one from the kernel's `vgem`: `echo vgem | sudo tee /etc/modules-load.d/vgem.conf`, `sudo modprobe vgem`, the node's user in the `render` group (`sudo usermod -aG render midas-node`), and the render node open to all, since sshd hands a node's session to `build` with that user's own groups only: a file `/etc/udev/rules.d/70-vgem-render.rules` with `SUBSYSTEM=="drm", KERNEL=="renderD*", KERNELS=="vgem", MODE="0666"` (vgem only hands out buffers; many distributions leave every render node so). Then setup with `--gpu /dev/dri/renderD128`. Rendering itself stays on the CPU (lavapipe): this gives QEMU its context, not the node a GPU, so the hub's `gpu` flag for it stays off. ## 3. Check it ```bash midas node status ``` ``` node box-1 on this machine (user midas-node, hub 10.44.0.1:4791) ✓ running ✓ firewall in force ✓ heartbeat 16s ago · midas f027df28 · load 1.2 · 120 GB free · warm at 3dac67f6 · free ``` More in [usage.md](usage.md#on-a-build-machine). ## Updating Pull, build and install a newer midas (step 1), then run setup again — no options needed: ```bash cd ~/midas && git pull && git log -1 # read what you are about to run cargo build --release --target x86_64-unknown-linux-musl sudo install -D -m 755 target/x86_64-unknown-linux-musl/release/midas /var/lib/midas/bin/midas sudo /var/lib/midas/bin/midas setup box-1 ``` On SteamOS the build line runs inside the distrobox, as in step 1: `distrobox enter arch -- sh -c 'cd ~/midas && cargo build --release --target x86_64-unknown-linux-musl'`. ### From your own machine, all at once `midas update` does the above for every build machine, one after another, from the machine you sit at: this checkout's commits sent to each as a git bundle (a machine's own git key often works only from a login with its ssh agent), built there (distrobox included), installed and set up with your sudo. The hub only says which machines and nodes there are; how to reach each is your config, in `~/.config/midas/hub.env`: ```bash MIDAS_MACHINES=deck=deck@192.168.1.50 box=me@box.lan # machine=ssh target, as its owner MIDAS_SRC=~/code/midas # the checkout it installs ``` The machine you run it on needs no entry: its nodes are set up there, so it builds in place. A machine with no checkout of midas — the hub's own, which has no toolchain — gets the binary another machine in `MIDAS_MACHINES` built for its architecture at the same commit (the deck's, for x86_64; machines go in name order, so one updated in the same run counts), and runs `setup` from a copy in /tmp the way deploy.sh does, without installing it: the hub's own `/usr/local/bin/midas` stays as it was. Where sudo needs no password (the vps's `ubuntu`), none is asked for. Then: ```bash midas update # every machine midas update deck # only those named midas update --src DIR # another checkout ``` A machine in neither is skipped, and one with a held node is left for later (exit 75), waited for (`--wait`: its nodes are drained, their holders told, and the update starts once they let go), or updated anyway (`--force` cuts the holder off); the nodes being updated are drained while it runs. The end says which machines were updated, skipped, held or failed. The machines only need `~/midas` and cargo, not a midas that has `update`; where the installed one predates it, run the checkout's own: `cargo run --release -- update`. Run without a terminal — by an agent — sudo asks for each password in a dialog on your screen (macOS's own; elsewhere set `SUDO_ASKPASS`): this machine's through `sudo -A` with midas as its askpass, a remote machine's through ssh's stdin to its one `sudo -S`. Neither goes into an argument list or into the output the agent reads. The dialog names the machine and the nodes; type a password only into one you expected. The node keeps its checkout and warm build directory. It restarts, so do it when `midas node status` says `free`. Afterwards `midas --version` and the `midas …` on status's fourth line name the build you installed. Setup is also what makes later features real on your machine: a newer midas does nothing until it is installed and set up again. A machine still on a build from before `setup` made `midas` a command has no `/etc/profile.d/midas.sh`, for instance. ## Power Setup also starts `midas node power` on the machine itself — not in the node: a VM sees no power sensor, and a stopped node's machine still draws. Once a minute it sends the hub the chip's power in watts, from - a Mac: `powermetrics` (root only), its combined CPU, GPU and Neural Engine power — the launchd job `eu.midas.power.machine`, log `/var/log/midas-power.log`; - Linux with an AMD APU (the Steam Deck): amdgpu's `power1_average`, the whole package — the systemd unit `midas-power.service`; - other Linux: RAPL's package energy counters. That is the chip, not the wall socket: memory, disk, fans and the power supply's loss come on top. A machine with none of these (a cloud VM) has nothing to send, and the service ends at once. It runs a copy of midas at `/var/lib/midas/power/midas`, put there by each setup. The hub takes a sample only from an address one of its nodes has, and keeps them for good; the page's Workspace and `midas power` show them. Removing the machine's last node stops it. ### Asleep while nobody uses it (Macs) A Mac node free for an hour — no lease, no ssh session, no bot, not drained, nobody waiting for a node — has its VM shut down, and started again as soon as somebody waits for a node it could serve, or it is drained for an update. The power job above does it, asking the hub every 15 s; the guest is asked to shut down (`tart run`'s SIGUSR2), never stopped hard, and its build directory stays on disk. Measured on the mini in November 2026: an idle macOS guest keeps about a core busy (audiomxd, configd), 17 W all night for two, and a sound device taken away with `--no-audio` changed nothing. Waking takes the VM's boot and its first heartbeat, a minute or two, which the first build after a quiet hour waits for. `midas status` and the page say *asleep*, not offline, and `midas check` does not count it as a problem. A machine whose power job stops asking has its nodes left awake. Linux nodes are not stopped. ## Removing ```bash sudo /var/lib/midas/bin/midas setup box-1 --remove ``` stops the node and removes its firewall. Its user and data stay until you delete them (`sudo userdel -r midas-node`). ## Renaming A node's name is a label; what it is, is the uuid the hub gave it, and its data — the volume at `/work`, or a Mac node's VM — is named once, when it is first set up, and never again from the name (`storage` in its settings file). So a rename moves nothing. At the hub, once nobody holds the node: ```bash midas nodes rename box-1 box-2 ``` then on the machine: ```bash sudo /var/lib/midas/bin/midas setup box-2 ``` Setup finds `box-1` here by its uuid (or, for a node set up before uuids, by the hub listing `box-1` as a former name), stops it, and starts `box-2` on the same data: the checkout, the warm build directory, its ssh host key — which the hub's known hosts already trust on that port — and its bots' secret. It refuses while the hub still knows `box-1` too: that is two nodes, not one renamed. A node set up before storage was recorded keeps its data under the name it had then (`midas-node-box-1-work`); the settings file says so. ## Bot credentials Usually set at the hub: `midas bot token ` from anywhere with a caller key ([usage.md](usage.md#running-a-bot)), which works for a Mac node too. What follows is the way that keeps the token on this machine instead. An agent may run a bot on your node (a program it talks to over MCP — [usage.md](usage.md#running-a-bot)), and a bot usually needs a credential of its own: for Cartopolis, an access token you create there for it. You give it here, on your machine; it never goes to the hub: ```bash sudo /var/lib/midas/bin/midas bot setup box-1 --env CARTO_TOKEN ``` It asks for the value with echo off (`--stdin` reads one line from a pipe instead) and stores it as `CARTO_TOKEN=…` in `bot.env`, beside the node's `node.env` — readable only by the node's `build` user, the user bots run as, which sees it as `/config/bot.env`. Every bot started on the node from then on has it in its environment. The name is remembered: to change the value, run it again without `--env`. `--remove` deletes it. Not on Mac nodes yet. Anything running as `build` in the node can read a running bot's environment — the agent holding it, and the hub's operator key — so give a token only what the bot needs, and revoke it where you made it if in doubt. ## When something is wrong | symptom | look at | |---|---| | `midas node status` says not running | `sudo midas node logs` | | running, but no heartbeat | [Check the tunnel](#check-the-tunnel) | | setup: `asking the hub … timed out` or `refused` | [Check the tunnel](#check-the-tunnel) | | down after a reboot | WireGuard at boot (above) | | setup says the address is not on this machine | WireGuard is not up, or the hub has another address for the node | | the hub logs `warm_failed … REMOTE HOST IDENTIFICATION HAS CHANGED` | something other than this node answers on its ssh port — see below | ### A second copy of the node Before the node had its own user, `install.sh` ran it as the machine's owner, from `~/.config/containers/systemd/midas-node-.container`. A machine set up then and again since has **two** nodes of one name. Whichever starts first at boot holds the ssh port; when that is the old one, it serves a host key the hub has never seen (the warmer refuses it, rightly), its git key is not registered, and the real node never starts. `midas node status` can still say `✓ running`, because both containers have the same name. To tell: ```bash ss -ltnp | grep :2223 # which user's process holds the port ls ~/.config/containers/systemd/ # as the owner: should hold no midas-node-* ``` Retire the old one as the owner (no sudo), then start the real one: ```bash mkdir -p ~/midas-old && mv ~/.config/containers/systemd/midas-node-box-1.container ~/midas-old/ systemctl --user daemon-reload && systemctl --user stop midas-node-box-1 sudo /var/lib/midas/bin/midas node restart ``` Leave the hub's `known_hosts` alone: the key it has is the real node's. The old copy's volume stays until `podman volume rm midas-node-box-1-work`.