| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  | { config, pkgs, ... }: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | with pkgs.lib; | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   cfg = config.services.autofs; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-25 06:39:43 +00:00
										 |  |  |   autoMaster = pkgs.writeText "auto.master" cfg.autoMaster; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  | in | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ###### interface | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   options = { | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |     services.autofs = { | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |       enable = mkOption { | 
					
						
							|  |  |  |         default = false; | 
					
						
							|  |  |  |         description = "
 | 
					
						
							| 
									
										
										
										
											2009-12-25 06:39:43 +00:00
										 |  |  |           Mount filesystems on demand. Unmount them automatically. | 
					
						
							|  |  |  |           You may also be interested in afuese. | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |         ";
 | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |       autoMaster = mkOption { | 
					
						
							| 
									
										
										
										
											2011-09-05 23:33:29 +00:00
										 |  |  |         example = literalExample ''
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |           autoMaster = let | 
					
						
							|  |  |  |             mapConf = pkgs.writeText "auto" '''
 | 
					
						
							|  |  |  |              kernel    -ro,soft,intr       ftp.kernel.org:/pub/linux | 
					
						
							|  |  |  |              boot      -fstype=ext2        :/dev/hda1 | 
					
						
							|  |  |  |              windoze   -fstype=smbfs       ://windoze/c | 
					
						
							|  |  |  |              removable -fstype=ext2        :/dev/hdd | 
					
						
							|  |  |  |              cd        -fstype=iso9660,ro  :/dev/hdc | 
					
						
							|  |  |  |              floppy    -fstype=auto        :/dev/fd0 | 
					
						
							|  |  |  |              server    -rw,hard,intr       / -ro myserver.me.org:/ \ | 
					
						
							|  |  |  |                                            /usr myserver.me.org:/usr \ | 
					
						
							|  |  |  |                                            /home myserver.me.org:/home | 
					
						
							|  |  |  |             ''';
 | 
					
						
							|  |  |  |           in '''
 | 
					
						
							|  |  |  |             /auto file:''${mapConf} | 
					
						
							|  |  |  |           '''
 | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         description = "
 | 
					
						
							|  |  |  |           file contents of /etc/auto.master. See man auto.master | 
					
						
							| 
									
										
										
										
											2009-12-25 06:39:43 +00:00
										 |  |  |           See man 5 auto.master and man 5 autofs. | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |         ";
 | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |       timeout = mkOption { | 
					
						
							|  |  |  |         default = 600; | 
					
						
							|  |  |  |         description = "Set the global minimum timeout, in seconds, until directories are unmounted"; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |       debug = mkOption { | 
					
						
							|  |  |  |         default = false; | 
					
						
							| 
									
										
										
										
											2009-12-25 06:39:43 +00:00
										 |  |  |         description = "
 | 
					
						
							|  |  |  |         pass -d and -7 to automount and write log to /var/log/autofs | 
					
						
							|  |  |  |         ";
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |       }; | 
					
						
							| 
									
										
										
										
											2009-12-25 06:39:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |   ###### implementation | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |   config = mkIf cfg.enable { | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |     environment.etc = singleton | 
					
						
							|  |  |  |       { target = "auto.master"; | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  |         source = pkgs.writeText "auto.master" cfg.autoMaster; | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |       }; | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-17 17:26:17 +00:00
										 |  |  |     boot.kernelModules = [ "autofs4" ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 18:09:34 +00:00
										 |  |  |     jobs.autofs = | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |       { description = "Filesystem automounter"; | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 22:19:17 +00:00
										 |  |  |         startOn = "started network-interfaces"; | 
					
						
							|  |  |  |         stopOn = "stopping network-interfaces"; | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-17 17:26:17 +00:00
										 |  |  |         path = [ pkgs.nfsUtils pkgs.sshfsFuse ]; | 
					
						
							| 
									
										
										
										
											2009-12-25 06:39:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  |         preStop = | 
					
						
							| 
									
										
										
										
											2009-12-25 06:39:43 +00:00
										 |  |  |           ''
 | 
					
						
							|  |  |  |             set -e; while :; do pkill -TERM automount; sleep 1; done | 
					
						
							|  |  |  |           '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # automount doesn't clean up when receiving SIGKILL. | 
					
						
							|  |  |  |         # umount -l should unmount the directories recursively when they are no longer used | 
					
						
							|  |  |  |         # It does, but traces are left in /etc/mtab. So unmount recursively.. | 
					
						
							|  |  |  |         postStop = | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |           ''
 | 
					
						
							| 
									
										
										
										
											2009-12-25 06:39:43 +00:00
										 |  |  |           PATH=${pkgs.gnused}/bin:${pkgs.coreutils}/bin | 
					
						
							|  |  |  |           exec &> /tmp/logss | 
					
						
							|  |  |  |           # double quote for sed: | 
					
						
							|  |  |  |           escapeSpaces(){ sed 's/ /\\\\040/g'; } | 
					
						
							|  |  |  |           unescapeSpaces(){ sed 's/\\040/ /g'; } | 
					
						
							|  |  |  |           sed -n 's@^\s*\(\([^\\ ]\|\\ \)*\)\s.*@\1@p' ${autoMaster} | sed 's/[\\]//' | while read mountPoint; do | 
					
						
							|  |  |  |             sed -n "s@[^ ]\+\s\+\($(echo "$mountPoint"| escapeSpaces)[^ ]*\).*@\1@p" /proc/mounts | sort -r | unescapeSpaces| while read smountP; do | 
					
						
							| 
									
										
										
										
											2012-03-09 14:37:58 +00:00
										 |  |  |               ${pkgs.utillinux}/bin/umount -l "$smountP" || true | 
					
						
							| 
									
										
										
										
											2009-12-25 06:39:43 +00:00
										 |  |  |             done | 
					
						
							|  |  |  |           done | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |           '';
 | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |         script = | 
					
						
							|  |  |  |           ''
 | 
					
						
							|  |  |  |             ${if cfg.debug then "exec &> /var/log/autofs" else ""} | 
					
						
							| 
									
										
										
										
											2009-12-25 06:39:43 +00:00
										 |  |  |             exec ${pkgs.autofs5}/sbin/automount ${if cfg.debug then "-d" else ""} -f -t ${builtins.toString cfg.timeout} "${autoMaster}" ${if cfg.debug then "-l7" else ""} | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |           '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-01 05:43:41 +00:00
										 |  |  | } |