iso-image: Workaround for better determinism in du output

The value of du output depends on the underlying file system, and thus is not fully deterministic. This workaround rounds up the disk usage size to the nearest multiple of 1MB, to increase the probability that two du output values on two different file systems fall within the same 1MB window. Note that this workaround won't make du output 100% reproducible, but will increase the probability of getting deterministic builds across different file systems.
This commit is contained in:
Ning Shang 2021-05-20 11:01:17 -07:00
parent e3cd644458
commit 4db7eb476f
No known key found for this signature in database
GPG key ID: 3C611CCC3C31E6E8

View file

@ -405,7 +405,8 @@ let
"${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}" ./boot/
touch --date=@0 ./EFI ./boot
usage_size=$(du -sb --apparent-size . | tr -cd '[:digit:]')
# Round up to the nearest multiple of 1MB, for more deterministic du output
usage_size=$(( $(du -s --block-size=1M --apparent-size . | tr -cd '[:digit:]') * 1024 * 1024 ))
# Make the image 110% as big as the files need to make up for FAT overhead
image_size=$(( ($usage_size * 110) / 100 ))
# Make the image fit blocks of 1M