$ nix-build -A rootfs

The rootfs derivation, defined as, creates a squashfs image. It contains the closures of toplevel and a registration file.

The rootfs is also available as an ext4 image.

To explore the result, we can extract the content of the rootfs in a temporary directory as follow:

$ mkdir tmp ; cd tmp
$ unsquashfs $(readlink -fn ../result)
$ find -maxdepth 2

The derivation is defined as a call to nixpkgs/nixos/lib/make-squashfs.nix, passing toplevel as argument. The closure is constructed by nixpkgs/build-support/closure-info.nix.

A call to nix-store --load-db with the registration file found in the rootfs is done in a runit script. I wonder if it could be done directly when the rootfs is mounted.