diff options
author | Matthew Bauer <mjbauer95@gmail.com> | 2018-10-05 22:47:45 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-05 22:47:45 -0500 |
commit | 357d32e2b3ed6557fc250b0d4b6791992ded526a (patch) | |
tree | 1427f4e7a851fb65f14f432c89c600fc9eeb9979 | |
parent | bb0c421ca1e3d67fc361cb59c30d0ce5546fe75d (diff) | |
parent | 16edfb22b814bf689a112de978bae97c334dd5e0 (diff) | |
download | nixlib-357d32e2b3ed6557fc250b0d4b6791992ded526a.tar nixlib-357d32e2b3ed6557fc250b0d4b6791992ded526a.tar.gz nixlib-357d32e2b3ed6557fc250b0d4b6791992ded526a.tar.bz2 nixlib-357d32e2b3ed6557fc250b0d4b6791992ded526a.tar.lz nixlib-357d32e2b3ed6557fc250b0d4b6791992ded526a.tar.xz nixlib-357d32e2b3ed6557fc250b0d4b6791992ded526a.tar.zst nixlib-357d32e2b3ed6557fc250b0d4b6791992ded526a.zip |
Merge pull request #46459 from volth/volth-patch-3
nixos/initrd-network: multiple DHCP fixes
-rw-r--r-- | nixos/modules/system/boot/initrd-network.nix | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/nixos/modules/system/boot/initrd-network.nix b/nixos/modules/system/boot/initrd-network.nix index 384ae909b701..dd0ea69e9685 100644 --- a/nixos/modules/system/boot/initrd-network.nix +++ b/nixos/modules/system/boot/initrd-network.nix @@ -6,11 +6,22 @@ let cfg = config.boot.initrd.network; + dhcpinterfaces = lib.attrNames (lib.filterAttrs (iface: v: v.useDHCP == true) (config.networking.interfaces or {})); + udhcpcScript = pkgs.writeScript "udhcp-script" '' #! /bin/sh if [ "$1" = bound ]; then ip address add "$ip/$mask" dev "$interface" + if [ -n "$mtu" ]; then + ip link set mtu "$mtu" dev "$interface" + fi + if [ -n "$staticroutes" ]; then + echo "$staticroutes" \ + | sed -r "s@(\S+) (\S+)@ ip route add \"\1\" via \"\2\" dev \"$interface\" ; @g" \ + | sed -r "s@ via \"0\.0\.0\.0\"@@g" \ + | /bin/sh + fi if [ -n "$router" ]; then ip route add "$router" dev "$interface" # just in case if "$router" is not within "$ip/$mask" (e.g. Hetzner Cloud) ip route add default via "$router" dev "$interface" @@ -93,18 +104,24 @@ in '' # Otherwise, use DHCP. - + optionalString config.networking.useDHCP '' + + optionalString (config.networking.useDHCP || dhcpinterfaces != []) '' if [ -z "$hasNetwork" ]; then # Bring up all interfaces. - for iface in $(cd /sys/class/net && ls); do + for iface in $(ls /sys/class/net/); do echo "bringing up network interface $iface..." ip link set "$iface" up done - # Acquire a DHCP lease. - echo "acquiring IP address via DHCP..." - udhcpc --quit --now --script ${udhcpcScript} ${udhcpcArgs} && hasNetwork=1 + # Acquire DHCP leases. + for iface in ${ if config.networking.useDHCP then + "$(ls /sys/class/net/ | grep -v ^lo$)" + else + lib.concatMapStringsSep " " lib.escapeShellArg dhcpinterfaces + }; do + echo "acquiring IP address via DHCP on $iface..." + udhcpc --quit --now -i $iface -O staticroutes --script ${udhcpcScript} ${udhcpcArgs} && hasNetwork=1 + done fi '' |