Author: eelco
Date: Sun Feb 19 22:53:25 2012
New Revision: 32409
URL: https://nixos.org/websvn/nix/?rev=32409&sc=1

Log:
* Move the dhclient/wpa_supplicant restart actions out of the ifplugd
  module.

Modified:
   nixos/trunk/modules/services/networking/dhclient.nix
   nixos/trunk/modules/services/networking/ifplugd.nix
   nixos/trunk/modules/services/networking/wpa_supplicant.nix

Modified: nixos/trunk/modules/services/networking/dhclient.nix
==============================================================================
--- nixos/trunk/modules/services/networking/dhclient.nix        Sun Feb 19 
21:36:54 2012        (r32408)
+++ nixos/trunk/modules/services/networking/dhclient.nix        Sun Feb 19 
22:53:25 2012        (r32409)
@@ -116,12 +116,16 @@
 
     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
       '';
 
   };
 
 }
-

Modified: nixos/trunk/modules/services/networking/ifplugd.nix
==============================================================================
--- nixos/trunk/modules/services/networking/ifplugd.nix Sun Feb 19 21:36:54 
2012        (r32408)
+++ nixos/trunk/modules/services/networking/ifplugd.nix Sun Feb 19 22:53:25 
2012        (r32409)
@@ -6,6 +6,8 @@
 
   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 @@
   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 @@
 
     networking.interfaceMonitor.enable = mkOption {
       default = false;
-      description = "
+      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 = "
+      description = ''
         If <literal>true</literal>, 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
+        <varname>iface</varname> contains the name of the interface,
+        while the variable <varname>status</varname> contains either
+        <literal>up</literal> or <literal>down</literal> to indicate
+        the new status.
+      '';
     };
 
   };
@@ -52,7 +65,7 @@
 
   ###### implementation
 
-  config = mkIf config.networking.interfaceMonitor.enable {
+  config = mkIf cfg.enable {
 
     jobs.ifplugd =
       { description = "Network interface connectivity monitor";
@@ -68,7 +81,7 @@
           '';
       };
 
-    environment.systemPackages = [ifplugd];
+    environment.systemPackages = [ ifplugd ];
 
   };
 

Modified: nixos/trunk/modules/services/networking/wpa_supplicant.nix
==============================================================================
--- nixos/trunk/modules/services/networking/wpa_supplicant.nix  Sun Feb 19 
21:36:54 2012        (r32408)
+++ nixos/trunk/modules/services/networking/wpa_supplicant.nix  Sun Feb 19 
22:53:25 2012        (r32409)
@@ -63,6 +63,11 @@
           + (optionalString (config.networking.WLANInterface != null) "-i 
${config.networking.WLANInterface}");
       };
   
+    powerManagement.resumeCommands =
+      ''
+        ${config.system.build.upstart}/sbin/restart wpa_supplicant
+      '';
+
   };
 
 }
_______________________________________________
nix-commits mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-commits

Reply via email to