Rework greetd start command config

Command is now listOf str, finalCommand is a shellEscapeArgs processed
command with applicable wrapper scripts applied
This commit is contained in:
NullBite 2024-03-23 20:44:39 -04:00
parent 197b557468
commit 9177f15feb
Signed by: nullbite
GPG Key ID: 6C4D545385D4925A
3 changed files with 34 additions and 7 deletions

View File

@ -65,7 +65,7 @@
}; };
}; };
services.greetd.settings.initial_session = { services.greetd.settings.initial_session = {
command = config.nixfiles.programs.greetd.settings.command; command = config.nixfiles.programs.greetd.settings.finalCommand;
user = "nullbite"; user = "nullbite";
}; };

View File

@ -1,16 +1,22 @@
{ pkgs, config, lib, options, ... }: { pkgs, config, lib, options, ... }:
let let
cfg = config.nixfiles.programs.greetd; cfg = config.nixfiles.programs.greetd;
inherit (lib.types) bool enum nullOr str path; inherit (lib.types) bool enum nullOr str path listOf;
inherit (builtins) isNull; inherit (builtins) isNull;
inherit (lib) optional optionals; inherit (lib) optional optionals;
optionalsSet = val: optionals (!(isNull val)); optionalsSet = val: optionals (!(isNull val));
optionalSet = val: optional (!(isNull val));
sessions = config.services.xserver.displayManager.sessionData.desktops; sessions = config.services.xserver.displayManager.sessionData.desktops;
xsessions = "${sessions}/share/xsessions"; xsessions = "${sessions}/share/xsessions";
wayland-sessions = "${sessions}/share/wayland-sessions"; wayland-sessions = "${sessions}/share/wayland-sessions";
loginwrap=pkgs.writeShellScriptBin "loginwrap" ''
exec "$SHELL" -lc 'exec "$@"' "login-wrapper" "$@"
'';
in in
{ {
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
environment.systemPackages = [ loginwrap ];
services.greetd = { services.greetd = {
enable = true; enable = true;
settings = { settings = {
@ -24,7 +30,10 @@ in
"--sessions" "${xsessions}:${wayland-sessions}" ] "--sessions" "${xsessions}:${wayland-sessions}" ]
++ optionalsSet st.greeting [ "--greeting" st.greeting ] ++ optionalsSet st.greeting [ "--greeting" st.greeting ]
++ optional st.time "--time" ++ optional st.time "--time"
++ optionalsSet st.command [ "--cmd" (lib.escapeShellArg st.command) ]; ++ optionalsSet st.command [ "--cmd" st.finalCommand ]
# i think tuigreet might be outdated on nix. disable this because it's not a valid option
# ++ optionalsSet st.loginShell [ "--session-wrapper" "loginwrap" ]
;
in lib.escapeShellArgs args; in lib.escapeShellArgs args;
}) })
@ -50,11 +59,29 @@ in
default = "log in pwease!! uwu"; default = "log in pwease!! uwu";
example = "something boring"; example = "something boring";
}; };
finalCommand = lib.mkOption {
description = "Final version of command";
type = nullOr str;
default = let
st = cfg.settings;
prevcmd = st.command;
command-login-wrapped = [ "loginwrap" ] ++ prevcmd;
cmd = if (builtins.isNull prevcmd) then null else
(if st.loginShell then command-login-wrapped else prevcmd);
in lib.escapeShellArgs cmd;
readOnly = true;
};
command = lib.mkOption { command = lib.mkOption {
description = "Command to run following successful authentication"; description = "Command to run following successful authentication";
type = nullOr str; type = nullOr (listOf str);
default = null; default = null;
example = "Hyprland"; example = [ "Hyprland" ];
};
loginShell = lib.mkOption {
description = "Wrap in login shell to source .profile/.zshenv/etc. (if configurable).";
type = bool;
default = true;
example = false;
}; };
time = lib.mkOption { time = lib.mkOption {
description = "Whether to show the current time (if configurable)"; description = "Whether to show the current time (if configurable)";

View File

@ -27,7 +27,7 @@ in
nixfiles.programs.greetd = { nixfiles.programs.greetd = {
enable = true; enable = true;
settings = { settings = {
command = "${pkgs.hyprland}/bin/Hyprland"; command = [ "${pkgs.hyprland}/bin/Hyprland" ];
}; };
}; };