| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2007-08-14 16:43:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | with lib; | 
					
						
							| 
									
										
										
										
											2009-10-12 17:09:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-14 16:43:56 +00:00
										 |  |  | let | 
					
						
							| 
									
										
										
										
											2009-03-06 12:27:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |   inherit (pkgs) ifplugd; | 
					
						
							| 
									
										
										
										
											2007-08-14 16:43:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 22:53:25 +00:00
										 |  |  |   cfg = config.networking.interfaceMonitor; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-14 16:43:56 +00:00
										 |  |  |   # The ifplugd action script, which is called whenever the link | 
					
						
							| 
									
										
										
										
											2013-10-29 17:34:43 +01:00
										 |  |  |   # status changes (i.e., a cable is plugged in or unplugged). | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |   plugScript = pkgs.writeScript "ifplugd.action" | 
					
						
							|  |  |  |     ''
 | 
					
						
							|  |  |  |       #! ${pkgs.stdenv.shell} | 
					
						
							| 
									
										
										
										
											2012-02-19 22:53:25 +00:00
										 |  |  |       iface="$1" | 
					
						
							|  |  |  |       status="$2" | 
					
						
							|  |  |  |       ${cfg.commands} | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |     '';
 | 
					
						
							| 
									
										
										
										
											2007-08-14 16:43:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | in | 
					
						
							| 
									
										
										
										
											2007-08-14 16:43:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ###### interface | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   options = { | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |     networking.interfaceMonitor.enable = mkOption { | 
					
						
							| 
									
										
										
										
											2013-10-29 17:34:43 +01:00
										 |  |  |       type = types.bool; | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |       default = false; | 
					
						
							| 
									
										
										
										
											2012-02-19 22:53:25 +00:00
										 |  |  |       description = ''
 | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |         If <literal>true</literal>, monitor Ethernet interfaces for | 
					
						
							|  |  |  |         cables being plugged in or unplugged.  When this occurs, the | 
					
						
							| 
									
										
										
										
											2013-10-29 17:34:43 +01:00
										 |  |  |         commands specified in | 
					
						
							|  |  |  |         <option>networking.interfaceMonitor.commands</option> are | 
					
						
							|  |  |  |         executed. | 
					
						
							| 
									
										
										
										
											2012-02-19 22:53:25 +00:00
										 |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     networking.interfaceMonitor.beep = mkOption { | 
					
						
							| 
									
										
										
										
											2013-10-29 17:34:43 +01:00
										 |  |  |       type = types.bool; | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |       default = false; | 
					
						
							| 
									
										
										
										
											2012-02-19 22:53:25 +00:00
										 |  |  |       description = ''
 | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |         If <literal>true</literal>, beep when an Ethernet cable is | 
					
						
							|  |  |  |         plugged in or unplugged. | 
					
						
							| 
									
										
										
										
											2012-02-19 22:53:25 +00:00
										 |  |  |       '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     networking.interfaceMonitor.commands = mkOption { | 
					
						
							| 
									
										
										
										
											2013-10-29 17:34:43 +01:00
										 |  |  |       type = types.lines; | 
					
						
							| 
									
										
										
										
											2012-02-20 16:53:44 +00:00
										 |  |  |       default = ""; | 
					
						
							| 
									
										
										
										
											2012-02-19 22:53:25 +00:00
										 |  |  |       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. | 
					
						
							|  |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ###### implementation | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 22:53:25 +00:00
										 |  |  |   config = mkIf cfg.enable { | 
					
						
							| 
									
										
										
										
											2009-03-06 12:27:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 18:09:34 +00:00
										 |  |  |     jobs.ifplugd = | 
					
						
							| 
									
										
										
										
											2009-10-12 17:09:38 +00:00
										 |  |  |       { description = "Network interface connectivity monitor"; | 
					
						
							| 
									
										
										
										
											2007-08-14 16:43:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 22:19:17 +00:00
										 |  |  |         startOn = "started network-interfaces"; | 
					
						
							|  |  |  |         stopOn = "stopping network-interfaces"; | 
					
						
							| 
									
										
										
										
											2007-08-14 16:43:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 17:09:38 +00: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 11:19:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 22:53:25 +00:00
										 |  |  |     environment.systemPackages = [ ifplugd ]; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-06 12:27:50 +00:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-14 16:43:56 +00:00
										 |  |  | } |