diff options
| author | tv <tv@krebsco.de> | 2026-11-16 00:39:36 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-16 00:39:36 +0000 |
| commit | c572066f87d0eda6e236373a451d15b24365b666 (patch) | |
| tree | 5af8a44474cd3a17df3922767cf67aa6f159e696 | |
| parent | 0c2dcfdadcf863fb7fd1be2c99cf53685e40dfef (diff) | |
add networking
Give the guest a virtio-net interface backed by the host tap device
fctap0, with a static address (172.16.0.2/24, gateway 172.16.0.1) set up
by systemd-networkd, and 9.9.9.9 as nameserver.
host.nix is a NixOS module for the host that creates fctap0, owned by
the given user, and NATs it:
imports = [ (import ./host.nix "tv") ];
Firecracker refuses to start if fctap0 doesn't exist.
| -rw-r--r-- | default.nix | 15 | ||||
| -rw-r--r-- | host.nix | 15 |
2 files changed, 30 insertions, 0 deletions
diff --git a/default.nix b/default.nix index 6bb6d08..043c874 100644 --- a/default.nix +++ b/default.nix @@ -35,6 +35,15 @@ let services.getty.autologinUser = "root"; networking.useDHCP = false; + networking.resolvconf.enable = false; + environment.etc."resolv.conf".text = "nameserver 9.9.9.9\n"; + systemd.network.enable = true; + systemd.network.wait-online.enable = false; + systemd.network.networks.eth = { + matchConfig.Type = "ether"; + address = [ "172.16.0.2/24" ]; + gateway = [ "172.16.0.1" ]; + }; boot.bcache.enable = false; boot.enableContainers = false; @@ -49,6 +58,7 @@ let services.fstrim.enable = false; services.lvm.enable = false; services.nscd.enable = false; + services.resolved.enable = false; services.timesyncd.enable = false; system.nssModules = lib.mkForce [ ]; system.switch.enable = false; @@ -67,6 +77,11 @@ let initrd_path = "${initialRamdisk}/${nixos.config.system.boot.loader.initrdFile}"; boot_args = toString (nixos.config.boot.kernelParams ++ [ "init=${toplevel}/init" ]); }; + network-interfaces = [{ + iface_id = "eth0"; + host_dev_name = "fctap0"; # see host.nix + guest_mac = "06:00:ac:10:00:02"; + }]; drives = [{ drive_id = "store"; path_on_host = "@STORE_IMAGE@"; diff --git a/host.nix b/host.nix new file mode 100644 index 0000000..3368677 --- /dev/null +++ b/host.nix @@ -0,0 +1,15 @@ +# Host side of the guest's network: a tap device owned by the user running +# the VM, NATed to the outside world. +# usage (in the host's configuration.nix): imports = [ (import ./host.nix "tv") ]; +user: { + networking.interfaces.fctap0 = { + virtual = true; + virtualType = "tap"; + virtualOwner = user; + ipv4.addresses = [{ address = "172.16.0.1"; prefixLength = 24; }]; + }; + networking.nat = { + enable = true; + internalInterfaces = [ "fctap0" ]; + }; +} |
