How to use systemd-resolved, iwd and systemd-networkd

I want to use systemd-networkd and iwd instead of networkamanger. And setup systemd-resolved as well. In normal distros, I just create a netwok file defining the name of the interface (wlan0 for wifi or en* for ethernet) . And for systemd-resolved, just link the /etd/resolv.conf to some resolv.conf. I enable the services: systemd-networkd.service, systemd-resolved.networkd and iwd.service after that.

SIde note: my ethernet interface gets read as wwp0s20f0u1 (USB Tethering from phone) and not as en* something. In other distros it used to get read as enp* something like that.

This is my networking.nix, currently working internet.

{lib, ...} : {
  networking = {
    # useNetworkd = true;
    useDHCP = false;
    # Refer this https://mynixos.com/nixpkgs/option/networking.hostName
    # For properly setting your hostname
    hostName = "hppavilion"; # Define your hostname.
    #networkmanager = {
    #  enable = true;
    #  wifi = {
    #    backend = "iwd";
    #  };
    #};
    wireless.iwd = {
      enable = true;
      settings = {
        Settings.AutoConnect = true;
      };
    };
  };
  systemd = {
    network = {
      enable = true;
      networks = {
        "50-dhcp" = {
          matchConfig.Name = "en*";
          networkConfig.DHCP = "yes";
          linkConfig.RequiredForOnline = "no";
        };

        "50-wireless" = {
          matchConfig.Name = "wlan0";
          networkConfig = {
            DHCP = "yes";
            IgnoreCarrierLoss = "3s";
          };
        };
      };
    };
  };
  services = {
    resolved = {
      enable = true;
    };
  };
}

What is the difference between networking.useNetworkd and system.network.enable?

networking.useNetworkd = true; means that the options declared in network-interfaces.nix (like networking.interfaces and networking.bridges) will be implemented using systemd-networkd instead of a bunch of scripts. Whereas systemd.network.enable = true; just enables systemd-networkd and allows you to configure it with systemd.network.* but leaves those network-interfaces.nix options implemented by scripts.

3 Likes

So which one should I go for?