2015-07-02 16:46:56 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.security.pam.mount;
|
|
|
|
|
2022-04-03 08:10:37 +02: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
|
|
|
|
'';
|
|
|
|
|
2015-07-02 16:46:56 +02:00
|
|
|
anyPamMount = any (attrByPath ["pamMount"] false) (attrValues config.security.pam.services);
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
|
|
|
security.pam.mount = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2015-07-02 16:46:56 +02:00
|
|
|
Enable PAM mount system to mount fileystems on user login.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraVolumes = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2022-08-03 22:46:41 +02:00
|
|
|
description = lib.mdDoc ''
|
2015-07-02 16:46:56 +02:00
|
|
|
List of volume definitions for pam_mount.
|
2022-08-03 22:46:41 +02:00
|
|
|
For more information, visit <http://pam-mount.sourceforge.net/pam_mount.conf.5.html>.
|
2015-07-02 16:46:56 +02:00
|
|
|
'';
|
|
|
|
};
|
2021-06-08 22:06:28 +02:00
|
|
|
|
|
|
|
additionalSearchPaths = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [];
|
2021-10-03 18:06:03 +02:00
|
|
|
example = literalExpression "[ pkgs.bindfs ]";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2021-06-08 22:06:28 +02: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-03 18:06:03 +02:00
|
|
|
example = literalExpression ''
|
2021-06-08 22:06:28 +02:00
|
|
|
[ "nodev" "nosuid" "force-user=%(USER)" "gid=%(USERGID)" "perms=0700" "chmod-deny" "chown-deny" "chgrp-deny" ]
|
|
|
|
'';
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2021-06-08 22:06:28 +02:00
|
|
|
Global mount options that apply to every FUSE volume.
|
|
|
|
You can define volume-specific options in the volume definitions.
|
|
|
|
'';
|
|
|
|
};
|
2022-04-03 08:10:37 +02:00
|
|
|
|
|
|
|
debugLevel = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
|
|
|
example = 1;
|
2022-08-03 22:46:41 +02:00
|
|
|
description = lib.mdDoc ''
|
2022-04-03 08:10:37 +02: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-03 22:46:41 +02:00
|
|
|
For more information, visit <http://pam-mount.sourceforge.net/pam_mount.conf.5.html>.
|
2022-04-03 08:10:37 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logoutWait = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
2022-08-03 22:46:41 +02:00
|
|
|
description = lib.mdDoc ''
|
2022-04-03 08:10:37 +02:00
|
|
|
Amount of microseconds to wait until killing remaining processes after
|
|
|
|
final logout.
|
2022-08-03 22:46:41 +02:00
|
|
|
For more information, visit <http://pam-mount.sourceforge.net/pam_mount.conf.5.html>.
|
2022-04-03 08:10:37 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logoutHup = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2022-04-03 08:10:37 +02:00
|
|
|
Kill remaining processes after logout by sending a SIGHUP.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logoutTerm = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2022-04-03 08:10:37 +02:00
|
|
|
Kill remaining processes after logout by sending a SIGTERM.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logoutKill = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2022-04-03 08:10:37 +02:00
|
|
|
Kill remaining processes after logout by sending a SIGKILL.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
createMountPoints = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2022-04-03 08:10:37 +02:00
|
|
|
Create mountpoints for volumes if they do not exist.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
removeCreatedMountPoints = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2022-04-03 08:10:37 +02:00
|
|
|
Remove mountpoints created by pam_mount after logout. This
|
|
|
|
only affects mountpoints that have been created by pam_mount
|
|
|
|
in the same session.
|
|
|
|
'';
|
|
|
|
};
|
2015-07-02 16:46:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.enable || anyPamMount) {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.pam_mount ];
|
2019-09-14 19:51:29 +02:00
|
|
|
environment.etc."security/pam_mount.conf.xml" = {
|
2015-07-02 16:46:56 +02:00
|
|
|
source =
|
|
|
|
let
|
2020-10-15 02:29:30 +02: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";
|
2015-07-02 16:46:56 +02: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-03 08:10:37 +02:00
|
|
|
<debug enable="${toString cfg.debugLevel}" />
|
2015-07-02 16:46:56 +02:00
|
|
|
<!-- if activated, requires ofl from hxtools to be present -->
|
2022-04-03 08:10:37 +02: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"}" />
|
2015-07-02 16:46:56 +02:00
|
|
|
<!-- set PATH variable for pam_mount module -->
|
2021-06-08 22:06:28 +02:00
|
|
|
<path>${makeBinPath ([ pkgs.util-linux ] ++ cfg.additionalSearchPaths)}</path>
|
2015-07-02 16:46:56 +02:00
|
|
|
<!-- create mount point if not present -->
|
2022-04-03 08:10:37 +02:00
|
|
|
<mkmountpoint enable="${if cfg.createMountPoints then "1" else "0"}" remove="${if cfg.removeCreatedMountPoints then "true" else "false"}" />
|
2015-07-02 16:46:56 +02:00
|
|
|
<!-- specify the binaries to be called -->
|
2021-06-08 22:06:28 +02:00
|
|
|
<fusemount>${pkgs.fuse}/bin/mount.fuse %(VOLUME) %(MNTPT) -o ${concatStringsSep "," (cfg.fuseMountOptions ++ [ "%(OPTIONS)" ])}</fusemount>
|
2022-04-03 08:10:37 +02:00
|
|
|
<fuseumount>${pkgs.fuse}/bin/fusermount -u %(MNTPT)</fuseumount>
|
2015-07-02 16:46:56 +02: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-03 08:10:37 +02:00
|
|
|
${optionalString oflRequired "<ofl>${fake_ofl}/bin/fake_ofl %(SIGNAL) %(MNTPT)</ofl>"}
|
2019-11-03 05:43:01 +01:00
|
|
|
${concatStrings (map userVolumeEntry (attrValues extraUserVolumes))}
|
|
|
|
${concatStringsSep "\n" cfg.extraVolumes}
|
2015-07-02 16:46:56 +02:00
|
|
|
</pam_mount>
|
|
|
|
'';
|
2019-09-14 19:51:29 +02:00
|
|
|
};
|
2015-07-02 16:46:56 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|