From 24597e9460e8c9dda666b20843e54f3c44d5007e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C6=B0=C6=A1ng=20Vi=E1=BB=87t=20Ho=C3=A0ng?= Date: Thu, 3 Oct 2024 15:52:32 +0700 Subject: [PATCH] nixos/network-interfaces-systemd: improve default ethernet network matching Reliably match physical ethernet interfaces by using `Kind=!*` with `Type=ether`. This will exclude veth interfaces, which have `Kind=veth`. --- .../tasks/network-interfaces-systemd.nix | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/nixos/modules/tasks/network-interfaces-systemd.nix b/nixos/modules/tasks/network-interfaces-systemd.nix index c1241d11de87..0f85c69428ca 100644 --- a/nixos/modules/tasks/network-interfaces-systemd.nix +++ b/nixos/modules/tasks/network-interfaces-systemd.nix @@ -45,25 +45,14 @@ let genericDhcpNetworks = initrd: mkIf cfg.useDHCP { networks."99-ethernet-default-dhcp" = { - # We want to match physical ethernet interfaces as commonly - # found on laptops, desktops and servers, to provide an - # "out-of-the-box" setup that works for common cases. This - # heuristic isn't perfect (it could match interfaces with - # custom names that _happen_ to start with en or eth), but - # should be good enough to make the common case easy and can - # be overridden on a case-by-case basis using - # higher-priority networks or by disabling useDHCP. - - # Type=ether matches veth interfaces as well, and this is - # more likely to result in interfaces being configured to - # use DHCP when they shouldn't. - - matchConfig.Name = ["en*" "eth*"]; + matchConfig = { + Type = "ether"; + Kind = "!*"; # physical interfaces have no kind + }; DHCP = "yes"; networkConfig.IPv6PrivacyExtensions = "kernel"; }; networks."99-wireless-client-dhcp" = { - # Like above, but this is much more likely to be correct. matchConfig.WLANInterfaceType = "station"; DHCP = "yes"; networkConfig.IPv6PrivacyExtensions = "kernel";