at 16.09-beta 2.6 kB view raw
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 = "Automounts filesystems on demand"; 79 after = [ "network.target" "ypbind.service" "sssd.service" "network-online.target" ]; 80 wants = [ "network-online.target" ]; 81 wantedBy = [ "multi-user.target" ]; 82 83 preStart = '' 84 # There should be only one autofs service managed by systemd, so this should be safe. 85 rm -f /tmp/autofs-running 86 ''; 87 88 serviceConfig = { 89 Type = "forking"; 90 PIDFile = "/run/autofs.pid"; 91 ExecStart = "${pkgs.autofs5}/bin/automount ${optionalString cfg.debug "-d"} -p /run/autofs.pid -t ${builtins.toString cfg.timeout} ${autoMaster}"; 92 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 93 }; 94 }; 95 96 }; 97 98}