···
rootfsImage = pkgs.callPackage ../../../lib/make-ext4-fs.nix ({
inherit (config.sdImage) storePaths;
21
-
compressImage = true;
21
+
compressImage = config.sdImage.compressImage;
populateImageCommands = config.sdImage.populateRootCommands;
volumeLabel = "NIXOS_SD";
} // optionalAttrs (config.sdImage.rootPartitionUUID != null) {
···
mtools, libfaketime, util-linux, zstd }: stdenv.mkDerivation {
name = config.sdImage.imageName;
177
-
nativeBuildInputs = [ dosfstools e2fsprogs mtools libfaketime util-linux zstd ];
177
+
nativeBuildInputs = [ dosfstools e2fsprogs libfaketime mtools util-linux ]
178
+
++ lib.optional config.sdImage.compressImage zstd;
inherit (config.sdImage) imageName compressImage;
···
echo "file sd-image $img" >> $out/nix-support/hydra-build-products
193
+
root_fs=${rootfsImage}
194
+
${lib.optionalString config.sdImage.compressImage ''
195
+
root_fs=./root-fs.img
echo "Decompressing rootfs image"
193
-
zstd -d --no-progress "${rootfsImage}" -o ./root-fs.img
197
+
zstd -d --no-progress "${rootfsImage}" -o $root_fs
# Gap in front of the first partition, in MiB
gap=${toString config.sdImage.firmwarePartitionOffset}
# Create the image file sized to fit /boot/firmware and /, plus slack for the gap.
199
-
rootSizeBlocks=$(du -B 512 --apparent-size ./root-fs.img | awk '{ print $1 }')
204
+
rootSizeBlocks=$(du -B 512 --apparent-size $root_fs | awk '{ print $1 }')
firmwareSizeBlocks=$((${toString config.sdImage.firmwareSize} * 1024 * 1024 / 512))
imageSize=$((rootSizeBlocks * 512 + firmwareSizeBlocks * 512 + gap * 1024 * 1024))
truncate -s $imageSize $img
···
# Copy the rootfs into the SD image
eval $(partx $img -o START,SECTORS --nr 2 --pairs)
217
-
dd conv=notrunc if=./root-fs.img of=$img seek=$START count=$SECTORS
222
+
dd conv=notrunc if=$root_fs of=$img seek=$START count=$SECTORS
# Create a FAT32 /boot/firmware partition of suitable size into firmware_part.img
eval $(partx $img -o START,SECTORS --nr 1 --pairs)