at 24.05-pre 902 B view raw
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;` 6# instead. 7 8{ lib, config, pkgs, ... }: 9 10let 11 rootDevice = config.virtualisation.rootDevice; 12in 13{ 14 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 18 ''; 19 20 boot.initrd.postDeviceCommands = lib.mkIf (!config.boot.initrd.systemd.enable) '' 21 # If the disk image appears to be empty, run mke2fs to 22 # initialise. 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} 27 fi 28 ''; 29}