From ac4bfcc965cdfac64b563874529a2b8135663e47 Mon Sep 17 00:00:00 2001 From: Christoph Heiss Date: Sat, 21 Dec 2024 16:31:11 +0100 Subject: [PATCH] nixos/initrd-network: add option for enabling udhcpc6 support Currently, having stage1 get an IPv6 address from a DHCPv6 server is not possible, which esp. presents itself as an problem in IPv6 networks/deployments. Signed-off-by: Christoph Heiss --- nixos/modules/system/boot/initrd-network.nix | 38 ++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/nixos/modules/system/boot/initrd-network.nix b/nixos/modules/system/boot/initrd-network.nix index 17929761936726..9b7ebf6aa7a5cf 100644 --- a/nixos/modules/system/boot/initrd-network.nix +++ b/nixos/modules/system/boot/initrd-network.nix @@ -15,8 +15,9 @@ let lib.filterAttrs (iface: v: v.useDHCP == true) (config.networking.interfaces or { }) ); doDhcp = cfg.udhcpc.enable || dhcpInterfaces != [ ]; + doDhcp6 = cfg.udhcpc6.enable || dhcpInterfaces != [ ]; dhcpIfShellExpr = - if config.networking.useDHCP || cfg.udhcpc.enable then + if config.networking.useDHCP || cfg.udhcpc.enable || cfg.udhcpc6.enable then "$(ls /sys/class/net/ | grep -v ^lo$)" else lib.concatMapStringsSep " " lib.escapeShellArg dhcpInterfaces; @@ -48,6 +49,7 @@ let ''; udhcpcArgs = toString cfg.udhcpc.extraArgs; + udhcpc6Args = toString cfg.udhcpc6.extraArgs; in @@ -108,6 +110,25 @@ in ''; }; + boot.initrd.network.udhcpc6.enable = mkOption { + default = false; + type = types.bool; + description = '' + Enables the udhcpc6 service during stage 1 of the boot process. This + defaults to `false`. + ''; + }; + + boot.initrd.network.udhcpc6.extraArgs = mkOption { + default = [ ]; + type = types.listOf types.str; + description = '' + Additional command-line arguments passed verbatim to udhcpc6 if + {option}`boot.initrd.network.enable` and + {option}`boot.initrd.network.udhcpc6.enable` are enabled. + ''; + }; + boot.initrd.network.postCommands = mkOption { default = ""; type = types.lines; @@ -141,14 +162,16 @@ in done '' - # Otherwise, use DHCP. - + optionalString doDhcp '' + + optionalString (doDhcp || doDhcp6) '' # Bring up all interfaces. for iface in ${dhcpIfShellExpr}; do echo "bringing up network interface $iface..." ip link set dev "$iface" up && ifaces="$ifaces $iface" done + '' + # Otherwise, use DHCP .. + + optionalString doDhcp '' # Acquire DHCP leases. for iface in ${dhcpIfShellExpr}; do echo "acquiring IP address via DHCP on $iface..." @@ -156,6 +179,15 @@ in done '' + # .. and/or DHCPv6 + + optionalString doDhcp6 '' + # Acquire DHCP leases. + for iface in ${dhcpIfShellExpr}; do + echo "acquiring IP address via DHCP on $iface..." + udhcpc6 --quit --now -i $iface --script ${udhcpcScript} ${udhcpc6Args} + done + '' + + cfg.postCommands ) );