]> git.scottworley.com Git - nixos-qemu-vm-isolation/blobdiff - modules/qemu-vm-isolation.nix
Reduce repetition in test script
[nixos-qemu-vm-isolation] / modules / qemu-vm-isolation.nix
index 7e0a37f6b0cda943ade4821d34685bb28aff6a24..260e9fec7323c985a53c0fc1f197b13c765af525 100644 (file)
@@ -1,6 +1,6 @@
 { config, lib, modulesPath, pkgs, ... }:
 let
-  inherit (lib) findSingle mkForce mkVMOverride;
+  inherit (lib) findSingle mkForce mkIf mkMerge mkVMOverride;
 
   lookupDriveDeviceName = driveName: driveList:
     (findSingle (drive: drive.name == driveName)
@@ -14,33 +14,44 @@ let
 
 in {
 
-  boot.initrd.availableKernelModules = [ "squashfs" ];
-
   fileSystems = mkVMOverride {
     "${storeMountPath}" = {
       device =
         lookupDriveDeviceName "nixstore" config.virtualisation.qemu.drives;
-      fsType = "squashfs";
+      fsType = "ext4";
       options = [ "ro" ];
       neededForBoot = true;
     };
   };
 
-  system.build.squashfsStore =
-    pkgs.callPackage (modulesPath + "/../lib/make-squashfs.nix") {
-      storeContents = config.virtualisation.pathsInNixDB;
+  # We use this to disable fsck runs on the ext4 nix store image because stage-1
+  # fsck crashes (maybe because the device is read-only?), halting boot.
+  boot.initrd.checkJournalingFS = false;
+
+  system.build.nixStoreImage =
+    import (modulesPath + "/../lib/make-disk-image.nix") {
+      inherit pkgs config lib;
+      additionalPaths = [
+        (config.virtualisation.host.pkgs.closureInfo {
+          rootPaths = config.virtualisation.additionalPaths;
+        })
+      ];
+      onlyNixStore = true;
+      label = "nix-store";
+      partitionTableType = "none";
+      installBootLoader = false;
+      diskSize = "auto";
+      additionalSpace = "0M";
+      copyChannel = false;
     };
 
   virtualisation = {
 
-    # This should be the default.
-    bootDevice = lookupDriveDeviceName "root" config.virtualisation.qemu.drives;
-
     sharedDirectories = mkForce { };
 
     qemu.drives = [{
       name = "nixstore";
-      file = "${config.system.build.squashfsStore}";
+      file = "${config.system.build.nixStoreImage}/nixos.img";
       driveExtraOpts = {
         format = "raw";
         read-only = "on";