File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed
Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ test-resources:
1010 $(NIXOS_SHELL ) examples/vm-resources.nix
1111
1212test-forward :
13- QEMU_NET_OPTS= " hostfwd=tcp::2222-:22 " $(NIXOS_SHELL ) examples/vm.nix
13+ $(NIXOS_SHELL ) examples/vm-forward .nix
1414
1515test-graphics :
1616 $(NIXOS_SHELL ) examples/vm-graphics.nix
Original file line number Diff line number Diff line change @@ -52,9 +52,12 @@ Or switch to qemu console with `Ctrl-a c` and type:
5252## Port forwarding
5353
5454To forward ports from the virtual machine to the host, override the
55- ` QEMU_NET_OPTS ` environment variable.
56- In this example the tcp port 2222 on the host is forwarded to port 22 in the virtual
57- machine:
55+ ` virtualisation.qemu.networkingOptions ` NixOS option.
56+ See ` examples/vm-forward.nix ` where the ssh server running on port 22 in the
57+ virtual machine is made accessible through port 2222 on the host.
58+
59+ If ` virtualisation.qemu.networkingOptions ` is not overridden the same can be
60+ also achieved by using the ` QEMU_NET_OPTS ` environment variable.
5861
5962``` console
6063$ QEMU_NET_OPTS=" hostfwd=tcp::2222-:22" nixos-shell
Original file line number Diff line number Diff line change 1+ { pkgs , ... } : {
2+ services . openssh . enable = true ;
3+ virtualisation . qemu . networkingOptions = [
4+ # We need to re-define our usermode network driver
5+ # since we are overriding the default value.
6+ "-net nic,netdev=user.0,model=virtio"
7+ # Than we can use qemu's hostfwd option to forward ports.
8+ "-netdev user,id=user.0,hostfwd=tcp::2222-:22"
9+ ] ;
10+ }
You can’t perform that action at this time.
0 commit comments