diff --git a/modules/services/networking/dhclient.nix b/modules/services/networking/dhclient.nix
index 5d82854fef5..fe118fb320e 100644
--- a/modules/services/networking/dhclient.nix
+++ b/modules/services/networking/dhclient.nix
@@ -116,12 +116,16 @@ in
powerManagement.resumeCommands =
''
- export PATH=${config.system.build.upstart}/sbin:$PATH
- initctl restart wpa_supplicant
- initctl restart dhclient
+ ${config.system.build.upstart}/sbin/restart dhclient
+ '';
+
+ networking.interfaceMonitor.commands =
+ ''
+ if [ "$status" = up ]; then
+ ${config.system.build.upstart}/sbin/restart dhclient
+ fi
'';
};
}
-
diff --git a/modules/services/networking/ifplugd.nix b/modules/services/networking/ifplugd.nix
index e4e4fd9216a..3e2bf9d6997 100644
--- a/modules/services/networking/ifplugd.nix
+++ b/modules/services/networking/ifplugd.nix
@@ -6,6 +6,8 @@ let
inherit (pkgs) ifplugd;
+ cfg = config.networking.interfaceMonitor;
+
# 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
@@ -14,10 +16,9 @@ let
plugScript = pkgs.writeScript "ifplugd.action"
''
#! ${pkgs.stdenv.shell}
- if test "$2" = up; then
- initctl stop dhclient
- initctl start dhclient
- fi
+ iface="$1"
+ status="$2"
+ ${cfg.commands}
'';
in
@@ -30,21 +31,33 @@ in
networking.interfaceMonitor.enable = mkOption {
default = false;
- description = "
+ 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).
- ";
+ '';
};
networking.interfaceMonitor.beep = mkOption {
default = false;
- description = "
+ description = ''
If true, beep when an Ethernet cable is
plugged in or unplugged.
- ";
+ '';
+ };
+
+ networking.interfaceMonitor.commands = mkOption {
+ default = false;
+ description = ''
+ Shell commands to be executed when the link status of an
+ interface changes. On invocation, the shell variable
+ iface contains the name of the interface,
+ while the variable status contains either
+ up or down to indicate
+ the new status.
+ '';
};
};
@@ -52,7 +65,7 @@ in
###### implementation
- config = mkIf config.networking.interfaceMonitor.enable {
+ config = mkIf cfg.enable {
jobs.ifplugd =
{ description = "Network interface connectivity monitor";
@@ -68,7 +81,7 @@ in
'';
};
- environment.systemPackages = [ifplugd];
+ environment.systemPackages = [ ifplugd ];
};
diff --git a/modules/services/networking/wpa_supplicant.nix b/modules/services/networking/wpa_supplicant.nix
index 7e29747dcc2..bf4cd6ae29a 100644
--- a/modules/services/networking/wpa_supplicant.nix
+++ b/modules/services/networking/wpa_supplicant.nix
@@ -63,6 +63,11 @@ in
+ (optionalString (config.networking.WLANInterface != null) "-i ${config.networking.WLANInterface}");
};
+ powerManagement.resumeCommands =
+ ''
+ ${config.system.build.upstart}/sbin/restart wpa_supplicant
+ '';
+
};
}