Skip to content

Commit 7199556

Browse files
committed
Merge branch 'tmpfs-home-per-user' into nfs-on-desktops
branch 'tmpfs-home-per-user' 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 32e9193 + c9c32d6 commit 7199556

5 files changed

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

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)