1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.autofs; 8 9 autoMaster = pkgs.writeText "auto.master" cfg.autoMaster; 10 11in 12 13{ 14 15 ###### interface 16 17 options = { 18 19 services.autofs = { 20 21 enable = mkOption { 22 default = false; 23 description = " 24 Mount filesystems on demand. Unmount them automatically. 25 You may also be interested in afuese. 26 "; 27 }; 28 29 autoMaster = mkOption { 30 type = types.str; 31 example = literalExample '' 32 let 33 mapConf = pkgs.writeText "auto" ''' 34 kernel -ro,soft,intr ftp.kernel.org:/pub/linux 35 boot -fstype=ext2 :/dev/hda1 36 windoze -fstype=smbfs ://windoze/c 37 removable -fstype=ext2 :/dev/hdd 38 cd -fstype=iso9660,ro :/dev/hdc 39 floppy -fstype=auto :/dev/fd0 40 server -rw,hard,intr / -ro myserver.me.org:/ \ 41 /usr myserver.me.org:/usr \ 42 /home myserver.me.org:/home 43 '''; 44 in ''' 45 /auto file:''${mapConf} 46 ''' 47 ''; 48 description = " 49 file contents of /etc/auto.master. See man auto.master 50 See man 5 auto.master and man 5 autofs. 51 "; 52 }; 53 54 timeout = mkOption { 55 default = 600; 56 description = "Set the global minimum timeout, in seconds, until directories are unmounted"; 57 }; 58 59 debug = mkOption { 60 default = false; 61 description = " 62 pass -d and -7 to automount and write log to /var/log/autofs 63 "; 64 }; 65 66 }; 67 68 }; 69 70 71 ###### implementation 72 73 config = mkIf cfg.enable { 74 75 boot.kernelModules = [ "autofs4" ]; 76 77 systemd.services.autofs = 78 { description = "Filesystem automounter"; 79 wantedBy = [ "multi-user.target" ]; 80 after = [ "network.target" ]; 81 82 serviceConfig = { 83 ExecStart = "${pkgs.autofs5}/sbin/automount ${if cfg.debug then "-d" else ""} -f -t ${builtins.toString cfg.timeout} ${autoMaster} ${if cfg.debug then "-l7" else ""}"; 84 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 85 }; 86 }; 87 88 }; 89 90}