Just a demo for now. Very dirty code inside; you have been warned!
- QEMU with U-Boot
Requires a properly configured, recent-ish U-Boot that provides a correct device tree, which is... hard to find on real hardware these days. I really hope one day vendors can do this right, but until then we might have to make do with hacky things like /dtbs/${fdtfile}
.
Prepare U-Boot and disk image:
$ nix build -o uboot ".#ubootQemuRiscv64Smode"
$ nix build -o image ".#nixos-image"
$ cp --no-preserve=mode image/efi-image.img .
$ truncate -s 4G efi-image.img # Size to your liking
Boot the image:
qemu-system-riscv64 -M virt -m 2g -nographic -s \
-kernel uboot/u-boot.bin \
-drive id=image,file=efi-image.img,format=raw,if=virtio
A temporary initial configuration (generated on the build system) is used for the first boot. It's easier to do this than to use bootctl
on the 'wrong' architecture and on a disk that doesn't really exist.
Early on during the first boot:
- The root partition is expanded to fill the device
- The Nix database is initialized and the system profile is set to the booted closure
- The 'correct' bootloader configuration is installed with NixOS's systemd-boot configuration generator
From now on the system should behave as a regular NixOS EFI image.
Largely based on the existing sd-image.nix
code.