3
0
Fork 0
forked from mirrors/nixpkgs

Convert "ifplugd" (interfaceMonitor)

svn path=/nixos/branches/fix-style/; revision=14408
This commit is contained in:
Marc Weber 2009-03-06 12:27:50 +00:00
parent 8cad533a76
commit 321763dd84
3 changed files with 57 additions and 43 deletions

View file

@ -245,29 +245,6 @@ in
";
};
interfaceMonitor = {
enable = mkOption {
default = false;
description = "
If <literal>true</literal>, monitor Ethernet interfaces for
cables being plugged in or unplugged. When this occurs, the
<command>dhclient</command> service is restarted to
automatically obtain a new IP address. This is useful for
roaming users (laptops).
";
};
beep = mkOption {
default = false;
description = "
If <literal>true</literal>, 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

View file

@ -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));

View file

@ -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 <literal>true</literal>, monitor Ethernet interfaces for
cables being plugged in or unplugged. When this occurs, the
<command>dhclient</command> service is restarted to
automatically obtain a new IP address. This is useful for
roaming users (laptops).
";
};
beep = mkOption {
default = false;
description = "
If <literal>true</literal>, 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
{
mkIf config.networking.interfaceMonitor.enable {
require = [
options
];
services = {
extraJobs = [{
name = "ifplugd";
extraPath = [ifplugd];
job = "
description \"Network interface connectivity monitor\"
job = ''
description "Network interface connectivity monitor"
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}";
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}
'';
}];
};
}