Skip to content

Commit 8d33c91

Browse files
committed
nixos-modules/microvm/store-disk: fallback in case of bubblewrap failure
1 parent e24078e commit 8d33c91

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

nixos-modules/microvm/store-disk.nix

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ let
2727
erofsFlags = builtins.concatStringsSep " " config.microvm.storeDiskErofsFlags;
2828
squashfsFlags = builtins.concatStringsSep " " config.microvm.storeDiskSquashfsFlags;
2929

30+
mkfsCommand =
31+
{
32+
squashfs = "gensquashfs ${squashfsFlags} -D store --all-root -q $out";
33+
erofs = "mkfs.erofs ${erofsFlags} -T 0 --all-root -L nix-store --mount-point=/nix/store $out store";
34+
}.${config.microvm.storeDiskType};
35+
3036
writeClosure = pkgs.writeClosure or pkgs.writeReferencesToFile;
3137

3238
storeDiskContents = writeClosure (
@@ -82,10 +88,12 @@ in
8288
done
8389
8490
echo Creating a ${config.microvm.storeDiskType}
85-
bwrap $BWRAP_ARGS -- time ${{
86-
squashfs = "gensquashfs ${squashfsFlags} -D store --all-root -q $out";
87-
erofs = "mkfs.erofs ${erofsFlags} -T 0 --all-root -L nix-store --mount-point=/nix/store $out store";
88-
}.${config.microvm.storeDiskType}}
91+
bwrap $BWRAP_ARGS -- time ${mkfsCommand} || \
92+
(
93+
echo "Bubblewrap failed. Falling back to copying...">&2
94+
cp -a $(sort -u ${storeDiskContents}) store/
95+
time ${mkfsCommand}
96+
)
8997
'';
9098
})
9199

0 commit comments

Comments
 (0)