nixos-configs/devices/bbsteamie/modules/desktop/session-switching.nix
matt1432 8c8c62bb6e
All checks were successful
Discord / discord commits (push) Has been skipped
feat(bbsteamie): add setup for palia map
2024-07-27 15:22:55 -04:00

90 lines
1.8 KiB
Nix

defaultSession: {
config,
lib,
pkgs,
...
}: let
inherit (lib) getExe mkForce;
inherit (config.vars) mainUser;
switch-session = pkgs.writeShellApplication {
name = "switch-session";
text = ''
mkdir -p /etc/sddm.conf.d
cat <<EOF | tee /etc/sddm.conf.d/autologin.conf
[Autologin]
User=${mainUser}
Session=$1
Relogin=true
EOF
'';
};
gaming-mode = pkgs.writeShellScriptBin "gaming-mode" ''
sudo ${pkgs.systemd}/bin/systemctl start to-gaming-mode.service
'';
in {
services = {
displayManager = {
sddm = {
enable = true;
autoLogin.relogin = true;
};
};
# Needed for sddm TODO: look into wayland SDDM?
xserver.enable = true;
};
# Sets the default session at launch
systemd.services."set-session" = {
wantedBy = ["multi-user.target"];
before = ["display-manager.service"];
path = [switch-session];
script = ''
switch-session "${defaultSession}"
'';
};
# Allows switching to gaming mode
systemd.services."to-gaming-mode" = {
wantedBy = mkForce [];
path = [switch-session];
script = ''
switch-session "gamescope-wayland"
systemctl restart display-manager
sleep 10
switch-session "${defaultSession}"
'';
};
# Make it so we don't need root to switch to gaming mode
security.sudo.extraRules = [
{
users = [mainUser];
groups = [100];
commands = [
{
command = "${pkgs.systemd}/bin/systemctl start to-gaming-mode.service";
options = ["SETENV" "NOPASSWD"];
}
];
}
];
# Add desktop entry to make it GUI friendly
home-manager.users.${mainUser}.xdg.desktopEntries."Gaming Mode" = {
name = "Gaming Mode";
exec = getExe gaming-mode;
icon = "steam";
terminal = false;
type = "Application";
};
}