not-os
runvm
$ nix-build -A runvm
/nix/store/53hil1l0c4ks7rvayfyn129mqxyw86h4-runvm
runvm is the main derivation of not-os. It is defined in default.nix
. Every other derivation
is a dependency.
The result is (a symlink to) a script calling qemu-kvm with the right parameters, in particular the kernel Ⓐ, the initrd Ⓑ, and the rootfs Ⓒ.
#! ${pkgs.stdenv.shell}
# To use this script, the `live` and `simpleStaticIp` options must be set to
# true.
exec ${pkgs.qemu_kvm}/bin/qemu-kvm \
-name not-os \
-m 512 \
-kernel ${config.system.build.kernel}/bzImage Ⓐ \
-initrd ${config.system.build.initialRamdisk}/initrd Ⓑ \
-drive index=0,id=drive1,file=${config.system.build.squashfs} Ⓒ,
readonly,media=cdrom,format=raw,if=virtio \
-append "console=ttyS0 ${toString config.boot.kernelParams} Ⓓ
quiet panic=-1" \
-device virtio-net,netdev=net0 \
-netdev user,id=net0,net=10.0.2.0/24,host=10.0.2.2,
dns=10.0.2.3,hostfwd=tcp::2222-:22,hostfwd=tcp::9080-:80,hostfwd=tcp::9443-:443 \
-device virtio-rng-pci \
-nographic \
-no-reboot
/nix/store/gsxyxrzgbdkjd14q71w10i82nlyg9nig-runvm.sh
Note: artificial newlines added.
A kernel command line Ⓓ is used to let the stage-1 know about the location of toplevel;
Example execution
Executing the resulting script looks like:
$ ./result
Entering stage-1...
/nix/store/1mq5jkzjcy2g2ypah1b9f848l00m5whq-stage-1
Creating base file systems...
Using /nix/store/w5dbz7ig5s3g0c1xz7aqqs9klghhq4lm-extra-utils...
Using /nix/store/70jf5sm6750jbbsirv6rqihwj22gsbvj-linux-4.14.84-shrunk...
Loading kernel module virtio...
Loading kernel module virtio_pci...
Loading kernel module virtio_net...
Loading kernel module virtio_rng...
Loading kernel module virtio_blk...
Loading kernel module virtio_console...
Loading kernel module dm_mod...
Loading kernel module tun...
Loading kernel module loop...
Loading kernel module squashfs...
Loading kernel module overlay...
Creating writable Nix store...
Switching root filesystem...
Entering stage-2...
/nix/store/w1g8p9zi8apj336xk177q2y6ddcp04nn-stage-2
Creating base file systems...
Using /nix/store/2whzzgy0ivkp6vw3i67w51kf78ij87n4-toplevel...
setting up /etc...
- runit: $Id: 25da3b86f7bed4038b8a039d2f8e8c9bbcf0822b $: booting.
- runit: enter stage: /etc/runit/1
Setting static IP address...
Running ntpdate...
23 Mar 14:20:27 ntpdate[108]: step time server 193.190.253.212 offset -2.542015 sec
- runit: leave stage: /etc/runit/1
- runit: enter stage: /etc/runit/2
Running runsvdir...
Running nix-daemon...
Running sshd...
QEMU: Terminated
You can type ctrl-a x
to quit. You can also enter the
QEMU monitor with ctrl-a c
, then e.g. type
screendump filename.ppm
to capture an image like the one in
the test, then quit
to terminate QEMU.