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; };
20 import (modulesPath + "/../lib/make-disk-image.nix") {
21 inherit pkgs config lib;
22 additionalPaths = [ storeContents ];
25 partitionTableType = "none";
26 installBootLoader = false;
28 additionalSpace = "0M";
33 hostPkgs.runCommand "nix-store-image" { } ''
35 cd ${builtins.storeDir}
36 ${hostPkgs.erofs-utils}/bin/mkfs.erofs \
40 -U eb176051-bd15-49b7-9e6b-462e0b467019 \
43 <${storeContents}/store-paths \
46 | ${hostPkgs.python3}/bin/python -c ${
47 escapeShellArg (builtins.readFile
48 (modulesPath + "/virtualisation/includes-to-excludes.py"))
55 "${hostPkgs.callPackage (modulesPath + "/../lib/make-squashfs.nix") {
56 storeContents = config.virtualisation.additionalPaths;
62 virtualisation.qemu.isolation.nixStoreFilesystemType = mkOption {
64 What filesystem to use for the guest's Nix store.
66 erofs is more compact than ext4, but less mature.
68 squashfs support currently requires a dubious kludge that results in these
69 VMs not being able to mount any other squashfs volumes besides the nix store.
71 type = lib.types.enum [ "ext4" "erofs" "squashfs" ];
77 boot.initrd.kernelModules =
78 optional (cfg.nixStoreFilesystemType == "erofs") "erofs";
80 nixpkgs.overlays = optional (cfg.nixStoreFilesystemType == "squashfs")
82 util-linux = prev.util-linux.overrideAttrs (old: {
83 patches = (old.patches or [ ])
84 ++ [ ./libblkid-squashfs-nix-store-kludge.patch ];
88 fileSystems = mkVMOverride {
89 "${storeMountPath}" = {
90 fsType = cfg.nixStoreFilesystemType;
97 system.build.nixStoreImage =
98 nixStoreImages."${cfg.nixStoreFilesystemType}";
102 sharedDirectories = mkForce { };
105 file = config.system.build.nixStoreImage;
115 (mkIf (cfg.nixStoreFilesystemType == "ext4") {
116 # We use this to disable fsck runs on the ext4 nix store image because stage-1
117 # fsck crashes (maybe because the device is read-only?), halting boot.
118 boot.initrd.checkJournalingFS = false;