How to create a virtual machine with a filesystem defined by nixos virtualisation module?

I am trying to come up with a quick iterative way of creating nixos VMs that i can spin up, reboot and has it’s own virtual drive, filesystem etc.

The motivation of this was when i was testing nixos modules disko and impermanence and i found that there wasn’t a way (AFAIK) to have an isolated VM where i had full control of it’s disk configuration and filesystem.

The approach that i like but doesn’t work is to use build-vm.

nixos-rebuild build-vm --flake .#test 
result/bin/run-nixos-vm 

and then declare virtualisation options in the flake

virtualisation.vmVariant = {
  virtualisation = {
    diskSize = 100000; 
    memorySize = 8192; y.
    cores = 3;
    graphics = true;
  };
};

i am able to start up this VM, but i cannot do any disk configuration within it i.e. i get errors when running parted commands. i believe this is because it uses a p9 filesystem but could be wrong. Either way i have attempted to create a vm filesystem that uses tmpfs or ext4 similar to if i did a live install of nixos from an iso image. To achieve this i tried to make use of the filesystem options within the nixos virtualisation module. But this seems to have no impact on the VM and i get the same output from lsblk and df -Th i.e. a p9 filesystem which errors on reformat/partition.

Does anybody know how to create a VM using build-vm and have the VM load with a pre-specified filesystem?

you have to pre-create all needed filesystems in the initrd hook, and also re-define them inside virtualisation.fileSystems
example:

{
  virtualisation = {
    emptyDiskImages = [ 4096 4096 ];

    fileSystems."/storage/photos" = {
      device = "zroot/photos";
      fsType = "zfs";
      options = [ "zfsutil" "nofail" ];
    };
  };

  boot.initrd.postDeviceCommands = ''
    zpool create -f zroot -R /mnt mirror -O mountpoint=none -O atime=off -o ashift=12 -O acltype=posixacl -O xattr=sa -O compression=lz4 /dev/vdb /dev/vdc
    zfs create -o mountpoint=legacy zroot/root
    zfs create -o mountpoint=legacy zroot/root/home

    zfs create zroot/photos
  '';
}