diff --git a/system/upstart.nix b/system/upstart.nix index 71affda04ac..194b6bdb8e1 100644 --- a/system/upstart.nix +++ b/system/upstart.nix @@ -93,7 +93,8 @@ import ../upstart-jobs/gather.nix { # DHCP client. ++ optional ["networking" "useDHCP"] (import ../upstart-jobs/dhclient.nix { - inherit (pkgs) nettools dhcp; + inherit (pkgs) nettools dhcp lib; + interfaces = config.get ["networking" "interfaces"]; }) # SSH daemon. diff --git a/upstart-jobs/dhclient.nix b/upstart-jobs/dhclient.nix index 73f80528c55..41fa887f7c6 100644 --- a/upstart-jobs/dhclient.nix +++ b/upstart-jobs/dhclient.nix @@ -1,4 +1,12 @@ -{dhcp, nettools}: +{dhcp, nettools, interfaces, lib}: + +let + + # Don't start dhclient on explicitly configured interfaces. + ignoredInterfaces = ["lo"] ++ + map (i: i.name) (lib.filter (i: i ? ipAddress) interfaces); + +in { name = "dhclient"; @@ -18,7 +26,7 @@ script interfaces= for i in $(cd /sys/class/net && ls -d *); do - if test \"$i\" != \"lo\"; then + if ! for j in ${toString ignoredInterfaces}; do echo $j; done | grep -F -x -q \"$i\"; then echo \"Running dhclient on $i\" interfaces=\"$interfaces $i\" fi