2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.security.pam.mount;
|
|
|
|
|
2022-04-15 01:41:22 +00:00
|
|
|
oflRequired = cfg.logoutHup || cfg.logoutTerm || cfg.logoutKill;
|
|
|
|
|
|
|
|
fake_ofl = pkgs.writeShellScriptBin "fake_ofl" ''
|
|
|
|
SIGNAL=$1
|
|
|
|
MNTPT=$2
|
|
|
|
${pkgs.lsof}/bin/lsof | ${pkgs.gnugrep}/bin/grep $MNTPT | ${pkgs.gawk}/bin/awk '{print $2}' | ${pkgs.findutils}/bin/xargs ${pkgs.util-linux}/bin/kill -$SIGNAL
|
|
|
|
'';
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
anyPamMount = any (attrByPath ["pamMount"] false) (attrValues config.security.pam.services);
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
|
|
|
security.pam.mount = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Enable PAM mount system to mount fileystems on user login.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraVolumes = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
List of volume definitions for pam_mount.
|
2022-08-12 12:06:08 +00:00
|
|
|
For more information, visit <http://pam-mount.sourceforge.net/pam_mount.conf.5.html>.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-06-28 23:13:55 +00:00
|
|
|
|
|
|
|
additionalSearchPaths = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [];
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression "[ pkgs.bindfs ]";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-06-28 23:13:55 +00:00
|
|
|
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 = [];
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2021-06-28 23:13:55 +00:00
|
|
|
[ "nodev" "nosuid" "force-user=%(USER)" "gid=%(USERGID)" "perms=0700" "chmod-deny" "chown-deny" "chgrp-deny" ]
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-06-28 23:13:55 +00:00
|
|
|
Global mount options that apply to every FUSE volume.
|
|
|
|
You can define volume-specific options in the volume definitions.
|
|
|
|
'';
|
|
|
|
};
|
2022-04-15 01:41:22 +00:00
|
|
|
|
|
|
|
debugLevel = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
|
|
|
example = 1;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-04-15 01:41:22 +00:00
|
|
|
Sets the Debug-Level. 0 disables debugging, 1 enables pam_mount tracing,
|
|
|
|
and 2 additionally enables tracing in mount.crypt. The default is 0.
|
2022-08-12 12:06:08 +00:00
|
|
|
For more information, visit <http://pam-mount.sourceforge.net/pam_mount.conf.5.html>.
|
2022-04-15 01:41:22 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logoutWait = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-04-15 01:41:22 +00:00
|
|
|
Amount of microseconds to wait until killing remaining processes after
|
|
|
|
final logout.
|
2022-08-12 12:06:08 +00:00
|
|
|
For more information, visit <http://pam-mount.sourceforge.net/pam_mount.conf.5.html>.
|
2022-04-15 01:41:22 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logoutHup = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-04-15 01:41:22 +00:00
|
|
|
Kill remaining processes after logout by sending a SIGHUP.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logoutTerm = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-04-15 01:41:22 +00:00
|
|
|
Kill remaining processes after logout by sending a SIGTERM.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logoutKill = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-04-15 01:41:22 +00:00
|
|
|
Kill remaining processes after logout by sending a SIGKILL.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
createMountPoints = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-04-15 01:41:22 +00:00
|
|
|
Create mountpoints for volumes if they do not exist.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
removeCreatedMountPoints = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-04-15 01:41:22 +00:00
|
|
|
Remove mountpoints created by pam_mount after logout. This
|
|
|
|
only affects mountpoints that have been created by pam_mount
|
|
|
|
in the same session.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.enable || anyPamMount) {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.pam_mount ];
|
|
|
|
environment.etc."security/pam_mount.conf.xml" = {
|
|
|
|
source =
|
|
|
|
let
|
2020-10-20 17:27:49 +00:00
|
|
|
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
|
|
|
|
"<volume ${concatStringsSep " " (mapAttrsToList mkAttr attrs)} />\n";
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
pkgs.writeText "pam_mount.conf.xml" ''
|
|
|
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
|
|
<!DOCTYPE pam_mount SYSTEM "pam_mount.conf.xml.dtd">
|
|
|
|
<!-- auto generated from Nixos: modules/config/users-groups.nix -->
|
|
|
|
<pam_mount>
|
2022-04-15 01:41:22 +00:00
|
|
|
<debug enable="${toString cfg.debugLevel}" />
|
2020-04-24 23:36:52 +00:00
|
|
|
<!-- if activated, requires ofl from hxtools to be present -->
|
2022-04-15 01:41:22 +00:00
|
|
|
<logout wait="${toString cfg.logoutWait}" hup="${if cfg.logoutHup then "yes" else "no"}" term="${if cfg.logoutTerm then "yes" else "no"}" kill="${if cfg.logoutKill then "yes" else "no"}" />
|
2020-04-24 23:36:52 +00:00
|
|
|
<!-- set PATH variable for pam_mount module -->
|
2021-06-28 23:13:55 +00:00
|
|
|
<path>${makeBinPath ([ pkgs.util-linux ] ++ cfg.additionalSearchPaths)}</path>
|
2020-04-24 23:36:52 +00:00
|
|
|
<!-- create mount point if not present -->
|
2022-04-15 01:41:22 +00:00
|
|
|
<mkmountpoint enable="${if cfg.createMountPoints then "1" else "0"}" remove="${if cfg.removeCreatedMountPoints then "true" else "false"}" />
|
2020-04-24 23:36:52 +00:00
|
|
|
<!-- specify the binaries to be called -->
|
2021-06-28 23:13:55 +00:00
|
|
|
<fusemount>${pkgs.fuse}/bin/mount.fuse %(VOLUME) %(MNTPT) -o ${concatStringsSep "," (cfg.fuseMountOptions ++ [ "%(OPTIONS)" ])}</fusemount>
|
2022-04-15 01:41:22 +00:00
|
|
|
<fuseumount>${pkgs.fuse}/bin/fusermount -u %(MNTPT)</fuseumount>
|
2020-04-24 23:36:52 +00:00
|
|
|
<cryptmount>${pkgs.pam_mount}/bin/mount.crypt %(VOLUME) %(MNTPT)</cryptmount>
|
|
|
|
<cryptumount>${pkgs.pam_mount}/bin/umount.crypt %(MNTPT)</cryptumount>
|
|
|
|
<pmvarrun>${pkgs.pam_mount}/bin/pmvarrun -u %(USER) -o %(OPERATION)</pmvarrun>
|
2022-04-15 01:41:22 +00:00
|
|
|
${optionalString oflRequired "<ofl>${fake_ofl}/bin/fake_ofl %(SIGNAL) %(MNTPT)</ofl>"}
|
2020-04-24 23:36:52 +00:00
|
|
|
${concatStrings (map userVolumeEntry (attrValues extraUserVolumes))}
|
|
|
|
${concatStringsSep "\n" cfg.extraVolumes}
|
|
|
|
</pam_mount>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|