1 { config, lib, modulesPath, pkgs, ... }:
4 escapeShellArg findSingle mkForce mkIf mkMerge mkOption mkVMOverride
7 cfg = config.virtualisation.qemu.isolation;
9 lookupDriveDeviceName = driveName: driveList:
10 (findSingle (drive: drive.name == driveName)
11 (throw "Drive ${driveName} not found")
12 (throw "Multiple drives named ${driveName}") driveList).device;
14 storeMountPath = if config.virtualisation.writableStore then
19 hostPkgs = config.virtualisation.host.pkgs;
22 hostPkgs.closureInfo { rootPaths = config.virtualisation.additionalPaths; };
25 ext4 = import (modulesPath + "/../lib/make-disk-image.nix") {
26 inherit pkgs config lib;
27 additionalPaths = [ storeContents ];
30 partitionTableType = "none";
31 installBootLoader = false;
33 additionalSpace = "0M";
36 erofs = hostPkgs.runCommand "nix-store-image" { } ''
38 cd ${builtins.storeDir}
39 ${hostPkgs.erofs-utils}/bin/mkfs.erofs \
43 -U eb176051-bd15-49b7-9e6b-462e0b467019 \
46 <${storeContents}/store-paths \
49 | ${hostPkgs.python3}/bin/python -c ${
50 escapeShellArg (builtins.readFile
51 (modulesPath + "/virtualisation/includes-to-excludes.py"))
60 virtualisation.qemu.isolation.nixStoreFilesystemType = mkOption {
62 What filesystem to use for the guest's Nix store.
64 erofs is more compact than ext4, but less mature.
66 type = lib.types.enum [ "ext4" "erofs" ];
72 boot.initrd.kernelModules =
73 optional (cfg.nixStoreFilesystemType == "erofs") "erofs";
75 fileSystems = mkVMOverride {
76 "${storeMountPath}" = {
78 lookupDriveDeviceName "nixstore" config.virtualisation.qemu.drives;
79 fsType = cfg.nixStoreFilesystemType;
85 system.build.nixStoreImage =
86 nixStoreImages."${cfg.nixStoreFilesystemType}";
90 sharedDirectories = mkForce { };
94 file = "${config.system.build.nixStoreImage}/nixos.img";
104 (mkIf (cfg.nixStoreFilesystemType == "ext4") {
105 # We use this to disable fsck runs on the ext4 nix store image because stage-1
106 # fsck crashes (maybe because the device is read-only?), halting boot.
107 boot.initrd.checkJournalingFS = false;