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`.
This commit is contained in:
Lương Việt Hoàng 2024-10-03 15:52:32 +07:00
parent 8ea3363046
commit 24597e9460

View File

@ -45,25 +45,14 @@ let
genericDhcpNetworks = initrd: mkIf cfg.useDHCP { genericDhcpNetworks = initrd: mkIf cfg.useDHCP {
networks."99-ethernet-default-dhcp" = { networks."99-ethernet-default-dhcp" = {
# We want to match physical ethernet interfaces as commonly matchConfig = {
# found on laptops, desktops and servers, to provide an Type = "ether";
# "out-of-the-box" setup that works for common cases. This Kind = "!*"; # physical interfaces have no kind
# 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*"];
DHCP = "yes"; DHCP = "yes";
networkConfig.IPv6PrivacyExtensions = "kernel"; networkConfig.IPv6PrivacyExtensions = "kernel";
}; };
networks."99-wireless-client-dhcp" = { networks."99-wireless-client-dhcp" = {
# Like above, but this is much more likely to be correct.
matchConfig.WLANInterfaceType = "station"; matchConfig.WLANInterfaceType = "station";
DHCP = "yes"; DHCP = "yes";
networkConfig.IPv6PrivacyExtensions = "kernel"; networkConfig.IPv6PrivacyExtensions = "kernel";