Skip to content

Commit e08aed6

Browse files
committed
nixos-modules/microvm/store-disk: mount source files with bubblewrap instead of copying
1 parent 5067708 commit e08aed6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

nixos-modules/microvm/store-disk.nix

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ let
2929

3030
writeClosure = pkgs.writeClosure or pkgs.writeReferencesToFile;
3131

32+
storeDiskContents = writeClosure (
33+
[ config.system.build.toplevel ]
34+
++
35+
lib.optional config.nix.enable regInfo
36+
);
37+
3238
in
3339
{
3440
options.microvm = with lib; {
@@ -84,6 +90,8 @@ in
8490

8591
microvm.storeDisk = pkgs.runCommandLocal "microvm-store-disk.${config.microvm.storeDiskType}" {
8692
nativeBuildInputs = [
93+
pkgs.buildPackages.time
94+
pkgs.buildPackages.bubblewrap
8795
{
8896
squashfs = [ pkgs.buildPackages.squashfs-tools-ng ];
8997
erofs = [ erofs-utils ];
@@ -93,22 +101,14 @@ in
93101
inherit regInfo;
94102
};
95103
} ''
96-
echo Copying a /nix/store
97104
mkdir store
98-
for d in $(sort -u ${
99-
lib.concatMapStringsSep " " writeClosure (
100-
lib.optionals config.microvm.storeOnDisk (
101-
[ config.system.build.toplevel ]
102-
++
103-
lib.optional config.nix.enable regInfo
104-
)
105-
)
106-
}); do
107-
cp -a $d store
105+
BWRAP_ARGS="--dev-bind / / --chdir $(pwd)"
106+
for d in $(sort -u ${storeDiskContents}); do
107+
BWRAP_ARGS="$BWRAP_ARGS --ro-bind $d $(pwd)/store/$(basename $d)"
108108
done
109109
110110
echo Creating a ${config.microvm.storeDiskType}
111-
time ${{
111+
bwrap $BWRAP_ARGS -- time ${{
112112
squashfs = "gensquashfs ${squashfsFlags} -D store --all-root -q $out";
113113
erofs = "mkfs.erofs ${erofsFlags} -T 0 --all-root -L nix-store --mount-point=/nix/store $out store";
114114
}.${config.microvm.storeDiskType}}

0 commit comments

Comments
 (0)