Compare commits

..

1 Commits

Author SHA1 Message Date
24a09a9922 [desktop] Add steam sleep inhibitor
Adds sleep inhibitor based on whether or not Steam is actively streaming
a remote session
2025-07-19 15:11:33 -07:00
6 changed files with 117 additions and 133 deletions

View File

@@ -1,19 +0,0 @@
#!/usr/bin/env bash
# Build Live USB ISO from flake configuration
# Creates an uncompressed ISO suitable for Ventoy and other USB boot tools
set -e
echo "Building Live USB ISO..."
nix build .#nixosConfigurations.live-usb.config.system.build.isoImage --show-trace
if [ -f "./result/iso/"*.iso ]; then
iso_file=$(ls ./result/iso/*.iso)
echo "✅ Build complete!"
echo "📁 ISO location: $iso_file"
echo "💾 Ready for Ventoy or dd to USB"
else
echo "❌ Build failed - no ISO file found"
exit 1
fi

View File

@@ -74,18 +74,6 @@
];
};
# Live USB ISO configuration
nixosConfigurations.live-usb = nixpkgs.lib.nixosSystem rec {
system = "x86_64-linux";
modules = baseModules ++ [
./machines/live-usb/configuration.nix
{
home-manager.users.johno = import ./home/home.nix;
home-manager.extraSpecialArgs = { inherit system; };
}
];
};
homeConfigurations."johno" = inputs.home-manager.lib.homeManagerConfiguration {
pkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
modules = [

View File

@@ -1,95 +0,0 @@
# Live USB ISO configuration for recovery and installation
{ pkgs, modulesPath, ... }:
{
imports = [
# Use minimal installation CD as base
(modulesPath + "/installer/cd-dvd/installation-cd-minimal.nix")
];
# Use roles structure for consistent configuration
roles = {
audio.enable = true;
bluetooth.enable = true;
users = {
enable = true;
extraGroups = [ "video" "wheel" "networkmanager" ];
};
};
# Allow unfree packages for broader hardware support
nixpkgs.config.allowUnfree = true;
# Essential packages for system recovery and installation
environment.systemPackages = with pkgs; [
# Text editors
neovim
nano
# System tools
git
curl
wget
htop
tree
lsof
strace
# Filesystem tools
btrfs-progs
e2fsprogs
xfsprogs
ntfs3g
dosfstools
# Network tools
networkmanager
wirelesstools
# Hardware tools
pciutils
usbutils
smartmontools
# Archive tools
unzip
p7zip
# Development tools (for quick fixes)
gcc
binutils
];
# Enable NetworkManager for easy wifi setup
networking.networkmanager.enable = true;
# Enable SSH daemon for remote access
services.openssh = {
enable = true;
settings = {
PermitRootLogin = "yes";
PasswordAuthentication = true;
};
};
# Override default nixos user, set johno as the main user with password
users.users.nixos.enable = false;
users.users.johno = {
isNormalUser = true;
description = "John Ogle";
extraGroups = [ "wheel" "networkmanager" "audio" "video" ];
password = "nixos"; # Simple password for live environment
};
# ISO customization
isoImage = {
volumeID = "NIXOS-LIVE";
};
# Enable some useful services
services.udisks2.enable = true; # For mounting USB drives
# Hardware support
hardware.enableAllFirmware = true;
hardware.enableRedistributableFirmware = true;
}

View File

@@ -20,5 +20,6 @@ with lib;
./kde.nix
./programs.nix
./sddm.nix
./steam-sleep-inhibitor.nix
];
}

View 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";
};
};
}

View File

@@ -19,12 +19,5 @@ in
nssmdns4 = true;
openFirewall = true;
};
hardware.printers.ensurePrinters = [{
name = "MFC-L8900CDW_series";
deviceUri = "dnssd://Brother%20MFC-L8900CDW%20series._ipp._tcp.local/?uuid=e3248000-80ce-11db-8000-b422006699d8";
model = "everywhere";
}];
hardware.printers.ensureDefaultPrinter = "MFC-L8900CDW_series";
};
}