nixos-configs/devices/bbsteamie/modules/desktop/session-switching.nix

91 lines
1.8 KiB
Nix
Raw Normal View History

defaultSession: {
config,
lib,
pkgs,
...
}: let
2024-06-30 12:58:09 -04:00
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 = {
2024-06-29 22:53:47 -04:00
sddm = {
enable = true;
2024-06-29 23:00:49 -04:00
autoLogin.relogin = true;
};
};
# Needed for sddm TODO: look into wayland SDDM?
xserver.enable = true;
};
2024-06-29 22:53:47 -04:00
# Sets the default session at launch
systemd.services."set-session" = {
wantedBy = ["multi-user.target"];
before = ["display-manager.service"];
path = [switch-session];
script = ''
2024-06-30 12:58:09 -04:00
switch-session "${defaultSession}"
'';
};
# Allows switching to gaming mode
systemd.services."to-gaming-mode" = {
2024-06-30 12:58:09 -04:00
wantedBy = mkForce [];
path = [switch-session];
script = ''
switch-session "gamescope-wayland"
systemctl restart display-manager
sleep 10
2024-06-30 12:58:09 -04:00
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";
};
}