{ config, lib, pkgs, ... }: with lib; let cfg = config.security.pam.mount; anyPamMount = any (attrByPath ["pamMount"] false) (attrValues config.security.pam.services); in { options = { security.pam.mount = { enable = mkOption { type = types.bool; default = false; description = '' Enable PAM mount system to mount fileystems on user login. ''; }; extraVolumes = mkOption { type = types.listOf types.str; default = []; description = '' List of volume definitions for pam_mount. For more information, visit . ''; }; additionalSearchPaths = mkOption { type = types.listOf types.package; default = []; example = literalExpression "[ pkgs.bindfs ]"; description = '' Additional programs to include in the search path of pam_mount. Useful for example if you want to use some FUSE filesystems like bindfs. ''; }; fuseMountOptions = mkOption { type = types.listOf types.str; default = []; example = literalExpression '' [ "nodev" "nosuid" "force-user=%(USER)" "gid=%(USERGID)" "perms=0700" "chmod-deny" "chown-deny" "chgrp-deny" ] ''; description = '' Global mount options that apply to every FUSE volume. You can define volume-specific options in the volume definitions. ''; }; }; }; config = mkIf (cfg.enable || anyPamMount) { environment.systemPackages = [ pkgs.pam_mount ]; environment.etc."security/pam_mount.conf.xml" = { source = let extraUserVolumes = filterAttrs (n: u: u.cryptHomeLuks != null || u.pamMount != {}) config.users.users; mkAttr = k: v: ''${k}="${v}"''; userVolumeEntry = user: let attrs = { user = user.name; path = user.cryptHomeLuks; mountpoint = user.home; } // user.pamMount; in "\n"; in pkgs.writeText "pam_mount.conf.xml" '' ${makeBinPath ([ pkgs.util-linux ] ++ cfg.additionalSearchPaths)} ${pkgs.fuse}/bin/mount.fuse %(VOLUME) %(MNTPT) -o ${concatStringsSep "," (cfg.fuseMountOptions ++ [ "%(OPTIONS)" ])} ${pkgs.pam_mount}/bin/mount.crypt %(VOLUME) %(MNTPT) ${pkgs.pam_mount}/bin/umount.crypt %(MNTPT) ${pkgs.pam_mount}/bin/pmvarrun -u %(USER) -o %(OPERATION) ${concatStrings (map userVolumeEntry (attrValues extraUserVolumes))} ${concatStringsSep "\n" cfg.extraVolumes} ''; }; }; }