2023-07-15 17:15:38 +00:00
|
|
|
# This is a test utility that automatically formats
|
|
|
|
# `config.virtualisation.rootDevice` in the initrd.
|
|
|
|
# Note that when you are using
|
|
|
|
# `boot.initrd.systemd.enable = true`, you can use
|
|
|
|
# `virtualisation.fileSystems."/".autoFormat = true;`
|
|
|
|
# instead.
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
{ lib, config, pkgs, ... }:
|
2023-07-15 17:15:38 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
rootDevice = config.virtualisation.rootDevice;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
boot.initrd.extraUtilsCommands = lib.mkIf (!config.boot.initrd.systemd.enable) ''
|
2023-07-15 17:15:38 +00:00
|
|
|
# We need mke2fs in the initrd.
|
|
|
|
copy_bin_and_libs ${pkgs.e2fsprogs}/bin/mke2fs
|
|
|
|
'';
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
boot.initrd.postDeviceCommands = lib.mkIf (!config.boot.initrd.systemd.enable) ''
|
2023-07-15 17:15:38 +00:00
|
|
|
# If the disk image appears to be empty, run mke2fs to
|
|
|
|
# initialise.
|
|
|
|
FSTYPE=$(blkid -o value -s TYPE ${rootDevice} || true)
|
|
|
|
PARTTYPE=$(blkid -o value -s PTTYPE ${rootDevice} || true)
|
|
|
|
if test -z "$FSTYPE" -a -z "$PARTTYPE"; then
|
|
|
|
mke2fs -t ext4 ${rootDevice}
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
}
|