Gaming on Linux: hardmode with NixOS 馃幃
My office AI server doubles as a game streaming box for rare game nights with a friend. Now starting a game flips it from one to the other.
In July 2025, I bought a used gaming PC with an RTX 3090. I loved the HBO series The Last of Us and wanted to play the game. My post about that PC literally ended with “And who knows, maybe I’ll even find the time to play ‘The Last of Us’.”
I almost never game alone.
Programming is just more fun for me right now.
So the PC got a second 3090 and became the local AI server in my office.
It serves llama.cpp and vLLM models behind llama-swap (setup, costs).
llama.cpp also handles embeddings.
The PC runs local speech-to-text and text-to-speech models too, through agent-cli.
Every couple of months, a friend comes over when we both get a night off from the kids. Because we both like making life harder, we game on Linux. Sunshine runs on the office PC and streams the game’s video and audio over my home network. Moonlight runs on the Xbox connected to the 4K TV in the living room. It shows the stream and sends controller input back, so the Xbox becomes a wireless receiver for my PC. Moonlight isn’t specific to an Xbox, and it also runs on Apple TV, smart TVs, phones, and tablets. I could have folded and installed Windows, but what’s the fun in that? It also doesn’t fit my free-software values (even if I’m streaming to an Xbox over NVIDIA’s proprietary driver 馃槄).
In early December, I finally got the whole setup working.
Table of contents
From Pop!_OS to NixOS, and back to btop #
I started with Pop!_OS because everyone recommended it for gaming. I had heard NVIDIA drivers on Linux had a bad reputation, though I didn’t really appreciate why until I lived it. I didn’t know Pop!_OS ships its own NVIDIA driver, matched to its kernel, from its own repositories. So when I installed a driver from somewhere else, the two clashed and I broke everything. I ended up debugging a black screen in GRUB with long commands an AI gave me. Once it worked again, the dread of never reproducing that setup pushed me to NixOS, and I fell in love (the full story).
NixOS fixed reproducibility, but it didn’t fix game night.
When you only game every couple of months, something has always changed since last time.
Sometimes my local AI services were hogging everything.
Other times a background process was crash-looping.
Once, my self-hosted services ate all the IP addresses on my home network, so the Xbox couldn’t even get online.
It’s the classic Linux gaming scene.
I’d sit on the couch with my phone, SSH’d into the office PC.
I’d have a coding agent open in one terminal and btop in another, to spot whatever was acting up mid-game.
Most nights, we were lucky if our gaming time matched our debugging time.
The controller that wouldn’t stop vibrating #
Getting this setup to a good place took months of small fixes, like automatically switching to a 4K HDMI dummy plug and sorting out scaling. Yesterday, I sat down to knock out the remaining annoyances after setting the PC to auto-login into GNOME. I turned on Moonlight, and the Xbox controller in my hand started vibrating uncontrollably. I figured it was broken and grabbed a second controller. It did the exact same thing.
This is the part that still amazes me. I described the symptom into my phone to my agent in MindRoom. Two minutes later, the controller stopped vibrating and the bug was fixed.
The agent found the cause in the kernel logs.
My PC runs xpadneo, a driver for Bluetooth Xbox controllers, and it was grabbing Sunshine’s virtual gamepad and trapping it in its connection rumble.
Switching Sunshine’s virtual controller to an older Xbox 360 profile (gamepad = x360) bypassed xpadneo entirely.
With that out of the way, I had the agent finish porting my display-switching script to GNOME and clean up the last few headless headaches, like waking a sleeping display and skipping desktop permission popups.1
Turning an AI server into a gaming PC #
Most days, the office PC is tuned to be a quiet AI server.
Both 3090s sit at a 270 W power limit instead of their stock 350 W, mostly to keep heat down.
That trims 23% off the power ceiling while costing only a small slice of performance, roughly 5 to 10%.
Meanwhile, llama-swap keeps models ready, and the CPU saves power.
That’s a great AI server, though for gaming I want the primary GPU uncapped and out of the AI services’ way.
Now starting an app in Moonlight flips the PC into gaming mode automatically. It pauses the AI services and blocks automated deploys from waking them mid-game. It raises GPU 0’s power limit to 350 W and puts the CPU in performance mode. It also switches the display to the 4K HDMI dummy plug that Sunshine streams from. Quitting the app, or a Sunshine crash, puts everything back.2
The switch itself is a small gaming-mode script, wired into NixOS via gaming.nix, that I can also run by hand from my shell.
A flake for shared Linux rigs #
My first instinct was to wish for a built-in gaming mode in NixOS. But every shared box is different. Your workloads and GPUs won’t match mine, so NixOS itself shouldn’t guess one standard mode.
A small standalone flake fits much better. You’d declare your own services to pause, GPU power limits, and CPU profile. The flake would generate the toggle script, the narrow sudo rule, the deploy guard, and the crash-safe undo hook.
I already run Feral’s gamemode, and it’s great for per-game tweaks.
It can even run custom scripts when a game starts and ends.
It doesn’t orchestrate the whole host with paused services, deploy guards, and crash teardown.
If other people want it, I might pull my own gaming.nix out into a small flake like this.
Ready for the next game night #
In my tests, everything now works as expected. One rough edge remains: in Moonlight, I have to pick “Quit App” instead of “Disconnect” for the undo hook to run. Until I do, my AI services stay paused and GPU 0’s power limit stays at 350 W.
Of course, the real test is when my friend and I game again, hopefully soon but more realistically in a month or two.
If my phone stays in my pocket instead of open on btop, I’ll call it a win.
For the curious, Sunshine now captures frames straight from the GPU with KMS (
capture = kmsinsunshine.conf), so GNOME’s ScreenCast permission dialog never appears. A systemdExecStartPrehook wakes blanked displays, and a one-line NixOS patch stops the first launch after a blank from failing with HTTP 503. During a stream,sunshine-mode.shuses GNOME’sgdctlto show only the dummy plug at 4K and scale 1, then restores my office monitor afterwards. ↩︎The details live in
gaming.nix,gaming-mode.py, andnvidia-undervolt.nix. A narrowNOPASSWDsudo rule allows onlygaming-mode onandgaming-mode off.ConditionPathExists = "!/run/gaming-mode.active"stops deploys from restarting the AI services, andExecStopPostonsunshine.serviceruns the undo after a crash. On the way back, it writespowersavebeforebalance_performance, because AMD’samd-pstate-eppdriver rejects that hint under theperformancegovernor. ↩︎