2020-12-03 12:48:07 +01:00
|
|
|
# Builds a compressed EFI System Partition image
|
2021-04-06 11:10:15 +02:00
|
|
|
{ config, lib, pkgs }:
|
|
|
|
|
2022-04-24 08:35:10 +02:00
|
|
|
let cfg = config.block.partitions;
|
|
|
|
|
|
|
|
in pkgs.stdenv.mkDerivation {
|
2020-12-03 12:48:07 +01:00
|
|
|
name = "boot.qcow2";
|
|
|
|
|
2021-02-06 21:11:39 +01:00
|
|
|
nativeBuildInputs = with pkgs.buildPackages.buildPackages; [
|
|
|
|
qemu_test
|
2020-12-03 12:48:07 +01:00
|
|
|
utillinux
|
|
|
|
zstd
|
|
|
|
];
|
|
|
|
|
2021-04-06 11:10:15 +02:00
|
|
|
disklabel = lib.uuidFrom config.system.nixos.label;
|
2021-03-30 22:39:22 +02:00
|
|
|
|
2020-12-03 12:48:07 +01:00
|
|
|
buildCommand = ''
|
|
|
|
img=./temp.raw
|
|
|
|
|
|
|
|
# Pad the front of the image
|
2021-04-06 11:10:15 +02:00
|
|
|
truncate --size=1M $img
|
2020-12-03 12:48:07 +01:00
|
|
|
|
|
|
|
# Concatentenate the ESP
|
2021-04-06 11:10:15 +02:00
|
|
|
espByteOffset=$(stat --printf='%s' $img)
|
2022-04-24 08:35:10 +02:00
|
|
|
zstdcat ${cfg.esp.image} >> $img
|
2021-04-06 11:10:15 +02:00
|
|
|
truncate --size=%1M $img
|
2020-12-03 12:48:07 +01:00
|
|
|
|
2021-04-06 11:10:15 +02:00
|
|
|
# Concatenate the store
|
|
|
|
storeByteOffset=$(stat --printf='%s' $img)
|
2022-04-24 08:35:10 +02:00
|
|
|
zstdcat ${cfg.store.image} >> $img
|
2021-04-06 11:10:15 +02:00
|
|
|
truncate --size=%1M $img
|
2020-12-03 12:48:07 +01:00
|
|
|
|
|
|
|
# Pad the end of the image
|
2021-04-06 11:10:15 +02:00
|
|
|
truncate --size=+1M $img
|
2020-12-03 12:48:07 +01:00
|
|
|
|
|
|
|
imgBytes=$(stat --format=%s $img)
|
|
|
|
|
|
|
|
# Create the partition table
|
2021-04-06 11:10:15 +02:00
|
|
|
sectorSize=512
|
2020-12-03 12:48:07 +01:00
|
|
|
sfdisk $img <<EOF
|
|
|
|
label: gpt
|
2021-04-06 11:10:15 +02:00
|
|
|
label-id: $disklabel
|
2022-04-24 08:35:10 +02:00
|
|
|
start=$(( $storeByteOffset / $sectorSize )), uuid=${cfg.store.guid}, type=${cfg.store.gptType}
|
|
|
|
start=$(( $espByteOffset / $sectorSize )), uuid=${cfg.esp.guid}, type=${cfg.esp.gptType}
|
2020-12-03 12:48:07 +01:00
|
|
|
EOF
|
2021-04-06 11:10:15 +02:00
|
|
|
sfdisk --reorder $img
|
2020-12-03 12:48:07 +01:00
|
|
|
|
2020-12-30 21:07:30 +01:00
|
|
|
qemu-img convert -f raw -O qcow2 $img $out
|
2020-12-03 12:48:07 +01:00
|
|
|
'';
|
|
|
|
}
|