mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-30 19:02:57 +00:00
3f4c802d26
Back in 2018, the kernel decided to remove the autofs4 module. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a2225d931f75ddd3c39f4d0d195fad99dfd68671 This caused immediate problems with systemd, so the kernel allowed autofs4 as a config option that would simply map back to autofs. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d02d21ea007b6b33cdaf15c2f84fb1fea996ecc2 Earlier this year, in July 2023, the kernel got tired of people not adapting to the autofs change, and forced the issue by fixing it within the kernel defconfigs, which NixOS uses as a starting point for their own kernel configs. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1f2190d6b7112d22d3f8dfeca16a2f6a2f51444e This commit reflects the post-2018 reality by changing the remaining autofs4 references to autofs. Since this change initially happened in kernel 4.18 and we no longer support 4.x kernels, we don't need any backwards-compatibility tweaks.
101 lines
2.7 KiB
Nix
101 lines
2.7 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.autofs;
|
|
|
|
autoMaster = pkgs.writeText "auto.master" cfg.autoMaster;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.autofs = {
|
|
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = lib.mdDoc ''
|
|
Mount filesystems on demand. Unmount them automatically.
|
|
You may also be interested in afuse.
|
|
'';
|
|
};
|
|
|
|
autoMaster = mkOption {
|
|
type = types.str;
|
|
example = literalExpression ''
|
|
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 = lib.mdDoc ''
|
|
Contents of `/etc/auto.master` file. See {command}`auto.master(5)` and {command}`autofs(5)`.
|
|
'';
|
|
};
|
|
|
|
timeout = mkOption {
|
|
type = types.int;
|
|
default = 600;
|
|
description = lib.mdDoc "Set the global minimum timeout, in seconds, until directories are unmounted";
|
|
};
|
|
|
|
debug = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = lib.mdDoc ''
|
|
Pass -d and -7 to automount and write log to the system journal.
|
|
'';
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
boot.kernelModules = [ "autofs" ];
|
|
|
|
systemd.services.autofs =
|
|
{ description = "Automounts filesystems on demand";
|
|
after = [ "network.target" "ypbind.service" "sssd.service" "network-online.target" ];
|
|
wants = [ "network-online.target" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
preStart = ''
|
|
# There should be only one autofs service managed by systemd, so this should be safe.
|
|
rm -f /tmp/autofs-running
|
|
'';
|
|
|
|
serviceConfig = {
|
|
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}";
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
};
|
|
};
|
|
|
|
};
|
|
|
|
}
|