From 589789997fe882668eae25f1f0578230d8576506 Mon Sep 17 00:00:00 2001 From: Franz Pletz Date: Sat, 8 Feb 2020 14:55:29 +0100 Subject: [PATCH] nixos/initrd-network: always run postCommands As outlined in #71447, postCommands should always be run if networking in initrd is enabled. regardless if the configuration actually succeeded. --- nixos/modules/system/boot/initrd-network.nix | 33 +++++++------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/nixos/modules/system/boot/initrd-network.nix b/nixos/modules/system/boot/initrd-network.nix index d36850c2a16..0ab6e626b34 100644 --- a/nixos/modules/system/boot/initrd-network.nix +++ b/nixos/modules/system/boot/initrd-network.nix @@ -113,8 +113,7 @@ in for o in $(cat /proc/cmdline); do case $o in ip=*) - ipconfig $o && hasNetwork=1 \ - && ifaces="$ifaces $(echo $o | cut -d: -f6)" + ipconfig $o && ifaces="$ifaces $(echo $o | cut -d: -f6)" ;; esac done @@ -122,28 +121,20 @@ in # Otherwise, use DHCP. + optionalString doDhcp '' - if [ -z "$hasNetwork" ]; then + # Bring up all interfaces. + for iface in ${dhcpIfShellExpr}; do + echo "bringing up network interface $iface..." + ip link set "$iface" up && ifaces="$ifaces $iface" + done - # Bring up all interfaces. - for iface in ${dhcpIfShellExpr}; do - echo "bringing up network interface $iface..." - ip link set "$iface" up && ifaces="$ifaces $iface" - done - - # Acquire DHCP leases. - for iface in ${dhcpIfShellExpr}; do - echo "acquiring IP address via DHCP on $iface..." - udhcpc --quit --now -i $iface -O staticroutes --script ${udhcpcScript} ${udhcpcArgs} && hasNetwork=1 - done - fi + # Acquire DHCP leases. + for iface in ${dhcpIfShellExpr}; do + echo "acquiring IP address via DHCP on $iface..." + udhcpc --quit --now -i $iface -O staticroutes --script ${udhcpcScript} ${udhcpcArgs} + done '' - + '' - if [ -n "$hasNetwork" ]; then - echo "networking is up!" - ${cfg.postCommands} - fi - ''); + + cfg.postCommands); boot.initrd.postMountCommands = mkIf cfg.flushBeforeStage2 '' for iface in $ifaces; do