Skip to content

Commit

Permalink
builders: imgBuilder: linux: enable overlayfs build
Browse files Browse the repository at this point in the history
  • Loading branch information
xieby1 committed Dec 30, 2024
1 parent 7dc2563 commit f3d8116
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions builders/imgBuilder/linux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@
, bc
, flex
, bison
# * With OverlayFS disabled, the default `unpackPhase` will copy the entire `common-build`,
# which involves approximately 1.7GB of disk writes.
# When building N linux images simultaneously, the disk write throughput becomes N*1.7GB.
# * With OverlayFS enabled, the build processes are overlaied onto 1.7GB `common-build`,
# resulting in minimal disk writes.
# However, because of the nix sandbox, overlayfs cannot be used directly in nix build processes,
# we utilize `runInLinuxVM` to work around this limitation.
# (For more details, see https://discourse.nixos.org/t/using-fuse-inside-nix-derivation/8534.)
# * If your nixbld* users have access to /dev/kvm,
# there will be no noticable performance degradation.
# * If your nixbld* users lack access to /dev/kvm,
# QEMU will fall back to translation mode (TCG),
# which is approximately 100 times slower.
, enableOverlayFS ? true
, fuse-overlayfs
, vmTools

, riscv64-cc
, rmExt
, initramfs
# TODO: use overlayfs to reduce disk usage
, common-build
}@args: stdenv.mkDerivation {
}@args: let overlayfsDisabled = stdenv.mkDerivation {
name = "${rmExt initramfs.name}.linux";
src = common-build;
buildInputs = [
Expand All @@ -33,7 +49,21 @@
make -j $NIX_BUILD_CORES
'';
installPhase = ''
# runInLinuxVM will auto create dir $out
rm -rf $out
cp arch/riscv/boot/Image $out
'';
passthru = args;
}
};
overlayfsEnabled = vmTools.runInLinuxVM (overlayfsDisabled.overrideAttrs (old: {
unpackPhase = ''
mkdir workdir
mkdir upperdir
mkdir overlaydir
/run/modprobe fuse
${fuse-overlayfs}/bin/fuse-overlayfs -o lowerdir=${old.src},workdir=workdir,upperdir=upperdir overlaydir
cd overlaydir
'';
memSize = 1024;
}));
in if enableOverlayFS then overlayfsEnabled else overlayfsDisabled

0 comments on commit f3d8116

Please sign in to comment.