2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2009-05-01 07:43:41 +02:00
|
|
|
|
|
|
|
let
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
cfg = config.services.autofs;
|
|
|
|
|
2009-12-25 07:39:43 +01:00
|
|
|
autoMaster = pkgs.writeText "auto.master" cfg.autoMaster;
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2009-05-01 07:43:41 +02:00
|
|
|
|
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
services.autofs = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
2009-12-25 07:39:43 +01:00
|
|
|
Mount filesystems on demand. Unmount them automatically.
|
|
|
|
You may also be interested in afuese.
|
2009-10-12 18:36:19 +02:00
|
|
|
";
|
2009-05-01 07:43:41 +02:00
|
|
|
};
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
autoMaster = mkOption {
|
2011-09-06 01:33:29 +02:00
|
|
|
example = literalExample ''
|
2009-10-12 18:36:19 +02:00
|
|
|
autoMaster = let
|
|
|
|
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 07:39:43 +01:00
|
|
|
See man 5 auto.master and man 5 autofs.
|
2009-10-12 18:36:19 +02:00
|
|
|
";
|
|
|
|
};
|
2009-05-01 07:43:41 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
timeout = mkOption {
|
|
|
|
default = 600;
|
|
|
|
description = "Set the global minimum timeout, in seconds, until directories are unmounted";
|
|
|
|
};
|
2009-05-01 07:43:41 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
debug = mkOption {
|
|
|
|
default = false;
|
2009-12-25 07:39:43 +01:00
|
|
|
description = "
|
|
|
|
pass -d and -7 to automount and write log to /var/log/autofs
|
|
|
|
";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-12-25 07:39:43 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-05-01 07:43:41 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-05-01 07:43:41 +02:00
|
|
|
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### implementation
|
2009-05-01 07:43:41 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
config = mkIf cfg.enable {
|
2009-05-01 07:43:41 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
environment.etc = singleton
|
|
|
|
{ target = "auto.master";
|
2009-05-01 07:43:41 +02:00
|
|
|
source = pkgs.writeText "auto.master" cfg.autoMaster;
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-05-01 07:43:41 +02:00
|
|
|
|
2012-03-17 18:26:17 +01:00
|
|
|
boot.kernelModules = [ "autofs4" ];
|
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.autofs =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ description = "Filesystem automounter";
|
2009-05-01 07:43:41 +02:00
|
|
|
|
2009-11-06 23:19:17 +01:00
|
|
|
startOn = "started network-interfaces";
|
|
|
|
stopOn = "stopping network-interfaces";
|
2009-05-01 07:43:41 +02:00
|
|
|
|
2012-03-17 18:26:17 +01:00
|
|
|
path = [ pkgs.nfsUtils pkgs.sshfsFuse ];
|
2009-12-25 07:39:43 +01:00
|
|
|
|
2011-09-14 20:20:50 +02:00
|
|
|
preStop =
|
2009-12-25 07:39:43 +01:00
|
|
|
''
|
|
|
|
set -e; while :; do pkill -TERM automount; sleep 1; done
|
|
|
|
'';
|
|
|
|
|
|
|
|
# automount doesn't clean up when receiving SIGKILL.
|
|
|
|
# umount -l should unmount the directories recursively when they are no longer used
|
|
|
|
# It does, but traces are left in /etc/mtab. So unmount recursively..
|
|
|
|
postStop =
|
2009-10-12 18:36:19 +02:00
|
|
|
''
|
2009-12-25 07:39:43 +01:00
|
|
|
PATH=${pkgs.gnused}/bin:${pkgs.coreutils}/bin
|
|
|
|
exec &> /tmp/logss
|
|
|
|
# double quote for sed:
|
|
|
|
escapeSpaces(){ sed 's/ /\\\\040/g'; }
|
|
|
|
unescapeSpaces(){ sed 's/\\040/ /g'; }
|
|
|
|
sed -n 's@^\s*\(\([^\\ ]\|\\ \)*\)\s.*@\1@p' ${autoMaster} | sed 's/[\\]//' | while read mountPoint; do
|
|
|
|
sed -n "s@[^ ]\+\s\+\($(echo "$mountPoint"| escapeSpaces)[^ ]*\).*@\1@p" /proc/mounts | sort -r | unescapeSpaces| while read smountP; do
|
2012-03-09 15:37:58 +01:00
|
|
|
${pkgs.utillinux}/bin/umount -l "$smountP" || true
|
2009-12-25 07:39:43 +01:00
|
|
|
done
|
|
|
|
done
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
2009-05-01 07:43:41 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
script =
|
|
|
|
''
|
|
|
|
${if cfg.debug then "exec &> /var/log/autofs" else ""}
|
2009-12-25 07:39:43 +01:00
|
|
|
exec ${pkgs.autofs5}/sbin/automount ${if cfg.debug then "-d" else ""} -f -t ${builtins.toString cfg.timeout} "${autoMaster}" ${if cfg.debug then "-l7" else ""}
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-05-01 07:43:41 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-05-01 07:43:41 +02:00
|
|
|
}
|