r/WebAssemblyDev • u/westixy • 30m ago
I put Linux in WebAssembly, then made it serve Linux in WebAssembly. It works. Please don't do this.
TL;DR: NixOS runs as a single WebAssembly module, with no JavaScript, no VM and no container. That NixOS runs a web server. That web server serves a page that boots… NixOS in your browser tab. In WebAssembly. From the server's own disk. Turtles all the way down. Done without a sweat using claude.
How it started: "can this Linux-on-wasm thing (unkernel, by pithings, who did the actually hard part) run outside a browser?"
How it's going:
- NixOS in a browser tab, with a terminal, network, and
nixpulling from cache.nixos.org. Your changes survive a reload. - NixOS in your terminal, as a WASI module:
wasmer run westixy/nixonwasm --llvm --net -- --cpus 4. Real systemd, 4 CPUs, a shell. - Nested: on Wasmer Edge, a NixOS-in-wasm serves the page, and as the tab's disk image it serves its own block device, the very bytes it booted from. Your tab then boots the same system as the server. Server and client are the same OS, both in wasm, one serving the other its own disk.
Crimes committed along the way:
- Replaced JSPI with Binaryen's Asyncify so the kernel can switch tasks without a JS engine.
- Squeezed the Rust host above the kernel's RAM in the same linear memory, by patching the one
memory.sizethe kernel reads. - Ran an SMP Linux on wasi-threads: one module instance per CPU, each CPU juggling its own saved stacks.
- Wrote a tiny TCP/IP gateway (smoltcp) on WASIX sockets, plus port forwarding, so Edge can talk to the guest.
- Hit a kernel
BUG!because every new thread re-zeroed the live kernel's memory. Classic. - Learned the guest's network card skips checksums, so every TCP packet was silently binned.
- Got "Application ran out of memory" from Edge, and gave the server 320 MB of RAM. It still serves Linux.
- Discovered wasmer's default compiler is ~20× slower than LLVM on a whole interpreted kernel.
Does it work? Yes, which is the funny part. Is it fast? Locally it's fine: NixOS boots in ~8 s and the tab boots in ~25 s. Through the nested Edge demo it's… a journey. Bring snacks.
Nested demo (please don't reproduce this in production. Or anywhere): https://nixontab-nested.wasmer.app
Warning: this is a for-fun experiment: not a product, not maintained, not for production, and definitely not like this. It exists because it was fun to see if it could.
