This is a demo of building bootable NixOS disk images that work on multiple architectures. In principle, this works on all UEFI platforms. For now, we use the following well supported platforms in NixOS:
- Intel/AMD
x86_64 - ARM
aarch64 - RISC-V
riscv64
We will build one disk image that boots on all these platforms.
Just build the default package via:
$ nix buildAs this cross-compiles code for aarch64 and riscv64, which is usually not found in cache.nixos.org, this will take a while. You can use nom to see what's going on:
$ nom buildWhen this process is done, you will have a disk image in /result/boot-volume.raw.
You can use any VMM that supports UEFI to run these. They should also run on real hardware (not tested!). For convenience, I've included the necessary Qemu magic in the shell environment:
$ nix develop
$ qemu-efi riscv64 result/boot-volume.raw # or x86_64 or aarch64We build UKIs for each architecture and put them into their default locations on the UEFI System Partition. These default locations are architecture-dependent.
Each UKI refers to a different NixOS top-level store path. We take all of those and their transitive closure and pack them into one big compressed read-only partition that eventually is mounted at /nix/store. So each architecture uses the same store and we save some bits compared to packing them all individually.
Of course, there are limitations. For now, all architectures share the same /var. This is probably a bad idea for any serious use, because programs might not share a compatible data format between architectures.