at 25.11-pre 2.7 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 9 cfg = config.services.autofs; 10 11 autoMaster = pkgs.writeText "auto.master" cfg.autoMaster; 12 13in 14 15{ 16 17 ###### interface 18 19 options = { 20 21 services.autofs = { 22 23 enable = lib.mkOption { 24 type = lib.types.bool; 25 default = false; 26 description = '' 27 Mount filesystems on demand. Unmount them automatically. 28 You may also be interested in afuse. 29 ''; 30 }; 31 32 autoMaster = lib.mkOption { 33 type = lib.types.str; 34 example = lib.literalExpression '' 35 let 36 mapConf = pkgs.writeText "auto" ''' 37 kernel -ro,soft,intr ftp.kernel.org:/pub/linux 38 boot -fstype=ext2 :/dev/hda1 39 windoze -fstype=smbfs ://windoze/c 40 removable -fstype=ext2 :/dev/hdd 41 cd -fstype=iso9660,ro :/dev/hdc 42 floppy -fstype=auto :/dev/fd0 43 server -rw,hard,intr / -ro myserver.me.org:/ \ 44 /usr myserver.me.org:/usr \ 45 /home myserver.me.org:/home 46 '''; 47 in ''' 48 /auto file:''${mapConf} 49 ''' 50 ''; 51 description = '' 52 Contents of `/etc/auto.master` file. See {manpage}`auto.master(5)` and {manpage}`autofs(5)`. 53 ''; 54 }; 55 56 timeout = lib.mkOption { 57 type = lib.types.int; 58 default = 600; 59 description = "Set the global minimum timeout, in seconds, until directories are unmounted"; 60 }; 61 62 debug = lib.mkOption { 63 type = lib.types.bool; 64 default = false; 65 description = '' 66 Pass -d and -7 to automount and write log to the system journal. 67 ''; 68 }; 69 70 }; 71 72 }; 73 74 ###### implementation 75 76 config = lib.mkIf cfg.enable { 77 78 boot.kernelModules = [ "autofs" ]; 79 80 systemd.services.autofs = { 81 description = "Automounts filesystems on demand"; 82 after = [ 83 "network.target" 84 "ypbind.service" 85 "sssd.service" 86 "network-online.target" 87 ]; 88 wants = [ "network-online.target" ]; 89 wantedBy = [ "multi-user.target" ]; 90 91 preStart = '' 92 # There should be only one autofs service managed by systemd, so this should be safe. 93 rm -f /tmp/autofs-running 94 ''; 95 96 serviceConfig = { 97 Type = "forking"; 98 PIDFile = "/run/autofs.pid"; 99 ExecStart = "${pkgs.autofs5}/bin/automount ${lib.optionalString cfg.debug "-d"} -p /run/autofs.pid -t ${builtins.toString cfg.timeout} ${autoMaster}"; 100 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 101 }; 102 }; 103 104 }; 105 106}