summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2023-10-14 20:47:36 +0200
committerGitHub <noreply@github.com>2023-10-14 20:47:36 +0200
commit632cfff25741c2cff9d22164bcb141cb7ca6f7af (patch)
treedab3e858644146e2c3b91973526e0b5f1526ef23 /nixos
parent050726bf76a666731c8116b555b1ef88f65865da (diff)
parentc4228b6c8f662a3e3022c187ec40f4debafbd454 (diff)
downloadnixpkgs-632cfff25741c2cff9d22164bcb141cb7ca6f7af.tar
nixpkgs-632cfff25741c2cff9d22164bcb141cb7ca6f7af.tar.gz
nixpkgs-632cfff25741c2cff9d22164bcb141cb7ca6f7af.tar.bz2
nixpkgs-632cfff25741c2cff9d22164bcb141cb7ca6f7af.tar.lz
nixpkgs-632cfff25741c2cff9d22164bcb141cb7ca6f7af.tar.xz
nixpkgs-632cfff25741c2cff9d22164bcb141cb7ca6f7af.tar.zst
nixpkgs-632cfff25741c2cff9d22164bcb141cb7ca6f7af.zip
Merge pull request #259619 from Majiir/fix-networkd-dhcp
nixos/network-interfaces-systemd: fix DHCP setting
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/tasks/network-interfaces-systemd.nix2
-rw-r--r--nixos/modules/tasks/network-interfaces.nix16
-rw-r--r--nixos/tests/networking.nix6
3 files changed, 14 insertions, 10 deletions
diff --git a/nixos/modules/tasks/network-interfaces-systemd.nix b/nixos/modules/tasks/network-interfaces-systemd.nix
index 53097e21c64..6912f671216 100644
--- a/nixos/modules/tasks/network-interfaces-systemd.nix
+++ b/nixos/modules/tasks/network-interfaces-systemd.nix
@@ -89,7 +89,7 @@ let
     networks."40-${i.name}" = mkMerge [ (genericNetwork id) {
       name = mkDefault i.name;
       DHCP = mkForce (dhcpStr
-        (if i.useDHCP != null then i.useDHCP else false));
+        (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)
diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix
index eda036cb726..cd0de51a6e0 100644
--- a/nixos/modules/tasks/network-interfaces.nix
+++ b/nixos/modules/tasks/network-interfaces.nix
@@ -190,9 +190,11 @@ let
         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.
+          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.
         '';
       };
 
@@ -640,9 +642,7 @@ in
           } ];
         };
       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.
+        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
@@ -1304,8 +1304,8 @@ in
       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.
+        configuration for all network interfaces that do not have any manually
+        configured IPv4 addresses.
       '';
     };
 
diff --git a/nixos/tests/networking.nix b/nixos/tests/networking.nix
index 46fc715d089..4d8b4c985c6 100644
--- a/nixos/tests/networking.nix
+++ b/nixos/tests/networking.nix
@@ -185,7 +185,11 @@ let
       nodes.router = router;
       nodes.client = { lib, ... }: {
         # Disable test driver default config
-        networking.interfaces = lib.mkForce {};
+        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;
       };