diff --git a/system/options.nix b/system/options.nix index fdb224b6788d..53a3d11d7f66 100644 --- a/system/options.nix +++ b/system/options.nix @@ -245,29 +245,6 @@ in "; }; - interfaceMonitor = { - - enable = mkOption { - default = false; - description = " - If true, monitor Ethernet interfaces for - cables being plugged in or unplugged. When this occurs, the - dhclient service is restarted to - automatically obtain a new IP address. This is useful for - roaming users (laptops). - "; - }; - - beep = mkOption { - default = false; - description = " - If true, beep when an Ethernet cable is - plugged in or unplugged. - "; - }; - - }; - defaultMailServer = { directDelivery = mkOption { @@ -428,6 +405,7 @@ in (import ../upstart-jobs/maintenance-shell.nix) # Handles the maintenance/stalled event (single-user shell). (import ../upstart-jobs/ctrl-alt-delete.nix) # Ctrl-alt-delete action. (import ../upstart-jobs/halt.nix) # FIXME (assertion) # Handles the reboot/halt events. + (import ../upstart-jobs/ifplugd.nix) # ifplugd daemon for monitoring Ethernet cables. # security diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index 85c5622bf4d8..57f0006eb8a3 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -70,13 +70,6 @@ let jobs = map makeJob [] - # ifplugd daemon for monitoring Ethernet cables. - ++ optional config.networking.interfaceMonitor.enable - (import ../upstart-jobs/ifplugd.nix { - inherit (pkgs) ifplugd writeScript bash; - inherit config; - }) - # User-defined events. ++ (map makeJob (config.services.extraJobs)); diff --git a/upstart-jobs/ifplugd.nix b/upstart-jobs/ifplugd.nix index 4536ee8b41e5..c1b9c4e56204 100644 --- a/upstart-jobs/ifplugd.nix +++ b/upstart-jobs/ifplugd.nix @@ -1,7 +1,42 @@ -{ifplugd, config, writeScript, bash}: +{pkgs, config, ...}: + +###### interface +let + inherit (pkgs.lib) mkOption mkIf; + + options = { + networking = { + interfaceMonitor = { + + enable = mkOption { + default = false; + description = " + If true, monitor Ethernet interfaces for + cables being plugged in or unplugged. When this occurs, the + dhclient service is restarted to + automatically obtain a new IP address. This is useful for + roaming users (laptops). + "; + }; + + beep = mkOption { + default = false; + description = " + If true, beep when an Ethernet cable is + plugged in or unplugged. + "; + }; + }; + }; + }; +in + +###### implementation let + inherit (pkgs) ifplugd writeScript bash; + # The ifplugd action script, which is called whenever the link # status changes (i.e., a cable is plugged in or unplugged). We do # nothing when a cable is unplugged. When a cable is plugged in, we @@ -17,19 +52,27 @@ let in -{ - name = "ifplugd"; +mkIf config.networking.interfaceMonitor.enable { + require = [ + options + ]; - extraPath = [ifplugd]; - - job = " -description \"Network interface connectivity monitor\" + services = { + extraJobs = [{ + name = "ifplugd"; -start on network-interfaces/started -stop on network-interfaces/stop + extraPath = [ifplugd]; + + job = '' + description "Network interface connectivity monitor" -respawn ${ifplugd}/sbin/ifplugd --no-daemon --no-startup --no-shutdown \\ - ${if config.networking.interfaceMonitor.beep then "" else "--no-beep"} \\ - --run ${plugScript}"; - + start on network-interfaces/started + stop on network-interfaces/stop + + respawn ${ifplugd}/sbin/ifplugd --no-daemon --no-startup --no-shutdown \ + ${if config.networking.interfaceMonitor.beep then "" else "--no-beep"} \ + --run ${plugScript} + ''; + }]; + }; }