aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs
Commit message (Collapse)AuthorAgeFilesLines
* layers/console.nix: a shell on the serial console, to import into a layertv6 days1-5/+3
| | | | | | | | | | | | | | | Since the base system turned off the console (and with it kbd), it had no getty at all: NixOS's gettys come with the console (services/ttys/getty.nix), so there was no shell on ttyS0 any more, only the kernel's and systemd's messages, and ssh. That stays the default, and the base system's console.enable is only that now, a default, for layers/console.nix: the console, with root logged in on ttyS0 (a default, too: services.getty.autologinUser can name another user, or be null for a login prompt), but no getty on tty1, and no systemd-vconsole-setup, which moved there from the base system, like the autologin. It's small, so the README has it imported into another layer, rather than as a layer, with an image, of its own, which works, too.
* run-firecracker-vm: no console, fontconfig, su xauth, hwdb, shutdown ramfstv6 days1-1/+13
| | | | | | | | | | | | The guest has no screen, no X, and no hardware to tell apart but virtio, so the base system leaves out kbd and systemd-vconsole-setup (console.enable; the unit doesn't need disabling any more), fontconfig and freetype, su's xauth with libX11 & co. (which shadow.nix turns on, not as a default), and udev's hardware database (14M). And there's nothing to unmount from a ramfs at shutdown: / is a tmpfs, and the store's images are read-only; systemd-shutdown remounts what's still busy, like the rw-store, read-only. About 30M less in the base image, and a service less at every shutdown.
* run-firecracker-vm: no initrds in the imagestv6 days1-2/+8
| | | | | | | | Each layer's system links its own initrd, so each layer's image had one, 19 to 25M, but the guest never reads any of them: Firecracker gets the initrd from the host. Now the images leave all of the systems' initrds out; with nix, the top system's is still in the host's store, where the registration says it is.
* host: static addresses for VMs, by name, on whichever tap they runtv6 days1-13/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A VM got the first free tap of its user's, and a tap's address came from its number, so a VM's address depended on what else ran, and on the users before it, and a reverse proxy on the host could only guess it (172.16.0.2, i.e. fctap0, for hermes). Now addresses are the VMs': the host module takes vms, VM name -> user and address (vms = { hermes = { user = "tv"; ip = "172.16.0.2"; }; }), any number of them, and a VM takes any free tap of its user's, which gets its address while it runs, so at most as many run at the same time as the user has taps. Taps have addresses of their own, for VMs without one: from 172.16.0.200 on, so they stand out (but for VMs' there). The MAC address, which dnsmasq hands out every address by, is 06:00 and the address (06:00:ac:10:00:02 for 172.16.0.2), and with it the IPv6 addresses; the run script takes the VM's from /etc/fc-vms, or the tap's own from /etc/fc-taps. The VMs' addresses are also in config.fc.vms.NAME (user, ip, ip6), for the host's configuration, e.g. proxyPass = "http://${config.fc.vms.hermes.ip}:9120"; Which address a tap has is up to fcbr0-firewall, which now also runs when a tap's VM's name (/run/fc-egress/TAP.name, which the run script writes) changes: the VM's, if it's one of the tap's user's in vms and on none of their other taps, too, else the tap's own. It puts it into the tap's new nftables sets addr_TAP and addr6_TAP, in the bridge's table, which lets the tap send from nothing else (instead of the static set guests), and in the other, whose per-tap rules go by them (instead of the tap's fixed addresses); and into /run/fcbr0-addr, ADDRESS: TAP and TAP: ADDRESS, where egress.lua finds a guest's tap (as long as both agree, and the address and the tap are the same user's), and the run script waits for its address before starting the guest. fc-egress vms shows the taps' addresses, too.
* run-firecracker-vm: nix as a layer, a read-only store without ittv6 days1-162/+121
| | | | | | | | | | | | | | | | | | | | | | | | The base system had nix, the nix-daemon, the host's store and nixpkgs via 9P, and a writable store on a drive, a scratch file without --store. Now all of that is in a layer of its own, layers/nix.nix, and the base system has neither nix nor nix-daemon in its closure: its store is its images, read-only, an overlay of them, or with a single image, the image itself, as overlayfs needs at least two lower layers without an upper one. This can become the base layer for guests that only run services. As a layer, nix gets an image of its own: put first, it's the same for all guests with nix, instead of in the image of whichever layer wants nix. It sets fc.nix, which the run script goes by, and nix.enable; setting nix.enable without it fails an assertion, as the run script wouldn't give the guest the drive for its store. The image decides, so the run script checks that the options fit it: a guest with nix requires --store (no more scratch store), and one without refuses --store, --store-size, --nixpkgs and --nixpkgs-cache. Without the rw-store drive, the images come first, and home after them; the store and nixpkgs aren't served, there's no fc.registration, and the initrd doesn't mount anything via 9P. The run script now waits for each of the 9P servers it starts, not only the store's.
* run-firecracker-vm: fc.home.required, for layers with state in /hometv6 days1-1/+17
| | | | | | | A layer that keeps its state in /home can set fc.home.required, and the run script then refuses to start the guest without --home, instead of booting with /home on the tmpfs, where the state is gone when the guest exits.
* run-firecracker-vm: fc-ssh-host-key without default dependenciestv6 days1-2/+7
| | | | | | | | | Being before sshd.socket made an ordering cycle: a service is after basic.target by default, which is after sockets.target, which is after sshd.socket. systemd broke it by dropping fc-ssh-host-key, so sshd had no host key and closed every connection. Now fc-ssh-host-key runs early, without default dependencies (but before shutdown.target and in conflict with it), and makes its mount point under /run.
* run-firecracker-vm: start fc-ssh-host-key at boot, before sshdtv6 days1-17/+31
| | | | | | | | | | | | | | | fc-ssh-host-key only ran on the first connection, as a requirement of the socket-activated sshd@ instance, and without startWhenNeeded not at all, so NixOS generated a random host key instead. Now it's required by, and runs before, whichever of sshd.socket or sshd.service is in use, startWhenNeeded is only a default (a layer can turn it off), and NixOS doesn't generate host keys. The run script now also deals with the key first thing, before starting any servers: it may be a pipe (<(...)), so it's read once, for the copy; a missing final newline gets added (sshd refuses the key without); and ssh-keygen -y checks it's a key without passphrase, so a bad one stops the run script right away rather than every connection.
* run-firecracker-vm: sshd, with a host key from the hosttv6 days1-3/+44
| | | | | | | | | | | | The guests run sshd, started on demand, with an ed25519 host key that isn't in the store: the run script takes it from --ssh-host-key FILE, by default ~/.local/share/run-firecracker-vm/ssh_host_ed25519_key, created on first use, so a user's guests share one key and one known_hosts line covers them (see README.md), and serves a copy from its private temporary directory via 9P on vsock port 567. In the guest, fc-ssh-host-key copies it to /run/ssh (0600) before sshd starts, and unmounts the share again. Who may log in is up to a layer (users.users.<name>.openssh.authorizedKeys).
* run-firecracker-vm: --vcpus Ntv6 days1-10/+19
| | | | | | | The guest's number of CPUs, default 2 as before, 1 to 32 (Firecracker's range). jq sets it in the config, along with --mem-size (instead of the quoted placeholder sed replaced) and dropping the home drive without --home, as before.
* host: IPv6 for the guests' tcp:// and udp:// rulestv6 days1-0/+6
| | | | | | | | | | | | | | | | | The guests get IPv6: fcbr0 has fdfc:fc::1/64 (module argument prefix6), the host's dnsmasq sends router advertisements, and each guest takes the address from its MAC (SLAAC with EUI-64; the guest's networkd is set up for that, without privacy addresses), so the host knows each tap's address, as with IPv4. The rules take IPv6 addresses in brackets, tcp://[42::1]:22 or udp://[42::/16]:5000-5100, and names now resolve to both families (and get AAAA records for the guests). Forwarded connections get NATed to the host's address, like IPv4. Like IPv4 everything else is refused: the bridge only lets a tap send from its own addresses (or :: for duplicate address detection), the host only answers neighbour and router discovery, denyDestinations and the per-guest limits apply. HTTPS stays IPv4, through the proxy: IPv6 port 443 is refused.
* run-firecracker-vm: pass host's pkgstv7 days1-0/+4
|
* run-firecracker-vm: name layer images after their filestv7 days1-1/+12
| | | | | | A layer's image is now firecracker-layer-K-NAME.img, NAME being the layer's file name without .nix (or, for .../NAME/default.nix, NAME). Layers that aren't files, and the base system, keep just the number.
* run-firecracker-vm: add --mem-sizetv7 days1-2/+11
| | | | | | | The guest's memory was fixed at 1024 MiB, which hermes, its gateway and a claude process or two outgrow. --mem-size MIB sets it, default 1024. The config gets it like the other per-run values, from a placeholder, here a quoted one, replaced by the bare number.
* drop rw-store paths that a lower layer has, before mounting the storetv7 days1-2/+31
| | | | | | | | | | | | | | | | nix in the guest deletes a path in the store that isn't in its database before it adds it, like any of the host's store's paths, which aren't registered. On the overlay, that leaves a whiteout in the rw-store, or an opaque directory with what nix adds again, if it gets that far. With a persistent rw-store, that hides the path from every later boot, from images that have it, too: a hermes layer's setup failed with exit 255, as python3's binary wrapper couldn't exec the python the rw-store hid. A path that a lower layer has is complete there, and the same as anything of that name in the rw-store. So drop such paths from the rw-store in the initrd, before sysroot-nix-store.mount; what's left is what only the guest added.
* run-firecracker-vm: no /home disk without --hometv7 days1-24/+43
| | | | | | | | | Without --home, /home is now simply part of the guest's root file system (a tmpfs, gone when it exits, as before), instead of a scratch disk. With --home, the disk is attached after the images, and the run script puts fc.home on the kernel command line, which makes a small generator in the guest mount it, so a guest without it doesn't wait for a drive that isn't there. The images are back at vdb, vdc, ...
* run-firecracker-vm: /home on a disk of its own, --hometv7 days1-19/+45
| | | | | | | | | | /home is now on its own disk: a scratch file, removed when the guest exits, or with --home FILE, one that persists (created if it doesn't exist, sparse, --home-size, default 16G), handled like the store's (--store), and also locked against use by two VMs. Separate from the store, so either can be kept or thrown away. The images move one drive up (vdc, vdd, ...).
* run-firecracker-vm: store layerstv7 days1-30/+53
| | | | | | | | | | | | | | | The new argument layers is a list of NixOS modules, each a layer on top of the ones before, the first on top of the base system. The guest runs the top layer's system. Each layer gets its own erofs image with only the store paths of its system's closure that the layers below don't have, so the base image (and those of layers below) stays the same whatever goes on top: nix-build pkgs/run-firecracker-vm --arg layers '[ ./my-service.nix ]' The images become read-only drives, mounted as overlay lower layers (with the host store below them, as before). The writable store disk is now the first drive (/dev/vda), the images follow (vdb, vdc, ...).
* run-firecracker-vm: --egress defaults to the VM's nametv10 days1-3/+4
| | | | | | A named VM uses the list of the same name unless given another with --egress; without a name, still the list default. A missing list means no egress (with a warning), as before; there's no fallback to default.
* run-firecracker-vm --nametv10 days1-4/+27
| | | | | | | | | | | | | | A VM can now have a name: run-firecracker-vm --name NAME. It's unique among the user's running VMs (a lock in the user's runtime directory, like the taps'), becomes the guest's host name (systemd.hostname= on the kernel command line), and goes to /run/fc-egress/TAP.name while the VM runs, for fc-egress. Names are letters, digits and -, and can't look like a tap's. fc-egress takes a running VM's name or tap where it takes a VM: -v VM works on the list the VM uses, use VM LIST switches it to another list, and vms shows tap, name and list. The logs keep saying taps (fc-egress vms maps them).
* per-VM egress whiteliststv10 days1-3/+23
| | | | | | | | | | | | | | | | | | | | | | | | Whitelists are now named, any number per user, in /var/lib/fc-egress/USER/LIST, and each VM uses one of them: run-firecracker-vm --egress LIST (default: default). The run script writes the list's name to /run/fc-egress/TAP when it takes the tap, and empties it when the VM exits; a list that doesn't exist allows nothing. A user's VMs can only use that user's lists. So the unit of policy is the tap (i.e. the running VM) rather than the user: nftables sets allow_TAP, nginx decrypt sockets decrypt-TAP.sock, egress_taps.lua maps guest addresses to tap and user. fcbr0-firewall updates a tap when its file in /run/fc-egress changes, and all of a user's taps when anything in the user's directory does. nginx's connection limit stays per user. fc-egress takes -l LIST (default: default), and has new commands lists and vms (running VMs' taps and their lists). Log lines now say user, tap and (nginx's) list: "ALLOW|DENY USER TAP LIST ...", kernel: "fc-egress ALLOW|DENY USER TAP". The old rules file, /var/lib/fc-egress/USER/allowed, is now just a list named "allowed"; rename it to "default" to keep using it.
* host: harden against users turning on the host or each othertv10 days1-1/+8
| | | | | | | | | | | | | | | | | | - denyDestinations (default: loopback, private, link-local, CGNAT, multicast, ...): no user's rules can open those, neither tcp:// and udp:// rules nor the proxy, whatever a name resolves to: nginx's own outgoing connections may only go to port 443 outside them, and not to the host. tcp:// rules no longer open anything on the host itself. - fcbr0-firewall no longer runs as root, but with only CAP_NET_ADMIN, doesn't follow symlinks, and gets started per user when that user's rules change, so one user can't stop the others' updates. Rules files are read up to 64k only, by egress.lua, too. - Limits per guest (maxConnections open, maxNewConnections per second), and per user in nginx, so one user can't starve the others. - tcp:// and udp:// connections, and refused ones, get logged (rate-limited) with the user; fc-egress log shows them. - The run script keeps its lock files in a directory of the user's own, not in /tmp, where others could take them first.
* per-user egress rulestv10 days1-4/+6
| | | | | | | | | | | | | The host module takes users = { NAME = TAPS; ... } instead of a single user: each user gets that many taps, and rules of their own, in /var/lib/fc-egress/USER/allowed, managed with fc-egress as before. The proxy tells whose a guest is by its address: each tap has a fixed one, handed out by dnsmasq by MAC address (derived from the tap's number, as the run script does), and the bridge drops anything a guest sends from another address. The decrypting server gets a socket per user, as it can't see the guest's address. The run script only takes the user's own taps.
* add --nixpkgs-cache MODEtv10 days1-10/+28
| | | | | | | | | | /nixpkgs isn't cached in the guest, so changes to a checkout show up right away, but evaluating is slow. --nixpkgs-cache sets 9P's cache mode for it, e.g. loose, which made evaluating tmux several times faster. It gets passed on the kernel command line as fc.9p566=cache=MODE, and mount.vsock9p appends such options for the port it mounts. Options also take the --option=value form now.
* serve nixpkgs to the guest via 9P instead of from the storetv10 days1-27/+30
| | | | | | | | | A <nixpkgs> outside the store got copied (i.e. hashed) to the store on every evaluation, for the guest's NIX_PATH, so no-op builds still took ~25s with a checkout. Now a third 9P server serves nixpkgs from wherever it is, read-only, at /nixpkgs in the guest, which NIX_PATH points to. It's in neither the closure nor the registration any more, and run-firecracker-vm --nixpkgs DIR can serve another one.
* don't hash nixpkgs on every evaluationtv10 days1-3/+7
| | | | | | | "${pkgs.path}" copies nixpkgs to the store, which means hashing all of it, on every evaluation, even when it's a store path already. That took no-op builds from ~3s to ~25s. Use builtins.storePath when it's a store path; only a nixpkgs outside the store still gets copied.
* move the host module to modules/hosttv10 days1-5/+5
| | | | | egress.lua goes along. The host now imports it as (import .../modules/host { user = ...; }).
* move the runner to pkgs/run-firecracker-vmtv10 days2-0/+433
So default.nix (or shell.nix, flake.nix) at the top can become something else. kernel.nix goes along, as it's only an argument of the runner.