NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.75k stars 13.87k forks source link

systemd-networkd does not survive reboot #318127

Open grindhold opened 4 months ago

grindhold commented 4 months ago

Describe the bug

A clear and concise description of what the bug is.

Steps To Reproduce

Steps to reproduce the behavior: I have a machine running the nixos config posted below. On reboot it fails to load systemd-networkd or rather reports the service isn't even there. when i redeploy the machine, everything works fine. the machine config is part of a flake that i deploy from a remote machien.

# After Reboot

[grindhold@xxx:~]$ networkctl
systemd-networkd is not running, output might be incomplete.
IDX LINK TYPE     OPERATIONAL SETUP
  1 lo   loopback -           unmanaged
  2 ens3 ether    -           unmanaged

2 links listed.

[grindhold@xxx:~]$ systemctl status systemd-networkd
Unit systemd-networkd.service could not be found.

# After re-deploying the config

[grindhold@xxx:~]$ systemctl status systemd-networkd
● systemd-networkd.service - Network Configuration
     Loaded: loaded (/etc/systemd/system/systemd-networkd.service; enabled; preset: enabled)
    Drop-In: /nix/store/xf7w4qsaqb5klgrmmbxc375f64g38bfg-system-units/systemd-networkd.service.d
             └─overrides.conf
     Active: active (running) since Sat 2024-06-08 01:02:02 CEST; 31s ago
TriggeredBy: ● systemd-networkd.socket
       Docs: man:systemd-networkd.service(8)
             man:org.freedesktop.network1(5)
   Main PID: 1651 (systemd-network)
     Status: "Processing requests..."
         IP: 64B in, 56B out
         IO: 1.7M read, 0B written
      Tasks: 1 (limit: 2353)
   FD Store: 0 (limit: 512)
     Memory: 3.4M
        CPU: 95ms

[grindhold@xxx:~]$ networkctl
IDX LINK    TYPE     OPERATIONAL SETUP
  1 lo      loopback carrier     unmanaged
  2 ens3    ether    enslaved    configured
  4 vmnet   bridge   routable    configured
  5 vb-mail ether    enslaved    configured

4 links listed.

Expected behavior

It should load systemd-networkd on boot.

Additional context

I have the following network-relevant code in my config

let
    netinfo = import ./netinfo.nix;
    dnsinfo = import ../../dns.nix;
in
{
  # [ … ]
  networking.useDHCP = false;

  services.resolved.enable = false;

  networking.nameservers = [ "46.38.225.230" "46.38.252.230"];

  networking.nat = {
    enable = true;
    enableIPv6 = true;
    internalIPs = ["${netinfo.local4}.0.0/16"];
    externalIP = "${netinfo.public4}";
    internalIPv6s = ["${netinfo.public6}::/64"];
    externalIPv6 = "${netinfo.public6}::1";
    externalInterface = "vmnet";
    forwardPorts = [
      {
        sourcePort = 465;
        proto = "tcp";
        destination = "${netinfo.local4}.0.3:465";
      }
      {
        sourcePort = 587;
        proto = "tcp";
        destination = "${netinfo.local4}.0.3:587";
      }
      {
        sourcePort = 465;
        proto = "tcp";
        destination = "[${netinfo.public6}::3]:465";
      }
      {
        sourcePort = 587;
        proto = "tcp";
        destination = "[${netinfo.public6}::3]:587";
      }
    ];
  };

  systemd.network.enable = true;

  systemd.network.netdevs."10-vmnet" = {
    netdevConfig = {
      Kind = "bridge";
      Name = "vmnet";
      MACAddress = netinfo.mac;
    };
  };
  systemd.network.networks."11-vmnet" = {
    matchConfig.Name = "vmnet";
    addresses =  [ 
      { addressConfig.Address = "${netinfo.public4}/22";}
      { addressConfig.Address = "${netinfo.local4}.0.1/16";}
      { addressConfig.Address = "${netinfo.local6}::1/64";}
      { addressConfig.Address = "${netinfo.public6}::1/64";}
    ];
    routes = [
      {
        routeConfig.Gateway = "${netinfo.gateway4}";
      }
    ];
  };
  systemd.network.links."19-wired" = {
    matchConfig.Name = "${netinfo.nicname}";
    linkConfig = {
      Name = "${netinfo.nicname}";
      Description = "WAN link";
    };
  };
  systemd.network.networks."20-bridging" = {
    matchConfig.Name = "${netinfo.nicname}";
    networkConfig = {
      Bridge="vmnet";
    };
    linkConfig.RequiredForOnline = "enslaved";
  };

  systemd.network.wait-online.ignoredInterfaces = [ "vmnet"  ];
}
eclairevoyant commented 4 months ago

any funny stuff like impermanence / root on tmpfs, etc?