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

nixos/network-interfaces-systemd: fix DHCP setting

Changed files
+14 -10
nixos
+1 -1
nixos/modules/tasks/network-interfaces-systemd.nix
···
networks."40-${i.name}" = mkMerge [ (genericNetwork id) {
name = mkDefault i.name;
DHCP = mkForce (dhcpStr
-
(if i.useDHCP != null then i.useDHCP else false));
address = forEach (interfaceIps i)
(ip: "${ip.address}/${toString ip.prefixLength}");
routes = forEach (interfaceRoutes i)
···
networks."40-${i.name}" = mkMerge [ (genericNetwork id) {
name = mkDefault i.name;
DHCP = mkForce (dhcpStr
+
(if i.useDHCP != null then i.useDHCP else (config.networking.useDHCP && i.ipv4.addresses == [ ])));
address = forEach (interfaceIps i)
(ip: "${ip.address}/${toString ip.prefixLength}");
routes = forEach (interfaceRoutes i)
+8 -8
nixos/modules/tasks/network-interfaces.nix
···
type = types.nullOr types.bool;
default = null;
description = lib.mdDoc ''
-
Whether this interface should be configured with dhcp.
-
Null implies the old behavior which depends on whether ip addresses
-
are specified or not.
'';
};
···
} ];
};
description = lib.mdDoc ''
-
The configuration for each network interface. If
-
{option}`networking.useDHCP` is true, then every
-
interface not listed here will be configured using DHCP.
Please note that {option}`systemd.network.netdevs` has more features
and is better maintained. When building new things, it is advised to
···
default = true;
description = lib.mdDoc ''
Whether to use DHCP to obtain an IP address and other
-
configuration for all network interfaces that are not manually
-
configured.
'';
};
···
type = types.nullOr types.bool;
default = null;
description = lib.mdDoc ''
+
Whether this interface should be configured with DHCP. Overrides the
+
default set by {option}`networking.useDHCP`. If `null` (the default),
+
DHCP is enabled if the interface has no IPv4 addresses configured
+
with {option}`networking.interfaces.<name>.ipv4.addresses`, and
+
disabled otherwise.
'';
};
···
} ];
};
description = lib.mdDoc ''
+
The configuration for each network interface.
Please note that {option}`systemd.network.netdevs` has more features
and is better maintained. When building new things, it is advised to
···
default = true;
description = lib.mdDoc ''
Whether to use DHCP to obtain an IP address and other
+
configuration for all network interfaces that do not have any manually
+
configured IPv4 addresses.
'';
};
+5 -1
nixos/tests/networking.nix
···
nodes.router = router;
nodes.client = { lib, ... }: {
# Disable test driver default config
-
networking.interfaces = lib.mkForce {};
networking.useNetworkd = networkd;
virtualisation.interfaces.enp1s0.vlan = 1;
};
···
nodes.router = router;
nodes.client = { lib, ... }: {
# Disable test driver default config
+
networking.interfaces = lib.mkForce {
+
# Make sure DHCP defaults correctly even when some unrelated config
+
# is set on the interface (nothing, in this case).
+
enp1s0 = {};
+
};
networking.useNetworkd = networkd;
virtualisation.interfaces.enp1s0.vlan = 1;
};