Skip to content

Commit

Permalink
nixos-modules/microvm/store-disk: mount source files with bubblewrap …
Browse files Browse the repository at this point in the history
…instead of copying
  • Loading branch information
astro committed Dec 10, 2024
1 parent 5067708 commit e08aed6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions nixos-modules/microvm/store-disk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ let

writeClosure = pkgs.writeClosure or pkgs.writeReferencesToFile;

storeDiskContents = writeClosure (
[ config.system.build.toplevel ]
++
lib.optional config.nix.enable regInfo
);

in
{
options.microvm = with lib; {
Expand Down Expand Up @@ -84,6 +90,8 @@ in

microvm.storeDisk = pkgs.runCommandLocal "microvm-store-disk.${config.microvm.storeDiskType}" {
nativeBuildInputs = [
pkgs.buildPackages.time
pkgs.buildPackages.bubblewrap
{
squashfs = [ pkgs.buildPackages.squashfs-tools-ng ];
erofs = [ erofs-utils ];
Expand All @@ -93,22 +101,14 @@ in
inherit regInfo;
};
} ''
echo Copying a /nix/store
mkdir store
for d in $(sort -u ${
lib.concatMapStringsSep " " writeClosure (
lib.optionals config.microvm.storeOnDisk (
[ config.system.build.toplevel ]
++
lib.optional config.nix.enable regInfo
)
)
}); do
cp -a $d store
BWRAP_ARGS="--dev-bind / / --chdir $(pwd)"
for d in $(sort -u ${storeDiskContents}); do
BWRAP_ARGS="$BWRAP_ARGS --ro-bind $d $(pwd)/store/$(basename $d)"
done
echo Creating a ${config.microvm.storeDiskType}
time ${{
bwrap $BWRAP_ARGS -- time ${{
squashfs = "gensquashfs ${squashfsFlags} -D store --all-root -q $out";
erofs = "mkfs.erofs ${erofsFlags} -T 0 --all-root -L nix-store --mount-point=/nix/store $out store";
}.${config.microvm.storeDiskType}}
Expand Down

0 comments on commit e08aed6

Please sign in to comment.