Why does qemu-vm only support the host CPU and not emulation?

I know qemu supports emulating CPUs and I wanted to try and run a x86_64-linux nixos virtual machine on my aarch64-darwin machine. According to the error message this isn’t possible:

error: Unsupported guest system x86_64-linux for host aarch64-darwin, supported: aarch64-linux

When I looked where this error is thrown I found that the default qemu package that qemu-vm uses is one that only supports the host CPU. When I manually edited the run-xxx-vm script to use a different qemu package I found that the VM does boot. I understand that this is much slower, but wouldn’t it be useful to have this support in nixpkgs? Maybe with a flag to make sure the user knows it will be much slower

Which package did you install? How was your command line constructed? On my aarch64-darwin machine, I ran the following successfully:
nix shell nixpkgs#qemu
and then (after downloading the x86_64 nixos iso):
qemu-system-x86_64 ~/Dowloads/nixos-minimal-22.11.3184.9b8e5abb183-x86_64-linux.iso

and it is running, though very slowly.

I should have clarified further, I’m talking about the result you get when you build a VM with config.system.build.vm on a nixpkgs.lib.nixosSystem.

When I set virtualisation.qemu.package to nixpkgs.aarch64-darwin.qemu and I set the system to x86_64-linux I get the error I posted above.

When I set build the x86_64-darwin variant and then manually set the qemu executable to my native one in the result/bin/run-nixos-vm script it does work, and it would be useful if nixpkgs could support that without my weird replacement hack

Does it work if you set boot.binfmt.emulatedSystems ?

I’m not sure how or where. I’m running on (aarch64) macOS not NixOS

Sorry, I missed that detail. I should really do better.