lol

Merge pull request #259619 from Majiir/fix-networkd-dhcp

nixos/network-interfaces-systemd: fix DHCP setting

authored by

Maximilian Bosch and committed by
GitHub
632cfff2 050726bf

+14 -10
+1 -1
nixos/modules/tasks/network-interfaces-systemd.nix
··· 89 89 networks."40-${i.name}" = mkMerge [ (genericNetwork id) { 90 90 name = mkDefault i.name; 91 91 DHCP = mkForce (dhcpStr 92 - (if i.useDHCP != null then i.useDHCP else false)); 92 + (if i.useDHCP != null then i.useDHCP else (config.networking.useDHCP && i.ipv4.addresses == [ ]))); 93 93 address = forEach (interfaceIps i) 94 94 (ip: "${ip.address}/${toString ip.prefixLength}"); 95 95 routes = forEach (interfaceRoutes i)
+8 -8
nixos/modules/tasks/network-interfaces.nix
··· 190 190 type = types.nullOr types.bool; 191 191 default = null; 192 192 description = lib.mdDoc '' 193 - Whether this interface should be configured with dhcp. 194 - Null implies the old behavior which depends on whether ip addresses 195 - are specified or not. 193 + Whether this interface should be configured with DHCP. Overrides the 194 + default set by {option}`networking.useDHCP`. If `null` (the default), 195 + DHCP is enabled if the interface has no IPv4 addresses configured 196 + with {option}`networking.interfaces.<name>.ipv4.addresses`, and 197 + disabled otherwise. 196 198 ''; 197 199 }; 198 200 ··· 640 642 } ]; 641 643 }; 642 644 description = lib.mdDoc '' 643 - The configuration for each network interface. If 644 - {option}`networking.useDHCP` is true, then every 645 - interface not listed here will be configured using DHCP. 645 + The configuration for each network interface. 646 646 647 647 Please note that {option}`systemd.network.netdevs` has more features 648 648 and is better maintained. When building new things, it is advised to ··· 1304 1304 default = true; 1305 1305 description = lib.mdDoc '' 1306 1306 Whether to use DHCP to obtain an IP address and other 1307 - configuration for all network interfaces that are not manually 1308 - configured. 1307 + configuration for all network interfaces that do not have any manually 1308 + configured IPv4 addresses. 1309 1309 ''; 1310 1310 }; 1311 1311
+5 -1
nixos/tests/networking.nix
··· 185 185 nodes.router = router; 186 186 nodes.client = { lib, ... }: { 187 187 # Disable test driver default config 188 - networking.interfaces = lib.mkForce {}; 188 + networking.interfaces = lib.mkForce { 189 + # Make sure DHCP defaults correctly even when some unrelated config 190 + # is set on the interface (nothing, in this case). 191 + enp1s0 = {}; 192 + }; 189 193 networking.useNetworkd = networkd; 190 194 virtualisation.interfaces.enp1s0.vlan = 1; 191 195 };