at 17.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 afuse. 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 Contents of <literal>/etc/auto.master</literal> file. See <command>auto.master(5)</command> and <command>autofs(5)</command>. 50 ''; 51 }; 52 53 timeout = mkOption { 54 default = 600; 55 description = "Set the global minimum timeout, in seconds, until directories are unmounted"; 56 }; 57 58 debug = mkOption { 59 default = false; 60 description = '' 61 Pass -d and -7 to automount and write log to the system journal. 62 ''; 63 }; 64 65 }; 66 67 }; 68 69 70 ###### implementation 71 72 config = mkIf cfg.enable { 73 74 boot.kernelModules = [ "autofs4" ]; 75 76 systemd.services.autofs = 77 { description = "Automounts filesystems on demand"; 78 after = [ "network.target" "ypbind.service" "sssd.service" "network-online.target" ]; 79 wants = [ "network-online.target" ]; 80 wantedBy = [ "multi-user.target" ]; 81 82 preStart = '' 83 # There should be only one autofs service managed by systemd, so this should be safe. 84 rm -f /tmp/autofs-running 85 ''; 86 87 serviceConfig = { 88 Type = "forking"; 89 PIDFile = "/run/autofs.pid"; 90 ExecStart = "${pkgs.autofs5}/bin/automount ${optionalString cfg.debug "-d"} -p /run/autofs.pid -t ${builtins.toString cfg.timeout} ${autoMaster}"; 91 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 92 }; 93 }; 94 95 }; 96 97}