mirror of
https://github.com/NixOS/mobile-nixos.git
synced 2024-09-21 00:37:15 +03:00
image-builder: makeFilesystem: reviews minimum size with blockSize
First of all, `du -s` will always combine the sizes into the multiple of its given --block-size, so 4×1 byte files will show up as 1 block size (assuming a block size > 4). The expected size would have been at least one block size per file, so for 512, 512×4 thus 2048. With this change, we sum the sizes ourselves. This adds a new requirement to the filesystems, that they pass the block size to the generic builder, though this is good, as it will increases reproducibility. In addition, filesystems can present the option to users, allowing the user to set their block sizes as expected.
This commit is contained in:
parent
32c93bb9a7
commit
c0001af576
@ -13,6 +13,7 @@ in
|
|||||||
, populateCommands ? null
|
, populateCommands ? null
|
||||||
# When size is not given, it is assumed that `populateCommands` will populate
|
# When size is not given, it is assumed that `populateCommands` will populate
|
||||||
# the filesystem.
|
# the filesystem.
|
||||||
|
, blockSize
|
||||||
, size ? null
|
, size ? null
|
||||||
, ...
|
, ...
|
||||||
} @ args:
|
} @ args:
|
||||||
@ -27,7 +28,7 @@ in
|
|||||||
stdenvNoCC.mkDerivation (args // rec {
|
stdenvNoCC.mkDerivation (args // rec {
|
||||||
# Do not inherit `size`; we don't want to accidentally use it. The `size` can
|
# Do not inherit `size`; we don't want to accidentally use it. The `size` can
|
||||||
# be dynamic depending on the contents.
|
# be dynamic depending on the contents.
|
||||||
inherit partName;
|
inherit partName blockSize;
|
||||||
|
|
||||||
name = "partition-${partName}";
|
name = "partition-${partName}";
|
||||||
filename = "${partName}.img";
|
filename = "${partName}.img";
|
||||||
@ -37,6 +38,16 @@ stdenvNoCC.mkDerivation (args // rec {
|
|||||||
] ++ optionals (args ? nativeBuildInputs) args.nativeBuildInputs;
|
] ++ optionals (args ? nativeBuildInputs) args.nativeBuildInputs;
|
||||||
|
|
||||||
buildCommand = ''
|
buildCommand = ''
|
||||||
|
sum-lines() {
|
||||||
|
local acc=0
|
||||||
|
while read -r number; do
|
||||||
|
acc=$((acc+number))
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$acc"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# The default stdenv/generic clashes with `runHook`.
|
# The default stdenv/generic clashes with `runHook`.
|
||||||
# It doesn't override as expected.
|
# It doesn't override as expected.
|
||||||
unset -f checkPhase
|
unset -f checkPhase
|
||||||
@ -54,7 +65,11 @@ stdenvNoCC.mkDerivation (args // rec {
|
|||||||
)
|
)
|
||||||
''}
|
''}
|
||||||
${optionalString (size == null) ''
|
${optionalString (size == null) ''
|
||||||
size=$(cd files; du -sb --apparent-size . | tr -cd '[:digit:]')
|
# Size rounded in blocks. This assumes all files are to be rounded to a
|
||||||
|
# multiple of blockSize.
|
||||||
|
size=$(du -akh --block-size "$blockSize" . | cut -f1 | sum-lines)
|
||||||
|
# Size in bytes
|
||||||
|
size=$((size * blockSize))
|
||||||
''}
|
''}
|
||||||
|
|
||||||
if (( size < minimumSize )); then
|
if (( size < minimumSize )); then
|
||||||
|
Loading…
Reference in New Issue
Block a user