vm_forward.nix example passes net option twice
Closed this issue · 1 comments
Running nixos-shell
on examples/vm_forward.nix
results in the following error:
nixos-shell/examples: nixos-shell vm-forward.nix
trace: warning: system.stateVersion is not set, defaulting to 22.05. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion.
/nix/store/ii93pa9vnfcf5j9niwglnf3m71yrm97j-nixos-vm
qemu-kvm: -netdev user,id=user.0,hostfwd=tcp::2222-:22: Duplicate ID 'user.0' for netdev
When looking at the corresponding run-nixos-vm
script we see that qemu gets two -net
and -netdev
options, both with id=user.0
.
-net nic,netdev=user.0,model=virtio -netdev user,id=user.0,"$QEMU_NET_OPTS" -net nic,netdev=user.0,model=virtio -netdev user,id=user.0,hostfwd=tcp::2222-:22
It's not passed twice. The module system concats the network devices from vm_forward.nix
to the one set in nixpkgs's ${modulesPath}/virtualisation/qemu_vm.nix
instead of replacing them, because a) it's a list, and b) they have the same priority. This is the same cause as for #51,
One (hacky) solution is to use mkForce
, as in
virtualisation.qemu.networkingOptions = nixpkgs.lib.mkForce [ ... ];
A more thorough solution might be to make a wrapper interface (i.e. nixos-shell.qemu.networkingOptions
) which does that under the hood.