nixdots/system/roles/workstation/display/login/greetd.nix

79 lines
2.6 KiB
Nix
Raw Normal View History

2024-06-24 23:32:59 +00:00
{
config,
pkgs,
lib,
...
}: let
inherit (lib) mkIf getExe;
inherit (lib.strings) concatStringsSep;
deviceType = config.myOptions.device.roles.type;
acceptedTypes = ["laptop" "desktop"];
2024-06-25 00:10:39 +00:00
greetingMsg = "'Access is restricted to authorized personnel only.'";
tuiGreetTheme = "'border=magenta;text=cyan;prompt=green;time=red;action=white;button=yellow;container=black;input=gray'";
2024-06-24 23:32:59 +00:00
sessionData = config.services.displayManager.sessionData.desktops;
# Run the session / application using the appropriate shell configured for this user.
# This will make sure all of the environment variables are set before the WM session
# is started. This is very important, as without it, variables for things like qt theme
# will not be set, and applications executed by the WM will not be themed properly.
sessionWrapperScript = pkgs.writeShellScriptBin "tuigreet-session-wrapper" ''
set -euo pipefail
script_name="$0"
shell="$(getent passwd itsdrike | awk -F: '{print $NF}')"
command=("$@")
exec "$shell" -c 'exec "$@"' "$script_name" "''${command[@]}"
'';
2024-06-24 23:32:59 +00:00
defaultSession = {
user = "greeter";
command = concatStringsSep " " [
(getExe pkgs.greetd.tuigreet)
"--time"
"--remember"
"--remember-user-session"
"--asterisks"
2024-06-25 00:10:39 +00:00
"--greeting ${greetingMsg}"
"--theme ${tuiGreetTheme}"
2024-06-27 12:35:16 +00:00
"--sessions '${sessionData}/share/wayland-sessions'"
"--xsessions '${sessionData}/share/xsessions'"
"--session-wrapper ${sessionWrapperScript}/bin/tuigreet-session-wrapper"
2024-06-27 14:29:47 +00:00
"--xsession-wrapper ${sessionWrapperScript}/bin/tuigreet-session-wrapper startx /usr/bin/env"
2024-06-24 23:32:59 +00:00
];
};
in {
config = mkIf (builtins.elem deviceType acceptedTypes) {
services.greetd = {
enable = true;
2024-06-25 00:10:39 +00:00
vt = 1;
2024-06-24 23:32:59 +00:00
# <https://man.sr.ht/~kennylevinsen/greetd/>
settings = {
# default session is what will be used if no session is selected
# in this case it'll be a TUI greeter
default_session = defaultSession;
};
};
# Suppress error messages on tuigreet. They sometimes obscure the TUI
# boundaries of the greeter.
# See: https://github.com/apognu/tuigreet/issues/68#issuecomment-1586359960
systemd.services.greetd.serviceConfig = {
Type = "idle";
2024-06-27 12:35:16 +00:00
StandardInput = "tty";
2024-06-24 23:32:59 +00:00
StandardOutput = "tty";
StandardError = "journal";
TTYReset = true;
TTYVHangup = true;
TTYVTDisallocate = true;
};
# Persist info about previous session & user
2024-07-26 23:07:07 +00:00
myOptions.system.impermanence.root.extraDirectories = ["/var/cache/tuigreet"];
2024-06-24 23:32:59 +00:00
};
}