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;`
8 { lib, config, pkgs, ... }:
11 rootDevice = config.virtualisation.rootDevice;
15 boot.initrd.extraUtilsCommands = lib.mkIf (!config.boot.initrd.systemd.enable) ''
16 # We need mke2fs in the initrd.
17 copy_bin_and_libs ${pkgs.e2fsprogs}/bin/mke2fs
20 boot.initrd.postDeviceCommands = lib.mkIf (!config.boot.initrd.systemd.enable) ''
21 # If the disk image appears to be empty, run mke2fs to
23 FSTYPE=$(blkid -o value -s TYPE ${rootDevice} || true)
24 PARTTYPE=$(blkid -o value -s PTTYPE ${rootDevice} || true)
25 if test -z "$FSTYPE" -a -z "$PARTTYPE"; then
26 mke2fs -t ext4 ${rootDevice}