Skip to content

Commit 65489e7

Browse files
authored
Merge pull request #68 from brianmcgee/fix/vm-forward-example
fix: vm-forward example
2 parents 2cb7687 + 5ee6d68 commit 65489e7

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,12 @@ Or switch to qemu console with `Ctrl-a c` and type:
8585

8686
## Port forwarding
8787

88-
To forward ports from the virtual machine to the host, override the
89-
`virtualisation.qemu.networkingOptions` NixOS option.
88+
To forward ports from the virtual machine to the host, use the
89+
`virtualisation.forwardPorts` NixOS option.
9090
See `examples/vm-forward.nix` where the ssh server running on port 22 in the
9191
virtual machine is made accessible through port 2222 on the host.
9292

93-
If `virtualisation.qemu.networkingOptions` is not overridden the same can be
94-
also achieved by using the `QEMU_NET_OPTS` environment variable.
93+
The same can be also achieved by using the `QEMU_NET_OPTS` environment variable.
9594

9695
```console
9796
$ QEMU_NET_OPTS="hostfwd=tcp::2222-:22" nixos-shell

examples/vm-forward.nix

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{ pkgs, ... }: {
22
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-
];
3+
virtualisation = {
4+
forwardPorts = [
5+
{ from = "host"; host.port = 2222; guest.port = 22; }
6+
];
7+
};
8+
109
}

0 commit comments

Comments
 (0)