130 lines
4.7 KiB
Nix
130 lines
4.7 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
let
|
|
cfgUser = "dominik"; # Adjust to your username
|
|
in {
|
|
#### 1) Provide two scripts:
|
|
#### - `steam-deck-mode.sh`: Runs Steam Big Picture with Gamescope (Wayland).
|
|
#### - `sway-session.sh`: Starts Sway.
|
|
environment.etc."steam-deck-mode.sh".text = ''
|
|
#!/usr/bin/env bash
|
|
|
|
# This script launches Steam in Big Picture mode under Gamescope (Wayland).
|
|
# Once Steam (or Gamescope) exits, the systemd user service stops.
|
|
# The ExecStopPost hook in the user service will then start Sway automatically.
|
|
|
|
# For safety, kill any existing Steam instance
|
|
pgrep steam && steam -shutdown || true
|
|
sleep 1
|
|
|
|
# Use Gamescope in fullscreen mode, exit on Steam exit, run Steam in Gamepad UI
|
|
exec gamescope -W 1280 -H 800 -f -e -- steam -gamepadui
|
|
'';
|
|
|
|
environment.etc."sway-session.sh".text = ''
|
|
#!/usr/bin/env bash
|
|
|
|
# This script starts a Sway session. When Sway exits, the user service stops,
|
|
# which triggers ExecStopPost to start Steam Big Picture again.
|
|
|
|
exec sway
|
|
'';
|
|
|
|
#### Make these scripts executable via a simple systemd service:
|
|
systemd.services."make-scripts-executable" = {
|
|
description = "Make steam-deck-mode.sh and sway-session.sh executable";
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig.ExecStart = [
|
|
"${pkgs.coreutils}/bin/chmod +x /etc/steam-deck-mode.sh"
|
|
"${pkgs.coreutils}/bin/chmod +x /etc/sway-session.sh"
|
|
];
|
|
};
|
|
|
|
#### 2) Create two systemd *user* services:
|
|
#### - steam-deck-mode: On stop, automatically start sway
|
|
#### - sway: On stop, automatically start steam-deck-mode
|
|
systemd.user.services."steam-deck-mode" = {
|
|
description = "Steam Deck Mode (Wayland Gamescope + Steam Big Picture)";
|
|
wantedBy = [ "default.target" ]; # So we can enable it for the user
|
|
serviceConfig = {
|
|
Type = "simple";
|
|
ExecStart = "/etc/steam-deck-mode.sh";
|
|
# On exit, automatically trigger Sway
|
|
ExecStopPost = "${pkgs.systemd}/bin/systemctl --user start sway";
|
|
Restart = "no"; # If Steam crashes, you can change to 'on-failure' if desired
|
|
};
|
|
};
|
|
|
|
systemd.user.services."sway" = {
|
|
description = "Sway WM Session";
|
|
wantedBy = [ ]; # We won't start this on login by default, but from steam or a script
|
|
serviceConfig = {
|
|
Type = "simple";
|
|
ExecStart = "/etc/sway-session.sh";
|
|
# On exit, automatically trigger Steam Deck Mode
|
|
ExecStopPost = "${pkgs.systemd}/bin/systemctl --user start steam-deck-mode";
|
|
Restart = "no";
|
|
};
|
|
};
|
|
|
|
#### 3) Provide a script & desktop entry to let you switch from Sway to Game Mode easily
|
|
#### (i.e., stop the 'sway' service, which triggers Steam).
|
|
environment.etc."switch-to-game-mode.sh".text = ''
|
|
#!/usr/bin/env bash
|
|
# This script stops Sway, causing the user service to exit
|
|
# The ExecStopPost of that service will start steam-deck-mode automatically.
|
|
${pkgs.systemd}/bin/systemctl --user stop sway
|
|
'';
|
|
|
|
systemd.services."make-switch-to-game-mode-executable" = {
|
|
description = "Make switch-to-game-mode.sh executable";
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig.ExecStart = [
|
|
"${pkgs.coreutils}/bin/chmod +x /etc/switch-to-game-mode.sh"
|
|
];
|
|
};
|
|
|
|
environment.etc."xdg/applications/switch-to-game-mode.desktop".text = ''
|
|
[Desktop Entry]
|
|
Name=Switch to Game Mode
|
|
Comment=Stop Sway and start Steam Big Picture (Gamescope)
|
|
Exec=/etc/switch-to-game-mode.sh
|
|
Terminal=false
|
|
Type=Application
|
|
Categories=Game;
|
|
'';
|
|
|
|
#### 4) If you want to start directly in Steam Deck Mode on boot (no display manager),
|
|
#### enable auto-login on TTY and run the user service for "dominik".
|
|
#### For example (uncomment if you want an immediate console login):
|
|
# services.getty.autologinUser = cfgUser;
|
|
# systemd.user.services."steam-deck-mode".wantedBy = [ "default.target" ]; # already set
|
|
# You'd do 'systemctl --user enable steam-deck-mode' as that user to start it on login.
|
|
|
|
#### 5) Additional recommended gaming packages if not set elsewhere:
|
|
environment.systemPackages = with pkgs; [
|
|
steam
|
|
gamemode
|
|
mangohud
|
|
vulkan-tools
|
|
vulkan-loader
|
|
vulkan-headers
|
|
# ...
|
|
];
|
|
|
|
#### 6) Enable 32-bit support for Steam
|
|
hardware.opengl.enable = true;
|
|
hardware.opengl.driSupport32Bit = true;
|
|
hardware.graphics.enable = true;
|
|
hardware.graphics.enable32Bit = true;
|
|
hardware.graphics.extraPackages = [
|
|
pkgs.amdvlk
|
|
pkgs.driversi686Linux.amdvlk
|
|
];
|
|
|
|
#### 7) Optionally handle udev rules for Steam/Controllers if needed
|
|
environment.etc."udev/rules.d/99-steamdeck-controller.rules".text = ''
|
|
SUBSYSTEM=="usb", ATTRS{idVendor}=="28de", MODE="0666"
|
|
KERNEL=="uinput", MODE="0660", GROUP="input", OPTIONS+="static_node=uinput"
|
|
'';
|
|
}
|