Skip to content

Commit 210f71d

Browse files
committed
Merge branch 'tmpfs-home-per-login' into nfs-on-desktops
branch 'tmpfs-home-per-login' (config to mount a tmpfs for each users' home directory on login) contains a script that copies /etc/skel to a newly mounted tmpfs home on login via pam_exec. this script will be modified to also set up ~/remote when remote home directories are mounted at /remote with nfs.
2 parents 2836f98 + dfb4d08 commit 210f71d

5 files changed

Lines changed: 113 additions & 32 deletions

File tree

modules/graphical/apps/browsers.nix

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,17 @@ in
6666
OfferToSaveLoginsDefault = false;
6767
HttpsOnlyMode = "enabled";
6868

69-
SanitizeOnShutdown = {
70-
Cache = true;
71-
Cookies = true;
72-
Downloads = true;
73-
FormData = true;
74-
History = true;
75-
Sessions = true;
76-
SiteSettings = true;
77-
OfflineApps = true;
78-
};
69+
# not needed since home directories are on tmpfs
70+
#SanitizeOnShutdown = {
71+
# Cache = true;
72+
# Cookies = true;
73+
# Downloads = true;
74+
# FormData = true;
75+
# History = true;
76+
# Sessions = true;
77+
# SiteSettings = true;
78+
# OfflineApps = true;
79+
#};
7980

8081
DontCheckDefaultBrowser = true;
8182
DisableBuiltinPDFViewer = true;

modules/home/home.nix

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
lib,
3+
config,
4+
pkgs,
5+
...
6+
}:
7+
8+
let
9+
cfg = config.ocf.home;
10+
homeSetupScript = pkgs.writeShellScript "ocf_setup_home" (builtins.readFile ./ocf_setup_home.sh);
11+
remoteHost = "tsunami";
12+
13+
# Default openssh doesn't include GSSAPI support, so we need to override sshfs
14+
# to use the openssh_gssapi package instead. This is annoying because the
15+
# sshfs package's openssh argument is nested in another layer of callPackage,
16+
# so we override callPackage instead to override openssh.
17+
sshfs = pkgs.sshfs.override {
18+
callPackage =
19+
fn: args:
20+
(pkgs.callPackage fn args).override {
21+
openssh = pkgs.openssh_gssapi;
22+
};
23+
};
24+
in
25+
{
26+
options.ocf.home = {
27+
tmpfs = lib.mkEnableOption "mount tmpfs on /home and each user's home directory (unmounted on logout)";
28+
#TODO mountRemote = lib.mkEnableOption "sshfs mount ${remoteHost}:~ on ~/remote";
29+
};
30+
31+
config = lib.mkIf cfg.tmpfs {
32+
fileSystems."/home" = {
33+
device = "tmpfs";
34+
fsType = "tmpfs";
35+
options = [
36+
"size=16G"
37+
"mode=755"
38+
];
39+
};
40+
41+
security.pam = {
42+
# Trim spaces from username
43+
services.login.rules.auth.trimspaces = {
44+
control = "requisite";
45+
modulePath = "${pkgs.ocf-pam_trimspaces}/lib/security/pam_trimspaces.so";
46+
order = 0;
47+
};
48+
49+
services.login.pamMount = true;
50+
51+
# needed to mount ~/remote with kerberos ssh auth
52+
services.login.rules.session.mount.order =
53+
config.security.pam.services.login.rules.session.krb5.order + 50;
54+
55+
# mount ~ and ~/remote
56+
mount.extraVolumes = [
57+
''<volume fstype="tmpfs" path="tmpfs" mountpoint="~" options="uid=%(USERUID),gid=%(USERGID),mode=0700"/>''
58+
# TODO: enable StrictHostKeyChecking and UserKnownHostsFile because these should not be disabled!
59+
''<volume fstype="fuse" path="${lib.getExe sshfs}#%(USER)@${remoteHost}:" mountpoint="~/remote/" options="follow_symlinks,UserKnownHostsFile=/dev/null,StrictHostKeyChecking=no" pgrp="ocf" />''
60+
];
61+
62+
# because mount now creates the home dir and mounts tmpfs on it, mkhomedir wont copy the skel because the dir exists
63+
# we can do copy skel as part of a home setup script, and do other stuff as well
64+
#services.login.rules.session.mkhomedir.order = config.security.pam.services.login.rules.session.mount.order + 50;
65+
#makeHomeDir.skelDirectory = "/etc/skel";
66+
67+
services.login.rules.session.ocf_home_setup = {
68+
order = config.security.pam.services.login.rules.session.mount.order + 50;
69+
control = "optional";
70+
modulePath = "pam_exec.so";
71+
args = [ "${homeSetupScript}" ];
72+
};
73+
};
74+
};
75+
}

modules/home/ocf_setup_home.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
user_home="$(getent passwd "$PAM_USER" | cut -d: -f6)"
4+
user_gid="$(getent passwd "$PAM_USER" | cut -d: -f4)"
5+
6+
umask 0077
7+
8+
case "$PAM_TYPE" in
9+
open_session)
10+
# populate users tmpfs home with skel
11+
# check to make sure that the directory is actually empty
12+
# FIXME: expects findutils to exist
13+
if [ -d "$user_home" ] && [ -z "$(find "$user_home" -maxdepth 0 -empty)" ]; then
14+
# /etc/skel is read only because its in the nix store.
15+
# we should follow umask like how pam_mkhomedir does
16+
cp -rT --no-preserve=mode /etc/skel/ "$user_home/"
17+
chown -R "$PAM_USER:$user_gid" "$user_home/"
18+
fi
19+
20+
# TODO: run desktoprc here
21+
;;
22+
close_session)
23+
# unmount everything under the users home dir
24+
umount --recursive "$USER_HOME"
25+
;;
26+
esac

modules/tmpfs-home.nix

Lines changed: 0 additions & 21 deletions
This file was deleted.

profiles/desktop.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ in
3232
acme.enable = false;
3333

3434
etc.enable = true;
35-
tmpfsHome.enable = true;
35+
home.tmpfs = true;
3636
network.wakeOnLan.enable = true;
3737
logged-in-users-exporter.enable = true;
3838

0 commit comments

Comments
 (0)