2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2009-05-01 06:43:41 +01:00
|
|
|
|
|
|
|
let
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
cfg = config.services.autofs;
|
|
|
|
|
2009-12-25 06:39:43 +00:00
|
|
|
autoMaster = pkgs.writeText "auto.master" cfg.autoMaster;
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2009-05-01 06:43:41 +01:00
|
|
|
|
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
services.autofs = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
2009-12-25 06:39:43 +00:00
|
|
|
Mount filesystems on demand. Unmount them automatically.
|
2016-09-19 12:49:47 +01:00
|
|
|
You may also be interested in afuse.
|
2009-10-12 17:36:19 +01:00
|
|
|
";
|
2009-05-01 06:43:41 +01:00
|
|
|
};
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
autoMaster = mkOption {
|
2016-01-17 18:34:55 +00:00
|
|
|
type = types.str;
|
2011-09-06 00:33:29 +01:00
|
|
|
example = literalExample ''
|
2016-01-17 18:34:55 +00:00
|
|
|
let
|
2009-10-12 17:36:19 +01:00
|
|
|
mapConf = pkgs.writeText "auto" '''
|
|
|
|
kernel -ro,soft,intr ftp.kernel.org:/pub/linux
|
|
|
|
boot -fstype=ext2 :/dev/hda1
|
|
|
|
windoze -fstype=smbfs ://windoze/c
|
|
|
|
removable -fstype=ext2 :/dev/hdd
|
|
|
|
cd -fstype=iso9660,ro :/dev/hdc
|
|
|
|
floppy -fstype=auto :/dev/fd0
|
|
|
|
server -rw,hard,intr / -ro myserver.me.org:/ \
|
|
|
|
/usr myserver.me.org:/usr \
|
|
|
|
/home myserver.me.org:/home
|
|
|
|
''';
|
|
|
|
in '''
|
|
|
|
/auto file:''${mapConf}
|
|
|
|
'''
|
|
|
|
'';
|
|
|
|
description = "
|
|
|
|
file contents of /etc/auto.master. See man auto.master
|
2009-12-25 06:39:43 +00:00
|
|
|
See man 5 auto.master and man 5 autofs.
|
2009-10-12 17:36:19 +01:00
|
|
|
";
|
|
|
|
};
|
2009-05-01 06:43:41 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
timeout = mkOption {
|
|
|
|
default = 600;
|
|
|
|
description = "Set the global minimum timeout, in seconds, until directories are unmounted";
|
|
|
|
};
|
2009-05-01 06:43:41 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
debug = mkOption {
|
|
|
|
default = false;
|
2009-12-25 06:39:43 +00:00
|
|
|
description = "
|
|
|
|
pass -d and -7 to automount and write log to /var/log/autofs
|
|
|
|
";
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
2009-12-25 06:39:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
2009-05-01 06:43:41 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
2009-05-01 06:43:41 +01:00
|
|
|
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
###### implementation
|
2009-05-01 06:43:41 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
config = mkIf cfg.enable {
|
2009-05-01 06:43:41 +01:00
|
|
|
|
2012-03-17 17:26:17 +00:00
|
|
|
boot.kernelModules = [ "autofs4" ];
|
|
|
|
|
2015-11-11 13:18:38 +00:00
|
|
|
systemd.services.autofs =
|
2016-08-14 11:27:33 +01:00
|
|
|
{ description = "Automounts filesystems on demand";
|
|
|
|
after = [ "network.target" "ypbind.service" "sssd.service" "network-online.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
2015-11-11 13:18:38 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2009-05-01 06:43:41 +01:00
|
|
|
|
2016-03-13 21:58:23 +00:00
|
|
|
preStart = ''
|
|
|
|
# There should be only one autofs service managed by systemd, so this should be safe.
|
|
|
|
rm -f /tmp/autofs-running
|
|
|
|
'';
|
|
|
|
|
2015-11-11 13:18:38 +00:00
|
|
|
serviceConfig = {
|
2016-08-14 11:27:33 +01:00
|
|
|
Type = "forking";
|
|
|
|
PIDFile = "/run/autofs.pid";
|
|
|
|
ExecStart = "${pkgs.autofs5}/bin/automount ${optionalString cfg.debug "-d"} -p /run/autofs.pid -t ${builtins.toString cfg.timeout} ${autoMaster}";
|
2015-11-11 13:18:38 +00:00
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-05-01 06:43:41 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-05-01 06:43:41 +01:00
|
|
|
}
|