summary refs log tree commit diff
diff options
context:
space:
mode:
authordigital <132694082+digtail@users.noreply.github.com>2023-07-31 16:08:56 +0200
committerGitHub <noreply@github.com>2023-07-31 16:08:56 +0200
commit9d78971007802fc8c4a30cb9e64645b624a6e4ab (patch)
treeca47c95bdc73746ad67a6bea6aefbf73f1774906
parent70bd808e818e26175b4b82635e0ebaf523be3652 (diff)
downloadnixpkgs-9d78971007802fc8c4a30cb9e64645b624a6e4ab.tar
nixpkgs-9d78971007802fc8c4a30cb9e64645b624a6e4ab.tar.gz
nixpkgs-9d78971007802fc8c4a30cb9e64645b624a6e4ab.tar.bz2
nixpkgs-9d78971007802fc8c4a30cb9e64645b624a6e4ab.tar.lz
nixpkgs-9d78971007802fc8c4a30cb9e64645b624a6e4ab.tar.xz
nixpkgs-9d78971007802fc8c4a30cb9e64645b624a6e4ab.tar.zst
nixpkgs-9d78971007802fc8c4a30cb9e64645b624a6e4ab.zip
nixos/boot/initrd-network: add option to enable udhcpc (#240406)
In some setups, and especially with sytemd-networkd becoming more widely
used, networking.useDHCP is set to false. Despite this, it may be useful
to have dhcp in the initramfs.
-rw-r--r--nixos/doc/manual/release-notes/rl-2311.section.md2
-rw-r--r--nixos/modules/system/boot/initrd-network.nix21
2 files changed, 18 insertions, 5 deletions
diff --git a/nixos/doc/manual/release-notes/rl-2311.section.md b/nixos/doc/manual/release-notes/rl-2311.section.md
index 305d534b257..616e45918d9 100644
--- a/nixos/doc/manual/release-notes/rl-2311.section.md
+++ b/nixos/doc/manual/release-notes/rl-2311.section.md
@@ -150,6 +150,8 @@ The module update takes care of the new config syntax and the data itself (user
 
 - `wrapHelm` now exposes `passthru.pluginsDir` which can be passed to `helmfile`. For convenience, a top-level package `helmfile-wrapped` has been added, which inherits `passthru.pluginsDir` from `kubernetes-helm-wrapped`. See [#217768](https://github.com/NixOS/nixpkgs/issues/217768) for details.
 
+- `boot.initrd.network.udhcp.enable` allows control over dhcp during stage 1 regardless of what `networking.useDHCP` is set to.
+
 ## Nixpkgs internals {#sec-release-23.11-nixpkgs-internals}
 
 - The `qemu-vm.nix` module by default now identifies block devices via
diff --git a/nixos/modules/system/boot/initrd-network.nix b/nixos/modules/system/boot/initrd-network.nix
index e8bbf1d0403..1d95742face 100644
--- a/nixos/modules/system/boot/initrd-network.nix
+++ b/nixos/modules/system/boot/initrd-network.nix
@@ -7,8 +7,8 @@ let
   cfg = config.boot.initrd.network;
 
   dhcpInterfaces = lib.attrNames (lib.filterAttrs (iface: v: v.useDHCP == true) (config.networking.interfaces or {}));
-  doDhcp = config.networking.useDHCP || dhcpInterfaces != [];
-  dhcpIfShellExpr = if config.networking.useDHCP
+  doDhcp = cfg.udhcpc.enable || dhcpInterfaces != [];
+  dhcpIfShellExpr = if config.networking.useDHCP || cfg.udhcpc.enable
                       then "$(ls /sys/class/net/ | grep -v ^lo$)"
                       else lib.concatMapStringsSep " " lib.escapeShellArg dhcpInterfaces;
 
@@ -79,13 +79,24 @@ in
       '';
     };
 
+    boot.initrd.network.udhcpc.enable = mkOption {
+      default = config.networking.useDHCP;
+      defaultText = "networking.useDHCP";
+      type = types.bool;
+      description = lib.mdDoc ''
+        Enables the udhcpc service during stage 1 of the boot process. This
+        defaults to {option}`networking.useDHCP`. Therefore, this useful if
+        useDHCP is off but the initramfs should do dhcp.
+      '';
+    };
+
     boot.initrd.network.udhcpc.extraArgs = mkOption {
       default = [];
       type = types.listOf types.str;
       description = lib.mdDoc ''
-        Additional command-line arguments passed verbatim to udhcpc if
-        {option}`boot.initrd.network.enable` and {option}`networking.useDHCP`
-        are enabled.
+        Additional command-line arguments passed verbatim to
+        udhcpc if {option}`boot.initrd.network.enable` and
+        {option}`boot.initrd.network.udhcpc.enable` are enabled.
       '';
     };