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