2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-10-12 16:36:19 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2009-05-01 05:43:41 +00:00
|
|
|
|
|
|
|
let
|
2009-10-12 16:36:19 +00:00
|
|
|
|
|
|
|
cfg = config.services.autofs;
|
|
|
|
|
2009-12-25 06:39:43 +00:00
|
|
|
autoMaster = pkgs.writeText "auto.master" cfg.autoMaster;
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2009-05-01 05:43:41 +00:00
|
|
|
|
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
services.autofs = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
enable = mkOption {
|
2020-04-20 18:05:26 +00:00
|
|
|
type = types.bool;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2009-12-25 06:39:43 +00:00
|
|
|
Mount filesystems on demand. Unmount them automatically.
|
2016-09-19 11:49:47 +00:00
|
|
|
You may also be interested in afuse.
|
2017-07-26 12:24:42 +00:00
|
|
|
'';
|
2009-05-01 05:43:41 +00:00
|
|
|
};
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
autoMaster = mkOption {
|
2016-01-17 18:34:55 +00:00
|
|
|
type = types.str;
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression ''
|
2016-01-17 18:34:55 +00:00
|
|
|
let
|
2009-10-12 16:36:19 +00: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}
|
|
|
|
'''
|
|
|
|
'';
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2017-07-26 12:24:42 +00:00
|
|
|
Contents of `/etc/auto.master` file. See {command}`auto.master(5)` and {command}`autofs(5)`.
|
|
|
|
'';
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
2009-05-01 05:43:41 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
timeout = mkOption {
|
2021-01-24 12:17:07 +00:00
|
|
|
type = types.int;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = 600;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Set the global minimum timeout, in seconds, until directories are unmounted";
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
2009-05-01 05:43:41 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
debug = mkOption {
|
2020-04-27 07:04:07 +00:00
|
|
|
type = types.bool;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2017-07-26 12:24:42 +00:00
|
|
|
Pass -d and -7 to automount and write log to the system journal.
|
|
|
|
'';
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
2009-12-25 06:39:43 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
2009-05-01 05:43:41 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
2009-05-01 05:43:41 +00:00
|
|
|
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
###### implementation
|
2009-05-01 05:43:41 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
config = mkIf cfg.enable {
|
2009-05-01 05:43:41 +00:00
|
|
|
|
2023-11-14 20:37:50 +00:00
|
|
|
boot.kernelModules = [ "autofs" ];
|
2012-03-17 17:26:17 +00:00
|
|
|
|
2015-11-11 13:18:38 +00:00
|
|
|
systemd.services.autofs =
|
2016-08-14 10:27:33 +00: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 05:43:41 +00: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 10:27:33 +00: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 16:36:19 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-05-01 05:43:41 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-05-01 05:43:41 +00:00
|
|
|
}
|