about summary refs log tree commit diff
path: root/nixos/lib/make-ext4-fs.nix
diff options
context:
space:
mode:
authorwucke13 <wucke13@gmail.com>2021-12-19 13:39:42 +0100
committerwucke13 <wucke13@gmail.com>2021-12-21 21:31:44 +0100
commit121e2f7e1554794e7392427cf77e94ab9887871e (patch)
tree83dbeb674f76007326554aa2d8bafa2cda057a40 /nixos/lib/make-ext4-fs.nix
parentd4a497382befcde76470e4ebb8f89062fe354c7d (diff)
honor sdImage.compressImage in intermediate build steps
Diffstat (limited to 'nixos/lib/make-ext4-fs.nix')
-rw-r--r--nixos/lib/make-ext4-fs.nix9
1 files changed, 9 insertions, 0 deletions
diff --git a/nixos/lib/make-ext4-fs.nix b/nixos/lib/make-ext4-fs.nix
index 416beeb32f2fa..b8e1b8d24c48b 100644
--- a/nixos/lib/make-ext4-fs.nix
+++ b/nixos/lib/make-ext4-fs.nix
@@ -78,6 +78,15 @@ pkgs.stdenv.mkDerivation {
       # get rid of the unnecessary slack here--but see
       # 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
         echo "Compressing image"
         zstd -v --no-progress ./$img -o $out