1 # This is a test utility that automatically formats
2 # `config.virtualisation.rootDevice` in the initrd.
3 # Note that when you are using
4 # `boot.initrd.systemd.enable = true`, you can use
5 # `virtualisation.fileSystems."/".autoFormat = true;`
16 rootDevice = config.virtualisation.rootDevice;
20 boot.initrd.extraUtilsCommands = lib.mkIf (!config.boot.initrd.systemd.enable) ''
21 # We need mke2fs in the initrd.
22 copy_bin_and_libs ${pkgs.e2fsprogs}/bin/mke2fs
25 boot.initrd.postDeviceCommands = lib.mkIf (!config.boot.initrd.systemd.enable) ''
26 # If the disk image appears to be empty, run mke2fs to
28 FSTYPE=$(blkid -o value -s TYPE ${rootDevice} || true)
29 PARTTYPE=$(blkid -o value -s PTTYPE ${rootDevice} || true)
30 if test -z "$FSTYPE" -a -z "$PARTTYPE"; then
31 mke2fs -t ext4 ${rootDevice}