This was born as an experiment to see if I could bootstrap a full NixOS system basically from nothing with a static build of nix and hey, you can! So I've automated it with guestfish. As how it's configured, this will install a BIOS-bootable virtio installation of NixOS for QEMU into the provided disk image.
This thing is pretty much an experiment, so use it at your own risk!
You need:
- guestfish (of course): use the package provided by your distro or use the example Dockerfile for more isolation!
WARNING: guestfish will try to use KVM acceleration for its VM or it will fallback to tcg and it will be pretty slow. If you use the container be sure to share the
/dev/kvmdevice to the container with the correct privileges. Also, the container uses an unprivileged user.
- a static build of Nix: you can get it from the NixOS CI system here. Download it, rename it to 'nix_static' and place it into this folder (check the SHA256 of the binary for bonus security points).
- the disk image: create a QCOW2 disk image called "nixos.qcow2" in this folder.
- the desired system configuration for the image: place it under the
etc/nixosfolder of this repo. By default it looks for a nixosConfiguration called "nixos" to build.
An example of a system configuration is already in the
etc/nixosfolder to start experimenting.
Well, now you can look at the beginning of the guestfish.script file: there are some tunable parameters (for example, logging, num of vcpus, memory, ...) you can set.
Now just run:
guestfish -f guestfish.script
and wait it for complete. At the end, the disk nixos.qcow2 will contain the NixOS system ready to use, with your configuration!