xonecas.io
8447
Co

conveyor / commit ed93980

Bake a Debian 13 image for the host's arch, and run guests on macOS with HVF

Co-Authored-By: Claude Opus 5.5

sacenox2026-11-13 ed93980f51b5aeb9e41f711ee69ed885a0121c0d parent a09c781

8 files changed

.cargo/config.toml+5−0
@@ -2,3 +2,8 @@
22 # The app and the widgets it loads share one std and one Rune, so both link them dynamically.
33 # Their own target dir, since the flag rebuilds everything. Run it from the repo's root.
44 app = ["build", "--release", "-p", "conveyor-app", "-p", "conveyor-widgets", "--target-dir", "target/app", "--config", "build.rustflags=['-Cprefer-dynamic']"]
5+# On a Mac, the guest's `conveyor` CLI: a static Linux build, since the host's binary can't run there.
6+guest = ["build", "--release", "-p", "conveyor", "--target", "aarch64-unknown-linux-musl"]
7+
8+[target.aarch64-unknown-linux-musl]
9+linker = "rust-lld"
DESIGN.md+18−4
@@ -2,7 +2,7 @@
22
33 > Reduce user cognitive load. The conveyor never stops.
44
5-Status: draft. Items marked **(spike)** are unproven and get a throwaway prototype before any product code. Linux only. Other platforms come after the app is good on Linux.
5+Status: draft. Items marked **(spike)** are unproven and get a throwaway prototype before any product code. Linux (x86_64, KVM) and macOS (Apple silicon, HVF). The guest is always Linux, for the host's architecture.
66
77 ## Principles
88
@@ -36,7 +36,7 @@ Status: draft. Items marked **(spike)** are unproven and get a throwaway prototy
3636
3737 - `conveyord` runs whether or not the app is open. Closing the window never stops work.
3838 - The guest's `conveyor` CLI reaches the host through a unix socket forwarded over the ssh session that runs the agent (`ssh -R`). Each socket is bound to one ticket, so a guest can touch only its own ticket. Socket paths are unique per run, because a restored snapshot brings back the old session's socket.
39-- **No root and no libvirt.** conveyord runs `qemu-system-x86_64` as your user: user-mode networking with ssh on a localhost port, and the guest agent, QMP and VNC on unix sockets in `/tmp`. Unix socket paths max out at 108 bytes, so they can't live under deep paths.
39+- **No root and no libvirt.** conveyord runs `qemu-system-x86_64` (`qemu-system-aarch64` on a Mac) as your user: user-mode networking with ssh on a localhost port, and the guest agent, QMP and VNC on unix sockets in `/tmp`. Unix socket paths max out at 108 bytes (104 on macOS), so they can't live under deep paths.
4040 - The guest clones from the host and pushes its branch back. Nothing else leaves the VM except through the CLI.
4141 - **Agent config:** at boot, conveyor copies your host agent folders (`~/.claude`, `~/.config/opencode`, and so on) into the guest. The agents use the login, settings and skills you already manage.
4242
@@ -151,10 +151,10 @@ Proven in spike 3: restoring the `decide` snapshot brought the disk, the transcr
151151
152152 ## VMs and concurrency
153153
154-The base image is built once by `tools/bake.py`, from the ISO already on disk, with nothing downloaded again. Besides the agents it installs the pinned Rust toolchain and pre-builds the widget library's preview:
154+The base image is built once by `tools/bake.py`, from Debian 13's cloud image for the host's architecture, downloaded once and kept in `images/`. cloud-init, seeded over HTTP from the bake, creates the user and runs the provisioning. The cloud kernel has no GPU driver, so the bake swaps it for the generic one. Besides the agents it installs the pinned Rust toolchain and pre-builds the widget library's preview:
155155
156156 ```
157-ISO ──install + configure (vm.sh steps)──▶ base.qcow2 (read-only)
157+cloud image ──cloud-init + provision──▶ base.qcow2 (read-only)
158158 ├─▶ t-1222.qcow2 overlay
159159 ├─▶ t-1223.qcow2 overlay
160160 └─▶ refine-1224.qcow2 overlay
@@ -178,6 +178,20 @@ Measured in spike 1, on the host:
178178 | Unique machine id and ssh host keys per overlay | yes, reset in the base and regenerated at first boot |
179179 | Guest screen without a VNC client | QMP `screendump` writes a PNG |
180180
181+Measured on a Mac (M5, 10 cores, 32 GB), Debian 13 arm64:
182+
183+| What | Result |
184+| --- | --- |
185+| Bake: download, provision, verify, pre-build the widget library | **5.5 min**, once. 8.4 GiB image |
186+| Create an overlay | **26–31 ms** |
187+| Boot an overlay to ssh | **10.0 s** |
188+| Three guests booting at the same time | 22.4 s each: three 8-vCPU guests on 10 cores |
189+| Host memory per idle guest with a desktop | **~1.9 GB RSS** |
190+| Guest allocates and frees 5 GB | **Not returned.** The guest reports free pages, but QEMU on macOS keeps them: a guest costs its peak until it stops |
191+| Unique machine id and ssh host keys per overlay | yes |
192+
193+On a Mac the guest's `conveyor` CLI is a static Linux build (`cargo guest`), since the host's binary can't run there.
194+
181195 **Assigned RAM is a ceiling, not a cost.** Free page reporting returns memory the guest frees, so a guest costs what it is using. Three slots fit easily, and the real limit is concurrent builds. KSM needs root, so it is untested and not needed yet.
182196
183197 ## App
HANDOFF.md+2−1
@@ -20,7 +20,8 @@ Ctrl+click ─▶ ticket ─▶ VM boot ─▶ push ─▶ agent ─▶ done ─
2020 | Daemon | `cargo build --release -p conveyor && ./target/release/conveyor daemon` |
2121 | App | `cargo app && ./target/app/release/conveyor-app` (`--safe` opens safe mode) |
2222 | Tests | `cargo test --release -p conveyor trial` |
23-| Base image | delete `~/.local/share/conveyor/images/base.qcow2`, then `tools/bake.py bake` (about 10 min) |
23+| Base image | delete `~/.local/share/conveyor/images/base.qcow2`, then `tools/bake.py bake` (about 6 min) |
24+| Guest CLI, on a Mac | `rustup target add aarch64-unknown-linux-musl` once, then `cargo guest` with every daemon build |
2425
2526 Rebake when the template's dependencies change (`templates/library/preview/Cargo.toml`, `Cargo.lock`)
2627 or the bake's package list does: the image's warm cargo cache must match, or every ticket rebuilds
crates/conveyor/src/agent.rs+3−3
@@ -29,7 +29,7 @@ fn run(p: &Project, id: u32) -> Result<String, String> {
2929 let keys = give_secrets(&vm)?;
3030 vm.sh("mkdir -p ~/.local/bin ~/.conveyor && cat > ~/.local/bin/conveyor && chmod +x ~/.local/bin/conveyor",
3131 // /proc/self/exe still reads after cargo replaces the binary; current_exe() would not.
32- &std::fs::read("/proc/self/exe").map_err(|e| e.to_string())?)?;
32+ &std::fs::read(if cfg!(target_os = "macos") { crate::paths::guest_bin() } else { "/proc/self/exe".into() }).map_err(|e| e.to_string())?)?;
3333 vm.sh("cat > ~/.conveyor/rules.md", RULES.as_bytes())?;
3434
3535 note("pushing the repo");
@@ -134,7 +134,7 @@ fn stopped(project: &str, id: u32) -> String {
134134 fn give_files(vm: &Vm, p: &Project, id: u32) -> Result<String, String> {
135135 let names: Vec<String> = store::files(&p.slug, id).iter().filter_map(|f| Some(f.file_name()?.to_str()?.to_owned())).collect();
136136 if names.is_empty() { return Ok(String::new()); }
137- let tar = Command::new("tar").arg("-C").arg(store::dir(&p.slug, id)).args(["-cf", "-", "files"]).output().map_err(|e| e.to_string())?;
137+ let tar = Command::new("tar").env("COPYFILE_DISABLE", "1").arg("--no-xattrs").arg("-C").arg(store::dir(&p.slug, id)).args(["-cf", "-", "files"]).output().map_err(|e| e.to_string())?;
138138 vm.sh("mkdir -p ~/ticket && tar -C ~/ticket -xf -", &tar.stdout)?;
139139 Ok(format!("\n\nAttached, in ~/ticket/files/: {}", names.join(", ")))
140140 }
@@ -166,7 +166,7 @@ fn give_secrets(vm: &Vm) -> Result<String, String> {
166166 fn give_agent_config(vm: &Vm) -> Result<(), String> {
167167 let home = std::env::var("HOME").map_err(|e| e.to_string())?;
168168 let files: Vec<&str> = AGENT_FILES.into_iter().filter(|f| Path::new(&home).join(f).exists()).collect();
169- let tar = Command::new("tar").arg("-C").arg(&home).arg("-cf").arg("-").args(&files).output().map_err(|e| e.to_string())?.stdout;
169+ let tar = Command::new("tar").env("COPYFILE_DISABLE", "1").arg("--no-xattrs").arg("-C").arg(&home).arg("-cf").arg("-").args(&files).output().map_err(|e| e.to_string())?.stdout;
170170 vm.sh("tar -xf - -C ~", &tar).map(|_| ())
171171 }
172172
crates/conveyor/src/paths.rs+6−1
@@ -44,7 +44,7 @@ pub fn socket() -> PathBuf {
4444 std::env::var("XDG_RUNTIME_DIR").map(PathBuf::from).unwrap_or_else(|_| "/tmp".into()).join("conveyor.sock")
4545 }
4646
47-/// Per-VM sockets live in /tmp, because unix socket paths max out at 108 bytes.
47+/// Per-VM sockets live in /tmp, because unix socket paths max out at 108 bytes (104 on macOS).
4848 pub fn vm_sock(name: &str, kind: &str) -> PathBuf {
4949 PathBuf::from(format!("/tmp/cv-{name}.{kind}"))
5050 }
@@ -54,6 +54,11 @@ pub fn app_target() -> PathBuf {
5454 std::env::var("CARGO_TARGET_DIR").map_or(source().join("target"), PathBuf::from).join("app")
5555 }
5656
57+/// On a Mac, the guest's `conveyor` CLI (`cargo guest`).
58+pub fn guest_bin() -> PathBuf {
59+ std::env::var("CARGO_TARGET_DIR").map_or(source().join("target"), PathBuf::from).join("aarch64-unknown-linux-musl/release/conveyor")
60+}
61+
5762 /// Conveyor's own source, to rebuild the app when the widget library changes.
5863 pub fn source() -> PathBuf {
5964 PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/../.."))
crates/conveyor/src/vm.rs+7−4
@@ -24,17 +24,20 @@ impl Vm {
2424 let _ = fs::remove_file(s(k));
2525 }
2626 let vm = Vm { name: name.into(), port, disk };
27- run(Command::new("qemu-system-x86_64").args([
28- "-name", name, "-enable-kvm", "-machine", "q35", "-cpu", "host", "-smp", "8", "-m", &mem_mb.to_string(),
27+ let arm = cfg!(target_arch = "aarch64");
28+ let arch: &[&str] = if arm { &["-bios", "edk2-aarch64-code.fd", "-device", "virtio-gpu-pci"] } else { &["-vga", "virtio"] };
29+ run(Command::new(if arm { "qemu-system-aarch64" } else { "qemu-system-x86_64" }).args([
30+ "-name", name, "-accel", if cfg!(target_os = "macos") { "hvf" } else { "kvm" },
31+ "-machine", if arm { "virt" } else { "q35" }, "-cpu", "host", "-smp", "8", "-m", &mem_mb.to_string(),
2932 "-drive", &format!("file={},if=virtio,format=qcow2,discard=unmap", vm.disk.display()),
3033 "-netdev", &format!("user,id=n0,hostfwd=tcp:127.0.0.1:{port}-:22"), "-device", "virtio-net-pci,netdev=n0",
3134 "-device", "virtio-balloon-pci,free-page-reporting=on", "-device", "virtio-serial-pci",
3235 "-chardev", &format!("socket,path={},server=on,wait=off,id=qga0", s("qga")),
3336 "-device", "virtserialport,chardev=qga0,name=org.qemu.guest_agent.0",
3437 "-qmp", &format!("unix:{},server=on,wait=off", s("qmp")),
35- "-vga", "virtio", "-display", "none", "-vnc", &format!("unix:{}", s("vnc")),
38+ "-display", "none", "-vnc", &format!("unix:{}", s("vnc")),
3639 "-device", "qemu-xhci", "-device", "usb-tablet", "-pidfile", &s("pid"), "-daemonize",
37- ]))?;
40+ ]).args(arch))?;
3841 let t0 = Instant::now();
3942 while t0.elapsed() < Duration::from_secs(300) {
4043 if vm.ssh().arg("true").stdout(Stdio::null()).stderr(Stdio::null()).status().is_ok_and(|s| s.success()) {
templates/library/widgets/ticket.rs+1−1
@@ -89,7 +89,7 @@ impl View for TicketCard {
8989 let path = f.clone();
9090 let name = std::path::Path::new(f).file_name().map_or(f.clone(), |n| n.to_string_lossy().into_owned());
9191 files = files.child(row().key(format!("file-{name}")).w_full().px(6.0).py(4.0).radius(5.0).role("button").label(name.as_str()).help(f.as_str()).hover(t.hover)
92- .on_press_tx(move |_: &mut HostState, _: &mut Tx| { let _ = std::process::Command::new("xdg-open").arg(&path).spawn(); })
92+ .on_press_tx(move |_: &mut HostState, _: &mut Tx| { let _ = std::process::Command::new(if cfg!(target_os = "macos") { "open" } else { "xdg-open" }).arg(&path).spawn(); })
9393 .child(text(format!("▤ {name}")).font(tok::type_::LABEL).color(t.text).truncate()));
9494 }
9595 body = body.child(files);
tools/bake.py+88−138
@@ -1,28 +1,29 @@
11 #!/usr/bin/env python3
2-"""Bakes conveyor's base VM image from the local CachyOS ISO, with QEMU run as the user.
3-conveyord runs every ticket in an overlay on this image. Run it again only to change the image:
4-delete images/base.qcow2 first.
2+"""Bakes conveyor's base VM image from Debian's cloud image for this host's architecture, with QEMU
3+run as the user. conveyord runs every ticket in an overlay on this image. Run it again only to change
4+the image: delete images/base.qcow2 first.
55
66 tools/bake.py bake
77
8-State lives in ~/.local/share/conveyor. Sockets live in /tmp/cv-*, because unix socket paths max out at 108 bytes.
8+State lives in ~/.local/share/conveyor. Sockets live in /tmp/cv-*, because unix socket paths max out at 104 bytes.
99 """
10-import base64, json, signal, socket, subprocess, sys, time
10+import http.server, json, os, platform, signal, socket, subprocess, sys, threading, time, urllib.request
1111 from pathlib import Path
1212
1313 DATA = Path.home() / ".local/share/conveyor"
1414 REPO = Path(__file__).resolve().parent.parent
1515 BASE = DATA / "images/base.qcow2"
16-VMS = DATA / "vms"
1716 KEY = DATA / "id_ed25519"
18-ISO = max(Path.home().glob("s/cachyos-desktop-linux*.iso"), default=None)
17+ARM = platform.machine() in ("arm64", "aarch64")
18+CLOUD = DATA / f"images/debian-13-{'arm64' if ARM else 'amd64'}.qcow2"
19+CLOUD_URL = f"https://cloud.debian.org/images/cloud/trixie/latest/{CLOUD.name.replace('debian-13', 'debian-13-genericcloud')}"
1920 USER, PASS = "sacenox", "zzzz"
20-# nodejs from extra, beside the simdjson it links: [cachyos] shadows it with a build that can lag simdjson's soname.
21-DEV_PKGS = "starship fzf tree-sitter-cli zig rustup extra/nodejs npm go python python-pip xdotool wmctrl maim xorg-xwininfo kitty nvim git openssh claude-code qemu-guest-agent vulkan-swrast ttf-jetbrains-mono ttf-jetbrains-mono-nerd".split()
22-XORG_PKGS = "libwnck3 mesa-utils xorg-xdpyinfo xorg-server xorg-xinit xorg-xinput xorg-xkill xorg-xrandr".split()
23-DE_PKGS = """blueman file-roller galculator gvfs lightdm lightdm-gtk-greeter network-manager-applet ristretto
24-thunar-archive-plugin xdg-user-dirs-gtk xed xfce4 xfce4-notifyd xfce4-pulseaudio-plugin xfce4-screenshooter
25-xfce4-taskmanager xfce4-whiskermenu-plugin""".split()
21+DEV_PKGS = """starship fzf tree-sitter-cli rustup nodejs npm golang-go python3 python3-pip xdotool wmctrl maim x11-utils
22+kitty neovim git curl build-essential libxkbcommon-dev qemu-guest-agent mesa-vulkan-drivers fonts-jetbrains-mono""".split()
23+XORG_PKGS = "libwnck-3-0 mesa-utils xserver-xorg xinit xinput x11-xserver-utils".split()
24+DE_PKGS = """blueman file-roller galculator gvfs lightdm lightdm-gtk-greeter ristretto thunar-archive-plugin
25+xdg-user-dirs-gtk mousepad xfce4 xfce4-notifyd xfce4-pulseaudio-plugin xfce4-screenshooter xfce4-taskmanager
26+xfce4-whiskermenu-plugin""".split()
2627
2728
2829 def sock(name, kind):
@@ -33,7 +34,7 @@ def log(*a):
3334 print(f"[{time.strftime('%H:%M:%S')}]", *a, flush=True)
3435
3536
36-# ---------- QMP and guest agent: JSON over a unix socket ----------
37+# ---------- QMP: JSON over a unix socket ----------
3738
3839 class Channel:
3940 def __init__(self, path, timeout=10):
@@ -72,86 +73,33 @@ def qmp(name):
7273 return c
7374
7475
75-def qga(name, timeout=5):
76- """Guest agent channel, synced: the agent answers guest-sync-delimited with 0xff then the reply."""
77- c = Channel(sock(name, "qga"), timeout)
78- c.s.sendall(b'{"execute":"guest-sync-delimited","arguments":{"id":4242}}\n')
79- data = b""
80- while True:
81- data += c.s.recv(65536)
82- if b"\xff" in data:
83- tail = data.split(b"\xff")[-1]
84- if b"\n" in tail:
85- c.buf = tail.split(b"\n", 1)[1]
86- return c
87-
88-
89-def wait_qga(name, secs):
90- end = time.monotonic() + secs
91- while time.monotonic() < end:
92- try:
93- c = qga(name, 3)
94- c.call("guest-ping")
95- return c
96- except (OSError, ConnectionError, RuntimeError):
97- time.sleep(2)
98- sys.exit(f"{name}: guest agent did not answer in {secs} s")
99-
100-
101-def guest_exec(name, cmd, timeout=3600):
102- c = wait_qga(name, 60)
103- pid = c.call("guest-exec", path="/bin/sh", arg=["-c", cmd], **{"capture-output": True})["pid"]
104- end = time.monotonic() + timeout
105- while True:
106- st = c.call("guest-exec-status", pid=pid)
107- if st.get("exited"):
108- break
109- if time.monotonic() > end:
110- sys.exit(f"guest command timed out: {cmd}")
111- time.sleep(2)
112- c.close()
113- out = base64.b64decode(st.get("out-data", "")).decode(errors="replace")
114- err = base64.b64decode(st.get("err-data", "")).decode(errors="replace")
115- return st.get("exitcode", 1), out, err
116-
117-
118-def guest_put(name, data: bytes, dst):
119- c = wait_qga(name, 60)
120- h = c.call("guest-file-open", path=dst, mode="w")
121- for i in range(0, len(data), 48 * 1024):
122- c.call("guest-file-write", handle=h, **{"buf-b64": base64.b64encode(data[i:i + 48 * 1024]).decode()})
123- c.call("guest-file-close", handle=h)
124- c.close()
125-
126-
12776 # ---------- QEMU ----------
12877
12978 def ssh_port(name):
13079 return 22000 + (sum(name.encode()) % 1000)
13180
13281
133-def boot(name, disk, mem_mb=8192, cpus=8, cdrom=None):
82+def boot(name, disk, mem_mb=8192, cpus=8, seed=None):
13483 for k in ("qmp", "qga", "vnc", "pid"):
13584 Path(sock(name, k)).unlink(missing_ok=True)
13685 args = [
137- "qemu-system-x86_64", "-name", name, "-enable-kvm", "-machine", "q35", "-cpu", "host",
138- "-smp", str(cpus), "-m", str(mem_mb),
139- "-drive", f"file={disk},if=virtio,format=qcow2,discard=unmap,cache=unsafe" if cdrom else
140- f"file={disk},if=virtio,format=qcow2,discard=unmap",
86+ f"qemu-system-{'aarch64' if ARM else 'x86_64'}", "-name", name, "-accel", "hvf" if sys.platform == "darwin" else "kvm",
87+ "-machine", "virt" if ARM else "q35", "-cpu", "host", "-smp", str(cpus), "-m", str(mem_mb),
88+ *(["-bios", "edk2-aarch64-code.fd"] if ARM else []),
89+ "-drive", f"file={disk},if=virtio,format=qcow2,discard=unmap",
14190 "-netdev", f"user,id=n0,hostfwd=tcp:127.0.0.1:{ssh_port(name)}-:22", "-device", "virtio-net-pci,netdev=n0",
14291 "-device", "virtio-balloon-pci,free-page-reporting=on",
14392 "-device", "virtio-serial-pci",
14493 "-chardev", f"socket,path={sock(name, 'qga')},server=on,wait=off,id=qga0",
14594 "-device", "virtserialport,chardev=qga0,name=org.qemu.guest_agent.0",
14695 "-qmp", f"unix:{sock(name, 'qmp')},server=on,wait=off",
147- "-vga", "virtio", "-display", "none", "-vnc", f"unix:{sock(name, 'vnc')}",
96+ *(["-device", "virtio-gpu-pci"] if ARM else ["-vga", "virtio"]), "-display", "none", "-vnc", f"unix:{sock(name, 'vnc')}",
14897 "-device", "qemu-xhci", "-device", "usb-tablet",
14998 "-pidfile", sock(name, "pid"), "-daemonize",
15099 ]
151- if cdrom:
152- args += ["-cdrom", str(cdrom), "-boot", "order=d"]
100+ if seed:
101+ args += ["-smbios", f"type=1,serial=ds=nocloud;s={seed}"]
153102 subprocess.run(args, check=True)
154- return int(Path(sock(name, "pid")).read_text())
155103
156104
157105 def ssh(name, *cmd, check=True, timeout=None):
@@ -175,10 +123,8 @@ def wait_ssh(name, secs=300):
175123
176124 def poweroff(name, secs=120):
177125 try:
178- c = qga(name, 5)
179- c.s.sendall(b'{"execute":"guest-shutdown","arguments":{"mode":"powerdown"}}\n')
180- c.close()
181- except OSError:
126+ qmp(name).call("system_powerdown")
127+ except (OSError, RuntimeError):
182128 pass
183129 pid_file = Path(sock(name, "pid"))
184130 end = time.monotonic() + secs
@@ -199,30 +145,20 @@ def poweroff(name, secs=120):
199145
200146 # ---------- bake ----------
201147
202-INSTALLER_SETTINGS = {
203- "install_type": "simple", "headless_mode": True, "device": "/dev/vda", "fs_name": "ext4",
204- "partitions": [{"name": "/dev/vda1", "mountpoint": "/", "size": "100%", "type": "root"}],
205- "hostname": "conveyor-base", "locale": "en_US.UTF-8", "xkbmap": "us", "timezone": "UTC",
206- "user_name": USER, "user_pass": PASS, "user_shell": "/bin/bash", "root_pass": PASS,
207- "kernel": "linux-cachyos", "desktop": "xfce", "bootloader": "grub", "hw_clock": "utc",
208- "carry_network": True, "os_prober": False, "hostcache": True, "autologin": True,
209- "net_profiles_path": "file:///root/net-profiles.toml",
210-}
211-
212148 PROVISION = f"""#!/bin/bash
213149 set -euo pipefail
214-pacman -Syyuu --noconfirm
215-pacman -S --needed --noconfirm {' '.join(DEV_PKGS + DE_PKGS + XORG_PKGS)}
216-systemctl enable sshd.service lightdm.service qemu-guest-agent.service
217-command -v ufw >/dev/null && ufw allow 22/tcp || true
218-groupadd -f autologin
219-gpasswd -a {USER} autologin
150+export DEBIAN_FRONTEND=noninteractive
151+apt-get update
152+apt-get -y full-upgrade
153+apt-get install -y {' '.join(DEV_PKGS + DE_PKGS + XORG_PKGS)}
154+# The cloud kernel has no GPU driver, and so no desktop: swap it for the generic one.
155+apt-get install -y linux-image-$(dpkg --print-architecture)
156+apt-get purge -y linux-image-cloud-$(dpkg --print-architecture) 'linux-image-*-cloud-*'
157+systemctl enable lightdm.service qemu-guest-agent.service
158+systemctl set-default graphical.target
220159 install -d /etc/lightdm/lightdm.conf.d
221160 printf '%s\\n' '[Seat:*]' 'autologin-user={USER}' 'autologin-user-timeout=0' 'autologin-session=xfce' > /etc/lightdm/lightdm.conf.d/50-autologin.conf
222-usermod -aG wheel {USER}
223161 systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
224-install -d -o {USER} -g {USER} -m 700 /home/{USER}/.ssh
225-install -o {USER} -g {USER} -m 600 /root/host_key.pub /home/{USER}/.ssh/authorized_keys
226162 git clone --depth 1 https://github.com/sacenox/dotfiles /tmp/dotfiles
227163 cp -a /tmp/dotfiles/. /home/{USER}/
228164 rm -rf /home/{USER}/.git /home/{USER}/README.md
@@ -238,64 +174,78 @@ cat > /home/{USER}/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-power-manager.
238174 XML
239175 chown -R {USER}:{USER} /home/{USER}
240176 runuser -u {USER} -- env HOME=/home/{USER} npm config set prefix /home/{USER}/.local
177+runuser -u {USER} -- env HOME=/home/{USER} bash -c 'curl -fsSL https://claude.ai/install.sh | bash'
241178 # A restored snapshot can leave a stale forwarded socket behind; let a new session replace it.
242-printf 'StreamLocalBindUnlink yes\n' > /etc/ssh/sshd_config.d/50-conveyor.conf
243-# No welcome app in a worker VM.
244-rm -f /etc/xdg/autostart/cachyos-hello.desktop /home/{USER}/.config/autostart/cachyos-hello.desktop
245-# Every overlay must get its own machine id and ssh host keys at first boot.
246-rm -f /etc/ssh/ssh_host_*
247-: > /etc/machine-id
179+printf 'StreamLocalBindUnlink yes\\n' > /etc/ssh/sshd_config.d/50-conveyor.conf
180+# Every overlay gets its own ssh host keys at first boot: Debian's sshd won't start without them.
181+install -d /etc/systemd/system/ssh.service.d
182+printf '%s\\n' '[Service]' 'ExecStartPre=' 'ExecStartPre=/usr/bin/ssh-keygen -A' 'ExecStartPre=/usr/sbin/sshd -t' > /etc/systemd/system/ssh.service.d/keygen.conf
183+# The seed is gone after the bake: cloud-init must not run again.
184+touch /etc/cloud/cloud-init.disabled
248185 """
249186
250187
188+def serve_seed():
189+ """cloud-init's NoCloud seed over HTTP: the guest reaches the host's loopback at 10.0.2.2."""
190+ files = {"/meta-data": b"instance-id: conveyor-base\nlocal-hostname: conveyor-base\n", "/vendor-data": b"",
191+ "/user-data": b"#cloud-config\n" + json.dumps({
192+ "users": [{"name": USER, "groups": ["sudo"], "shell": "/bin/bash", "lock_passwd": False,
193+ "plain_text_passwd": PASS, "ssh_authorized_keys": [KEY.with_suffix(".pub").read_text().strip()]}],
194+ "write_files": [{"path": "/root/provision.sh", "permissions": "0700", "content": PROVISION}],
195+ "runcmd": [["sh", "-c", "/root/provision.sh > /var/log/provision.log 2>&1 && touch /var/log/provision.ok"]],
196+ }).encode()}
197+
198+ class Seed(http.server.BaseHTTPRequestHandler):
199+ def do_GET(self):
200+ body = files.get(self.path)
201+ self.send_response(200 if body is not None else 404)
202+ self.end_headers()
203+ self.wfile.write(body or b"")
204+
205+ def log_message(self, *a):
206+ pass
207+
208+ srv = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Seed)
209+ threading.Thread(target=srv.serve_forever, daemon=True).start()
210+ return f"http://10.0.2.2:{srv.server_port}/"
211+
212+
251213 def bake():
252214 if BASE.exists():
253215 sys.exit(f"{BASE} exists. Delete it to bake again.")
254- if not ISO:
255- sys.exit("no ~/s/cachyos-desktop-linux*.iso")
256216 BASE.parent.mkdir(parents=True, exist_ok=True)
217+ if not CLOUD.exists():
218+ log(f"downloading {CLOUD_URL}")
219+ urllib.request.urlretrieve(CLOUD_URL, CLOUD.with_suffix(".part"))
220+ CLOUD.with_suffix(".part").rename(CLOUD)
257221 if not KEY.exists():
258- subprocess.run(["ssh-keygen", "-q", "-t", "ed25519", "-N", "", "-C", "conveyor-spike", "-f", str(KEY)], check=True)
222+ subprocess.run(["ssh-keygen", "-q", "-t", "ed25519", "-N", "", "-C", "conveyor", "-f", str(KEY)], check=True)
259223 tmp = BASE.with_suffix(".baking.qcow2")
260- tmp.unlink(missing_ok=True)
261- subprocess.run(["qemu-img", "create", "-q", "-f", "qcow2", str(tmp), "60G"], check=True)
224+ subprocess.run(["qemu-img", "convert", "-q", "-O", "qcow2", str(CLOUD), str(tmp)], check=True)
225+ subprocess.run(["qemu-img", "resize", "-q", str(tmp), "60G"], check=True)
262226 t0 = time.monotonic()
263- log(f"booting {ISO.name}")
264- boot("bake", tmp, 8192, 8, cdrom=ISO)
265- wait_qga("bake", 600).close()
266- log(f"live environment up after {time.monotonic() - t0:.0f} s")
267- guest_put("bake", json.dumps(INSTALLER_SETTINGS).encode(), "/root/settings.json")
268- profiles = "[desktop.xfce]\npackages = [\n" + ",\n".join(f' "{p}"' for p in DE_PKGS) + "\n]\n"
269- guest_put("bake", profiles.encode(), "/root/net-profiles.toml")
270- log("running cachyos-installer")
271- rc, out, err = guest_exec("bake", "cachyos-installer --config /root/settings.json > /root/install.log 2>&1; rc=$?; tail -n 30 /root/install.log; exit $rc")
272- if rc:
273- sys.exit(f"installer failed ({rc}):\n{out}{err}")
274- log(f"installed after {time.monotonic() - t0:.0f} s; provisioning")
275- guest_put("bake", PROVISION.encode(), "/root/provision.sh")
276- guest_put("bake", KEY.with_suffix(".pub").read_bytes(), "/root/host_key.pub")
277- # The host's repos: the installer leaves the v3 ones out, so the upgrade would downgrade it all to generic builds.
278- guest_put("bake", Path("/etc/pacman.conf").read_bytes(), "/root/pacman.conf")
279- rc, out, err = guest_exec("bake", "mount /dev/vda1 /mnt && install -m700 /root/provision.sh /root/host_key.pub /mnt/root/ "
280- "&& install -m644 /root/pacman.conf /mnt/etc/pacman.conf "
281- "&& cp --dereference /etc/resolv.conf /mnt/etc/resolv.conf "
282- "&& arch-chroot /mnt /root/provision.sh > /root/provision.log 2>&1; rc=$?; "
283- "tail -n 40 /root/provision.log; umount -R /mnt 2>/dev/null; sync; exit $rc")
284- if rc:
285- sys.exit(f"provisioning failed ({rc}):\n{out}{err}")
286- log(f"provisioned after {time.monotonic() - t0:.0f} s; powering off")
227+ log(f"booting {CLOUD.name}")
228+ boot("bake", tmp, seed=serve_seed())
229+ if not wait_ssh("bake", 300):
230+ sys.exit("the cloud image does not answer ssh")
231+ log(f"up after {time.monotonic() - t0:.0f} s; provisioning")
232+ r = ssh("bake", "cloud-init status --wait >/dev/null; tail -n 40 /var/log/provision.log; test -e /var/log/provision.ok", check=False)
233+ if r.returncode:
234+ sys.exit(f"provisioning failed:\n{r.stdout or ''}")
235+ log(f"provisioned after {time.monotonic() - t0:.0f} s; rebooting into the desktop")
287236 poweroff("bake")
288- log("first boot from disk, to check it")
289- boot("bake", tmp, 8192, 8)
237+ boot("bake", tmp)
290238 if not wait_ssh("bake", 300):
291239 sys.exit("baked image does not answer ssh")
292- r = ssh("bake", "systemctl is-system-running --wait; pacman -Q claude-code xfce4-session qemu-guest-agent; pgrep -u sacenox xfce4-session", check=False)
240+ r = ssh("bake", "systemctl is-system-running --wait; ~/.local/bin/claude --version; dpkg-query -W xfce4-session qemu-guest-agent; "
241+ "pgrep -u sacenox xfce4-session", check=False)
293242 log("verify:", (r.stdout or "").strip().replace("\n", " | "))
294243 # Rust and a warm cargo cache, so a widget ticket builds in seconds, not minutes.
295244 log("pre-building the widget library")
296245 # In ~/work, where agents build: cargo fingerprints workspace crates by path.
297- tar = subprocess.run(["tar", "-C", str(REPO / "templates"), "--exclude=library/target", "-cf", "-", "library"],
298- capture_output=True, check=True).stdout
246+ # Without macOS metadata: its ._* files would read as widgets.
247+ tar = subprocess.run(["tar", "--no-xattrs", "-C", str(REPO / "templates"), "--exclude=library/target", "-cf", "-", "library"],
248+ capture_output=True, check=True, env={**os.environ, "COPYFILE_DISABLE": "1"}).stdout
299249 subprocess.run(["ssh", "-i", str(KEY), "-p", str(ssh_port("bake")), "-o", "BatchMode=yes", "-o", "StrictHostKeyChecking=no",
300250 "-o", "UserKnownHostsFile=/dev/null", "-o", "LogLevel=ERROR", f"{USER}@127.0.0.1", "tar -xf - -C /tmp && mv /tmp/library ~/work"], input=tar, check=True)
301251 r = ssh("bake", "rustup default 1.99.1 >/dev/null 2>&1 && cd ~/work && CARGO_TARGET_DIR=$HOME/.cache/conveyor-target "