diff --git a/system/options.nix b/system/options.nix index d0831473ce7..4628fae2c54 100644 --- a/system/options.nix +++ b/system/options.nix @@ -31,7 +31,10 @@ let in { - + require = [ + # newtworking + (import ../upstart-jobs/dhclient.nix) + ] time = { @@ -376,30 +379,6 @@ in ''; }; - useDHCP = mkOption { - default = true; - description = " - Whether to use DHCP to obtain an IP adress and other - configuration for all network interfaces that are not manually - configured. - "; - }; - - interfaces = mkOption { - default = []; - example = [ - { name = "eth0"; - ipAddress = "131.211.84.78"; - subnetMask = "255.255.255.128"; - } - ]; - description = " - The configuration for each network interface. If - is true, then each interface - not listed here will be configured using DHCP. - "; - }; - defaultGateway = mkOption { default = ""; example = "131.211.84.1"; diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index b67cfa77ea7..e7cf35133c6 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -177,13 +177,6 @@ let config = config.services.atd; }) - # DHCP client. - ++ optional config.networking.useDHCP - (import ../upstart-jobs/dhclient.nix { - inherit (pkgs) nettools dhcp lib; - interfaces = config.networking.interfaces; - }) - # ifplugd daemon for monitoring Ethernet cables. ++ optional config.networking.interfaceMonitor.enable (import ../upstart-jobs/ifplugd.nix { diff --git a/upstart-jobs/dhclient.nix b/upstart-jobs/dhclient.nix index 3f198d44d2d..f72f2b7fe43 100644 --- a/upstart-jobs/dhclient.nix +++ b/upstart-jobs/dhclient.nix @@ -1,21 +1,71 @@ -{dhcp, nettools, interfaces, lib}: +{pkgs, config, ...}: -let +###### interface +let + inherit (pkgs.lib) mkOption + mergeEnableOption mergeListOption; + + options = { + networking = { + useDHCP = mkOption { + default = true; + merge = mergeEnableOption; + description = " + Whether to use DHCP to obtain an IP adress and other + configuration for all network interfaces that are not manually + configured. + "; + }; + + interfaces = mkOption { + default = []; + merge = mergeListOption; + example = [ + { name = "eth0"; + ipAddress = "131.211.84.78"; + subnetMask = "255.255.255.128"; + } + ]; + description = " + The configuration for each network interface. If + is true, then each interface + not listed here will be configured using DHCP. + "; + }; + }; + }; +in + +###### implementation +let + ifEnable = arg: + if config.networking.useDHCP then arg + else if builtins.isList arg then [] + else if builtins.isAttrs arg then {} + else null; + + inherit (pkgs) nettools dhcp lib; # Don't start dhclient on explicitly configured interfaces. ignoredInterfaces = ["lo"] ++ map (i: i.name) (lib.filter (i: i ? ipAddress) interfaces); stateDir = "/var/lib/dhcp"; # Don't use /var/state/dhcp; not FHS-compliant. - in { - name = "dhclient"; + require = [ + # (import ../upstart-jobs/default.nix) + options + ]; - extraPath = [dhcp]; + services = { + extraJobs = IfEnable [{ + name = "dhclient"; + + extraPath = [dhcp]; - job = " + job = " description \"DHCP client\" start on network-interfaces/started @@ -45,6 +95,8 @@ script exec ${dhcp}/sbin/dhclient -d $interfaces -e \"PATH=$PATH\" -lf ${stateDir}/dhclient.leases end script - "; - + "; + }]; + }; } +