2009-03-06 12:27:50 +00:00
|
|
|
{pkgs, config, ...}:
|
2007-08-14 17:43:56 +01:00
|
|
|
|
2009-10-12 18:09:38 +01:00
|
|
|
with pkgs.lib;
|
|
|
|
|
2007-08-14 17:43:56 +01:00
|
|
|
let
|
2009-03-06 12:27:50 +00:00
|
|
|
|
2009-07-15 12:19:11 +01:00
|
|
|
inherit (pkgs) ifplugd;
|
2007-08-14 17:43:56 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
# restart dhclient, which will hopefully give us a new IP address
|
|
|
|
# if appropriate.
|
2009-07-15 12:19:11 +01:00
|
|
|
plugScript = pkgs.writeScript "ifplugd.action"
|
|
|
|
''
|
|
|
|
#! ${pkgs.stdenv.shell}
|
|
|
|
if test "$2" = up; then
|
|
|
|
initctl stop dhclient
|
|
|
|
initctl start dhclient
|
|
|
|
fi
|
|
|
|
'';
|
2007-08-14 17:43:56 +01:00
|
|
|
|
|
|
|
in
|
|
|
|
|
2009-07-15 12:19:11 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
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).
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.interfaceMonitor.beep = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
If <literal>true</literal>, beep when an Ethernet cable is
|
|
|
|
plugged in or unplugged.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.networking.interfaceMonitor.enable {
|
2009-03-06 12:27:50 +00:00
|
|
|
|
2009-10-12 19:09:34 +01:00
|
|
|
jobs.ifplugd =
|
2009-10-12 18:09:38 +01:00
|
|
|
{ description = "Network interface connectivity monitor";
|
2007-08-14 17:43:56 +01:00
|
|
|
|
2009-11-06 22:19:17 +00:00
|
|
|
startOn = "started network-interfaces";
|
|
|
|
stopOn = "stopping network-interfaces";
|
2007-08-14 17:43:56 +01:00
|
|
|
|
2009-10-12 18:09:38 +01:00
|
|
|
exec =
|
|
|
|
''
|
|
|
|
${ifplugd}/sbin/ifplugd --no-daemon --no-startup --no-shutdown \
|
|
|
|
${if config.networking.interfaceMonitor.beep then "" else "--no-beep"} \
|
|
|
|
--run ${plugScript}
|
|
|
|
'';
|
|
|
|
};
|
2009-07-15 12:19:11 +01:00
|
|
|
|
|
|
|
environment.systemPackages = [ifplugd];
|
|
|
|
|
2009-03-06 12:27:50 +00:00
|
|
|
};
|
2009-07-15 12:19:11 +01:00
|
|
|
|
2007-08-14 17:43:56 +01:00
|
|
|
}
|