Merge pull request #181746 from hercules-ci/nixosTest-erofs

nixos/qemu-vm: Use disposable EROFS for store when writableStore = false
This commit is contained in:
Robert Hensing
2022-08-14 08:46:21 +02:00
committed by GitHub
4 changed files with 140 additions and 5 deletions

View File

@@ -17,6 +17,8 @@ let
cfg = config.virtualisation;
opt = options.virtualisation;
qemu = cfg.qemu.package;
consoles = lib.concatMapStringsSep " " (c: "console=${c}") cfg.qemu.consoles;
@@ -122,11 +124,32 @@ let
TMPDIR=$(mktemp -d nix-vm.XXXXXXXXXX --tmpdir)
fi
${lib.optionalString cfg.useNixStoreImage
''
# Create a writable copy/snapshot of the store image.
${qemu}/bin/qemu-img create -f qcow2 -F qcow2 -b ${storeImage}/nixos.qcow2 "$TMPDIR"/store.img
''}
${lib.optionalString (cfg.useNixStoreImage)
(if cfg.writableStore
then ''
# Create a writable copy/snapshot of the store image.
${qemu}/bin/qemu-img create -f qcow2 -F qcow2 -b ${storeImage}/nixos.qcow2 "$TMPDIR"/store.img
''
else ''
(
cd ${builtins.storeDir}
${pkgs.erofs-utils}/bin/mkfs.erofs \
--force-uid=0 \
--force-gid=0 \
-U eb176051-bd15-49b7-9e6b-462e0b467019 \
-T 0 \
--exclude-regex="$(
<${pkgs.closureInfo { rootPaths = [ config.system.build.toplevel regInfo ]; }}/store-paths \
sed -e 's^.*/^^g' \
| cut -c -10 \
| ${pkgs.python3}/bin/python ${./includes-to-excludes.py} )" \
"$TMPDIR"/store.img \
. \
</dev/null >/dev/null
)
''
)
}
# Create a directory for exchanging data with the VM.
mkdir -p "$TMPDIR/xchg"
@@ -746,6 +769,26 @@ in
}
]));
warnings =
optional (
cfg.writableStore &&
cfg.useNixStoreImage &&
opt.writableStore.highestPrio > lib.modules.defaultPriority)
''
You have enabled ${opt.useNixStoreImage} = true,
without setting ${opt.writableStore} = false.
This causes a store image to be written to the store, which is
costly, especially for the binary cache, and because of the need
for more frequent garbage collection.
If you really need this combination, you can set ${opt.writableStore}
explicitly to false, incur the cost and make this warning go away.
Otherwise, we recommend
${opt.writableStore} = false;
'';
# Note [Disk layout with `useBootLoader`]
#
# If `useBootLoader = true`, we configure 2 drives:
@@ -769,6 +812,8 @@ in
);
boot.loader.grub.gfxmodeBios = with cfg.resolution; "${toString x}x${toString y}";
boot.initrd.kernelModules = optionals (cfg.useNixStoreImage && !cfg.writableStore) [ "erofs" ];
boot.initrd.extraUtilsCommands = lib.mkIf (cfg.useDefaultFilesystems && !config.boot.initrd.systemd.enable)
''
# We need mke2fs in the initrd.
@@ -905,6 +950,7 @@ in
name = "nix-store";
file = ''"$TMPDIR"/store.img'';
deviceExtraOpts.bootindex = if cfg.useBootLoader then "3" else "2";
driveExtraOpts.format = if cfg.writableStore then "qcow2" else "raw";
}])
(mkIf cfg.useBootLoader [
# The order of this list determines the device names, see