mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
Merge pull request #151633 from wucke13/sd-image-experiment
honor `sdImage.compressImage` also in the build process
This commit is contained in:
commit
773cbfbd28
2 changed files with 19 additions and 5 deletions
|
@ -78,6 +78,15 @@ pkgs.stdenv.mkDerivation {
|
||||||
# get rid of the unnecessary slack here--but see
|
# get rid of the unnecessary slack here--but see
|
||||||
# https://github.com/NixOS/nixpkgs/issues/125121 for caveats.
|
# https://github.com/NixOS/nixpkgs/issues/125121 for caveats.
|
||||||
|
|
||||||
|
# shrink to fit
|
||||||
|
resize2fs -M $img
|
||||||
|
|
||||||
|
# Add 16 MebiByte to the current_size
|
||||||
|
new_size=$(dumpe2fs -h $img | awk -F: \
|
||||||
|
'/Block count/{count=$2} /Block size/{size=$2} END{print (count*size+16*2**20)/size}')
|
||||||
|
|
||||||
|
resize2fs $img $new_size
|
||||||
|
|
||||||
if [ ${builtins.toString compressImage} ]; then
|
if [ ${builtins.toString compressImage} ]; then
|
||||||
echo "Compressing image"
|
echo "Compressing image"
|
||||||
zstd -v --no-progress ./$img -o $out
|
zstd -v --no-progress ./$img -o $out
|
||||||
|
|
|
@ -18,7 +18,7 @@ with lib;
|
||||||
let
|
let
|
||||||
rootfsImage = pkgs.callPackage ../../../lib/make-ext4-fs.nix ({
|
rootfsImage = pkgs.callPackage ../../../lib/make-ext4-fs.nix ({
|
||||||
inherit (config.sdImage) storePaths;
|
inherit (config.sdImage) storePaths;
|
||||||
compressImage = true;
|
compressImage = config.sdImage.compressImage;
|
||||||
populateImageCommands = config.sdImage.populateRootCommands;
|
populateImageCommands = config.sdImage.populateRootCommands;
|
||||||
volumeLabel = "NIXOS_SD";
|
volumeLabel = "NIXOS_SD";
|
||||||
} // optionalAttrs (config.sdImage.rootPartitionUUID != null) {
|
} // optionalAttrs (config.sdImage.rootPartitionUUID != null) {
|
||||||
|
@ -174,7 +174,8 @@ in
|
||||||
mtools, libfaketime, util-linux, zstd }: stdenv.mkDerivation {
|
mtools, libfaketime, util-linux, zstd }: stdenv.mkDerivation {
|
||||||
name = config.sdImage.imageName;
|
name = config.sdImage.imageName;
|
||||||
|
|
||||||
nativeBuildInputs = [ dosfstools e2fsprogs mtools libfaketime util-linux zstd ];
|
nativeBuildInputs = [ dosfstools e2fsprogs libfaketime mtools util-linux ]
|
||||||
|
++ lib.optional config.sdImage.compressImage zstd;
|
||||||
|
|
||||||
inherit (config.sdImage) imageName compressImage;
|
inherit (config.sdImage) imageName compressImage;
|
||||||
|
|
||||||
|
@ -189,14 +190,18 @@ in
|
||||||
echo "file sd-image $img" >> $out/nix-support/hydra-build-products
|
echo "file sd-image $img" >> $out/nix-support/hydra-build-products
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
root_fs=${rootfsImage}
|
||||||
|
${lib.optionalString config.sdImage.compressImage ''
|
||||||
|
root_fs=./root-fs.img
|
||||||
echo "Decompressing rootfs image"
|
echo "Decompressing rootfs image"
|
||||||
zstd -d --no-progress "${rootfsImage}" -o ./root-fs.img
|
zstd -d --no-progress "${rootfsImage}" -o $root_fs
|
||||||
|
''}
|
||||||
|
|
||||||
# Gap in front of the first partition, in MiB
|
# Gap in front of the first partition, in MiB
|
||||||
gap=${toString config.sdImage.firmwarePartitionOffset}
|
gap=${toString config.sdImage.firmwarePartitionOffset}
|
||||||
|
|
||||||
# Create the image file sized to fit /boot/firmware and /, plus slack for the gap.
|
# Create the image file sized to fit /boot/firmware and /, plus slack for the gap.
|
||||||
rootSizeBlocks=$(du -B 512 --apparent-size ./root-fs.img | awk '{ print $1 }')
|
rootSizeBlocks=$(du -B 512 --apparent-size $root_fs | awk '{ print $1 }')
|
||||||
firmwareSizeBlocks=$((${toString config.sdImage.firmwareSize} * 1024 * 1024 / 512))
|
firmwareSizeBlocks=$((${toString config.sdImage.firmwareSize} * 1024 * 1024 / 512))
|
||||||
imageSize=$((rootSizeBlocks * 512 + firmwareSizeBlocks * 512 + gap * 1024 * 1024))
|
imageSize=$((rootSizeBlocks * 512 + firmwareSizeBlocks * 512 + gap * 1024 * 1024))
|
||||||
truncate -s $imageSize $img
|
truncate -s $imageSize $img
|
||||||
|
@ -214,7 +219,7 @@ in
|
||||||
|
|
||||||
# Copy the rootfs into the SD image
|
# Copy the rootfs into the SD image
|
||||||
eval $(partx $img -o START,SECTORS --nr 2 --pairs)
|
eval $(partx $img -o START,SECTORS --nr 2 --pairs)
|
||||||
dd conv=notrunc if=./root-fs.img of=$img seek=$START count=$SECTORS
|
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
|
# Create a FAT32 /boot/firmware partition of suitable size into firmware_part.img
|
||||||
eval $(partx $img -o START,SECTORS --nr 1 --pairs)
|
eval $(partx $img -o START,SECTORS --nr 1 --pairs)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue