1 { config, lib, modulesPath, pkgs, ... }:
4 escapeShellArg mkForce mkIf mkMerge mkOption mkVMOverride optional;
6 cfg = config.virtualisation.qemu.isolation;
8 storeMountPath = if config.virtualisation.writableStore then
13 hostPkgs = config.virtualisation.host.pkgs;
16 hostPkgs.closureInfo { rootPaths = config.virtualisation.additionalPaths; };
19 ext4 = import (modulesPath + "/../lib/make-disk-image.nix") {
20 inherit pkgs config lib;
21 additionalPaths = [ storeContents ];
24 partitionTableType = "none";
25 installBootLoader = false;
27 additionalSpace = "0M";
30 erofs = hostPkgs.runCommand "nix-store-image" { } ''
32 cd ${builtins.storeDir}
33 ${hostPkgs.erofs-utils}/bin/mkfs.erofs \
37 -U eb176051-bd15-49b7-9e6b-462e0b467019 \
40 <${storeContents}/store-paths \
43 | ${hostPkgs.python3}/bin/python -c ${
44 escapeShellArg (builtins.readFile
45 (modulesPath + "/virtualisation/includes-to-excludes.py"))
54 virtualisation.qemu.isolation.nixStoreFilesystemType = mkOption {
56 What filesystem to use for the guest's Nix store.
58 erofs is more compact than ext4, but less mature.
60 type = lib.types.enum [ "ext4" "erofs" ];
66 boot.initrd.kernelModules =
67 optional (cfg.nixStoreFilesystemType == "erofs") "erofs";
69 fileSystems = mkVMOverride {
70 "${storeMountPath}" = {
71 fsType = cfg.nixStoreFilesystemType;
78 system.build.nixStoreImage =
79 nixStoreImages."${cfg.nixStoreFilesystemType}";
83 sharedDirectories = mkForce { };
86 file = "${config.system.build.nixStoreImage}/nixos.img";
96 (mkIf (cfg.nixStoreFilesystemType == "ext4") {
97 # We use this to disable fsck runs on the ext4 nix store image because stage-1
98 # fsck crashes (maybe because the device is read-only?), halting boot.
99 boot.initrd.checkJournalingFS = false;