Also is there a better way how to specify imports?
I use a flake for my NixOS config and importing <nixos/.../...nix seems like pre-flake configuration. For example HM is imported as home-manager.nixosModules.home-manager and not <home-manager/.../...nix.
You can use fallocate to create a disk image. Then, create partitions n the disk image using fdisk or parted. Next, format the partitions and mount them. Then you can use nixos-install to install NixOS into the disk image. You should be able to convert the raw image to qcow2, if you want.
The problem with nixos-rebuild build-vm is that it shares /nix store. That’s great for testing but not so much for a general use as a VM that can run on a different host.
But are you sure this is actually what you want? If you build the VM, you’ll need to copy the entire derivation to whatever device you plan to use it on anyway, and the closure will always contain everything it needs.
Not speaking for the OP’s specific needs, but a common reason to need this is when the intended VM host is not running nix/nixos; indeed it may not be a host you control at all.
Yes, of course. I want to get qcow2 file with many GiB in size.
Exactly.
Is my question surprising / unusual? Isn’t this a common thing people do to use Nix to get Raspberry Pi images, containers, VirtualBox VMs, AWS AMIs and they all have all bits they need to run on any hardware / host?
First time I heard about Nix is when I researched for an alternative to Hashicorp Packer to build AWS, Azure, QEMU… images
It is surprising that people don’t “speak” more often about building topic. Most of questions here on the forum are about building executable and configuration (NixOS)…
If you’re building VM why not build and install the VM within say, virt-manager? That would keep it pretty separate aside from passing through your network config and such? Or am I misunderstanding the specific ask here? Sorry if I am!