Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom PAM rule for desktop login #939

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions modules/common/users/admin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ in
extraGroups =
[
"wheel"
"video"
]
++ cfg.extraGroups
++ optionals cfg.createHome [ "desktop" ]
++ optionals cfg.createHome [
"audio"
"video"
]
++ optionals config.security.tpm2.enable [ "tss" ]
++ optionals config.ghaf.virtualization.docker.daemon.enable [ "docker" ];
};
Expand Down
15 changes: 6 additions & 9 deletions modules/common/users/desktop.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ let
extraGroups = mkOption {
description = "Extra groups for the login user.";
type = types.listOf types.str;
default = [ ];
default = [
"audio"
"video"
];
};
homeSize = mkOption {
description = ''
Expand Down Expand Up @@ -137,12 +140,6 @@ in
members = [ cfg.appUser.name ];
};
})
{
"desktop" = {
name = "desktop";
members = [ ];
};
}
];
};
}
Expand Down Expand Up @@ -177,9 +174,9 @@ in
echo -n "Enter your user name: "
read -e -r USERNAME
USERNAME=''${USERNAME// /_}
USERNAME=''${USERNAME//[^a-zA-Z0-9_]/}
USERNAME=''${USERNAME//[^a-zA-Z0-9_-]/}
USERNAME=''$(echo -n "$USERNAME" | tr '[:upper:]' '[:lower:]')
if grep -q -w "$USERNAME:" /etc/passwd; then
if grep -q "$USERNAME:" /etc/passwd; then
echo "User $USERNAME already exists. Please choose another user name."
else
ACCEPTABLE_USER=true
Expand Down
30 changes: 27 additions & 3 deletions modules/desktop/graphics/labwc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,37 @@ in
XDG_DATA_HOME = "$HOME/.local/share";
XDG_STATE_HOME = "$HOME/.local/state";
XDG_CACHE_HOME = "$HOME/.cache";
XDG_PICTURES_DIR = "$HOME/Pictures";
XDG_VIDEOS_DIR = "$HOME/Videos";
GSETTINGS_SCHEMA_DIR = "${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}/glib-2.0/schemas";
};
};

# It will create a /etc/pam.d/ file for authentication
security.pam.services.gtklock = { };
# Create custom PAM rules
security.pam.services = {
gtklock = {
rules.auth = {
systemd_home.order = 11399; # Re-order to allow either password _or_ fingerprint
fprintd.args = [ "maxtries=3" ];
};
};
greetd = {
fprintAuth = false; # User needs to enter password to decrypt home
rules = {
account.group = {
enable = true;
control = "requisite";
modulePath = "${pkgs.linux-pam}/lib/security/pam_succeed_if.so";
order = 10000;
args = [
"user"
"ingroup"
"video"
];
};
};
};
};

# Needed for power commands
security.polkit.enable = true;
Expand All @@ -179,7 +204,6 @@ in
BindsTo = [ "graphical-session.target" ];
After = [ "graphical-session-pre.target" ];
Wants = [ "graphical-session-pre.target" ];
ConditionGroup = "desktop";
};
};

Expand Down
2 changes: 0 additions & 2 deletions modules/microvm/virtualization/microvm/appvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ let
users.appUser = {
enable = true;
extraGroups = [
"audio"
"video"
"users"
];
};
Expand Down
1 change: 0 additions & 1 deletion modules/microvm/virtualization/microvm/audiovm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ let
enable = true;
extraGroups = [
"audio"
"video"
"pipewire"
];
};
Expand Down
24 changes: 1 addition & 23 deletions modules/microvm/virtualization/microvm/guivm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,7 @@ let
applications.enable = false;
graphics.enable = true;
};
users = {
loginUser = {
enable = true;
extraGroups = [
"audio"
"video"
"desktop"
];
};
};

users.loginUser.enable = true;
development = {
ssh.daemon.enable = lib.mkDefault config.ghaf.development.ssh.daemon.enable;
debug.tools.enable = lib.mkDefault config.ghaf.development.debug.tools.enable;
Expand All @@ -108,14 +98,6 @@ let
storagevm = {
enable = true;
name = vmName;
directories = [
{
directory = "/var/lib/private/ollama";
user = "ollama";
group = "ollama";
mode = "u=rwx,g=,o=";
}
];
};

# Services
Expand Down Expand Up @@ -219,10 +201,6 @@ let
pkgs.libva-utils
pkgs.glib
];
sessionVariables = {
XDG_PICTURES_DIR = "$HOME/Pictures";
XDG_VIDEOS_DIR = "$HOME/Videos";
};
};

time.timeZone = config.time.timeZone;
Expand Down
4 changes: 1 addition & 3 deletions modules/microvm/virtualization/microvm/microvm-host.nix
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,13 @@ in
'';
};
in
mkIf config.ghaf.profiles.debug.enable {
{
description = "Remove ghaf login users";
enable = true;
path = [ userRemovalScript ];
unitConfig.ConditionPathExists = "/storagevm/gui-vm/var/lib/nixos/user.lock";
serviceConfig = {
Type = "oneshot";
StandardOutput = "journal";
StandardError = "journal";
ExecStart = "${userRemovalScript}/bin/remove-users";
};
};
Expand Down
46 changes: 28 additions & 18 deletions modules/reference/services/ollama/ollama.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@
}:
let
cfg = config.ghaf.reference.services;
inherit (lib) mkIf;
inherit (lib) mkIf optionalAttrs;
in
{
config = mkIf cfg.ollama {
services.ollama = {
enable = true;
openFirewall = true;
host = "0.0.0.0";
host = "127.0.0.1";
};

ghaf = optionalAttrs (builtins.hasAttr "storagevm" config.ghaf) {
storagevm.directories = [
{
directory = "/var/lib/private/ollama";
mode = "u=rwx,g=,o=";
}
];
};

environment.systemPackages = [
Expand Down Expand Up @@ -72,23 +81,24 @@ in
# its own.
system.userActivationScripts.alpaca-configure = {
text = ''
source ${config.system.build.setEnvironment}
mkdir -p $HOME/.config/com.jeffser.Alpaca
cat <<EOF > $HOME/.config/com.jeffser.Alpaca/server.json
[[ "$UID" != ${toString config.ghaf.users.loginUser.uid} ]] && exit 0
source ${config.system.build.setEnvironment}
mkdir -p $HOME/.config/com.jeffser.Alpaca
cat <<EOF > $HOME/.config/com.jeffser.Alpaca/server.json
{
"remote_url": "http://localhost:11434",
"remote_bearer_token": "",
"run_remote": true,
"local_port": 11435,
"run_on_background": false,
"powersaver_warning": true,
"model_tweaks": {
"temperature": 0.7,
"seed": 0,
"keep_alive": 5
},
"ollama_overrides": {},
"idle_timer": 0
"remote_url": "http://localhost:11434",
"remote_bearer_token": "",
"run_remote": true,
"local_port": 11435,
"run_on_background": false,
"powersaver_warning": true,
"model_tweaks": {
"temperature": 0.7,
"seed": 0,
"keep_alive": 5
},
"ollama_overrides": {},
"idle_timer": 0
}
EOF
'';
Expand Down
Loading