networking: useNetworkd and useDHCP

I used to use the following on NixOS -unstable until today's upgrade
(admittedly, after quite a while):

  networking = {
    useDHCP = true;
    useNetworkd = true;
  }

My goal was to use systemd-networkd(8) and a generic way of enabling
DHCP for all interfaces.

As of today, useDHCP is deprecated and above config will result in an
assertion failure that recommends using disabling the global and
enabling explicit per-interface configuration for DHCP.

Thus the following amended config works

  networking = {
    useDHCP = false;
    interfaces.enp0s2.useDHCP = true;
    useNetworkd = true;
  }

but is not interface agnostic any longer. Using the first version,
would it be possible to make /etc/systemd/network/99-main.network
default to DHCP on (all) interfaces, unless explicit/more specific
interface configuration is provided?

1 Like

You might be interested in Undeprecate networking.useDHCP · Issue #75515 · NixOS/nixpkgs · GitHub and nixos-generate-config request: put in useDHCP stuff in hardware-configuration.nix · Issue #73595 · NixOS/nixpkgs · GitHub.

1 Like

My colleague @fpletz wrote a detailed explanation of the decision in Undeprecate networking.useDHCP · Issue #75515 · NixOS/nixpkgs · GitHub. However there are a few people against this, so feel free to contribute to the discussion.

Btw, nixos-generate-config can take care of this for you since nixos-generate-config: add useDHCP per interface · NixOS/nixpkgs@5ee383e · GitHub.

1 Like