Compare commits
1 Commits
c6d7399d64
...
add-steam-
| Author | SHA1 | Date | |
|---|---|---|---|
| 24a09a9922 |
@@ -20,5 +20,6 @@ with lib;
|
|||||||
./kde.nix
|
./kde.nix
|
||||||
./programs.nix
|
./programs.nix
|
||||||
./sddm.nix
|
./sddm.nix
|
||||||
|
./steam-sleep-inhibitor.nix
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
116
roles/desktop/steam-sleep-inhibitor.nix
Normal file
116
roles/desktop/steam-sleep-inhibitor.nix
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
{ lib, config, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.roles.desktop;
|
||||||
|
|
||||||
|
steamSleepInhibitor = pkgs.writeShellScript "steam-sleep-inhibitor" ''
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Steam log path - adjust if different
|
||||||
|
STEAM_LOG="$HOME/.local/share/Steam/logs/streaming_log.txt"
|
||||||
|
FALLBACK_LOG="$HOME/.steam/steam/logs/streaming_log.txt"
|
||||||
|
|
||||||
|
# Find Steam log file
|
||||||
|
if [[ -f "$STEAM_LOG" ]]; then
|
||||||
|
LOG_FILE="$STEAM_LOG"
|
||||||
|
elif [[ -f "$FALLBACK_LOG" ]]; then
|
||||||
|
LOG_FILE="$FALLBACK_LOG"
|
||||||
|
else
|
||||||
|
# Monitor Steam process for streaming activity
|
||||||
|
LOG_FILE=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
INHIBITOR_PID=""
|
||||||
|
MONITORING=false
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
if [[ -n "$INHIBITOR_PID" ]]; then
|
||||||
|
echo "Stopping sleep inhibitor (PID: $INHIBITOR_PID)"
|
||||||
|
kill "$INHIBITOR_PID" 2>/dev/null
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
start_inhibitor() {
|
||||||
|
if [[ -z "$INHIBITOR_PID" ]]; then
|
||||||
|
echo "Starting sleep inhibitor for Steam Remote Play session"
|
||||||
|
${pkgs.systemd}/bin/systemd-inhibit \
|
||||||
|
--what=sleep \
|
||||||
|
--who="Steam Remote Play" \
|
||||||
|
--why="Active streaming session detected" \
|
||||||
|
--mode=block \
|
||||||
|
sleep infinity &
|
||||||
|
INHIBITOR_PID=$!
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
stop_inhibitor() {
|
||||||
|
if [[ -n "$INHIBITOR_PID" ]]; then
|
||||||
|
echo "Stopping sleep inhibitor - streaming session ended"
|
||||||
|
kill "$INHIBITOR_PID" 2>/dev/null
|
||||||
|
INHIBITOR_PID=""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if Steam Remote Play is active by looking for streaming processes
|
||||||
|
check_streaming_active() {
|
||||||
|
# Check for Steam streaming processes
|
||||||
|
if pgrep -f "streaming_client" >/dev/null || \
|
||||||
|
pgrep -f "steamremoteplay" >/dev/null || \
|
||||||
|
${pkgs.procps}/bin/pgrep -f "Remote Play" >/dev/null; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for active network connections on Steam streaming ports
|
||||||
|
if ${pkgs.nettools}/bin/netstat -an 2>/dev/null | grep -E ":(27036|27037)" | grep ESTABLISHED >/dev/null; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
trap cleanup EXIT INT TERM
|
||||||
|
|
||||||
|
echo "Steam sleep inhibitor monitoring started"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
if check_streaming_active; then
|
||||||
|
if [[ "$MONITORING" == "false" ]]; then
|
||||||
|
MONITORING=true
|
||||||
|
start_inhibitor
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [[ "$MONITORING" == "true" ]]; then
|
||||||
|
MONITORING=false
|
||||||
|
stop_inhibitor
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
config = mkIf (cfg.enable && cfg.kde && cfg.gaming) {
|
||||||
|
# Steam streaming sleep inhibitor service
|
||||||
|
systemd.user.services.steam-sleep-inhibitor = {
|
||||||
|
description = "Steam Remote Play Sleep Inhibitor";
|
||||||
|
wantedBy = [ "default.target" ];
|
||||||
|
after = [ "graphical-session.target" ];
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "simple";
|
||||||
|
ExecStart = "${steamSleepInhibitor}";
|
||||||
|
Restart = "always";
|
||||||
|
RestartSec = "5";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# Steam-specific environment variables to prevent sleep interference
|
||||||
|
environment.sessionVariables = {
|
||||||
|
SDL_VIDEO_ALLOW_SCREENSAVER = "1";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user