<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Linux | Bas Nijholt</title><link>https://www.nijho.lt/category/linux/</link><atom:link href="https://www.nijho.lt/category/linux/index.xml" rel="self" type="application/rss+xml"/><description>Linux</description><generator>Hugo</generator><language>en-us</language><copyright>© 2026</copyright><lastBuildDate>Fri, 04 Dec 2026 00:00:00 +0000</lastBuildDate><image><url>https://www.nijho.lt/media/icon_hu_408a8f6cef43e327.png</url><title>Linux</title><link>https://www.nijho.lt/category/linux/</link></image><item><title>Gaming on Linux: hardmode with NixOS 🎮</title><link>https://www.nijho.lt/post/gaming-on-nixos/</link><pubDate>Fri, 04 Dec 2026 00:00:00 +0000</pubDate><guid isPermaLink="false">/post/gaming-on-nixos/</guid><description>&lt;p&gt;In July 2025, I bought a used gaming PC with an RTX 3090.&#10;I loved the HBO series &lt;em&gt;The Last of Us&lt;/em&gt; and wanted to play the game.&#10;My &lt;a href="https://www.nijho.lt/post/local-ai-journey/"&gt;post about that PC&lt;/a&gt; literally ended with &amp;ldquo;And who knows, maybe I&amp;rsquo;ll even find the time to play &amp;lsquo;The Last of Us&amp;rsquo;.&amp;rdquo;&lt;/p&gt;&#10;&lt;p&gt;I almost never game alone.&#10;Programming is just more fun for me right now.&#10;So the PC got a second 3090 and became the local AI server in my office.&#10;It serves &lt;code&gt;llama.cpp&lt;/code&gt; and &lt;code&gt;vLLM&lt;/code&gt; models behind &lt;span class="hover-tip" data-tooltip="A lightweight proxy that loads and unloads local AI models on demand instead of keeping them all in VRAM at once." tabindex="0"&gt;&lt;code&gt;llama-swap&lt;/code&gt;&lt;/span&gt; (&lt;a href="https://www.nijho.lt/post/llama-nixos/"&gt;setup&lt;/a&gt;, &lt;a href="https://www.nijho.lt/post/self-hosting-ai-is-not-cheaper/"&gt;costs&lt;/a&gt;).&#10;&lt;code&gt;llama.cpp&lt;/code&gt; also handles embeddings.&#10;The PC runs local speech-to-text and text-to-speech models too, through &lt;a href="https://github.com/basnijholt/agent-cli" target="_blank" rel="noopener"&gt;&lt;code&gt;agent-cli&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;Every couple of months, a friend comes over when we both get a night off from the kids.&#10;Because we both like making life harder, we game on Linux.&#10;&lt;a href="https://github.com/LizardByte/Sunshine" target="_blank" rel="noopener"&gt;Sunshine&lt;/a&gt; runs on the office PC and streams the game&amp;rsquo;s video and audio over my home network.&#10;&lt;a href="https://moonlight-stream.org/" target="_blank" rel="noopener"&gt;Moonlight&lt;/a&gt; runs on the Xbox connected to the 4K TV in the living room.&#10;It shows the stream and sends controller input back, so the Xbox becomes a wireless receiver for my PC.&#10;Moonlight isn&amp;rsquo;t specific to an Xbox, and it also runs on Apple TV, smart TVs, phones, and tablets.&#10;I could have folded and installed Windows, but what&amp;rsquo;s the fun in that?&#10;It also doesn&amp;rsquo;t fit my free-software values (even if I&amp;rsquo;m streaming to an Xbox over NVIDIA&amp;rsquo;s proprietary driver 😅).&lt;/p&gt;&#10;&lt;p&gt;In early December, I finally got the whole setup working.&lt;/p&gt;&#10;&lt;aside class="callout callout-note"&gt;&lt;svg class="ico" viewBox="0 0 256 256" aria-hidden="true"&gt;&lt;path d="M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm16-40a8,8,0,0,1-8,8,16,16,0,0,1-16-16V128a8,8,0,0,1,0-16,16,16,0,0,1,16,16v40A8,8,0,0,1,144,176ZM112,84a12,12,0,1,1,12,12A12,12,0,0,1,112,84Z"/&gt;&lt;/svg&gt;&lt;div&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; Starting a game in Moonlight now turns my office AI server into a gaming PC, and quitting turns it back.&#10;My AI agent fixed the weirdest bug, two controllers that wouldn&amp;rsquo;t stop vibrating, in two minutes.&#10;I think this kind of switch belongs in a small reusable NixOS flake, not in NixOS itself.&lt;/div&gt;&lt;/aside&gt;&#10;&lt;details class="toc" open&gt;&lt;summary&gt;Table of contents&lt;/summary&gt;&lt;nav id="TableOfContents"&gt;&#10; &lt;ul&gt;&#10; &lt;li&gt;&lt;a href="#from-pop_os-to-nixos-and-back-to-btop"&gt;From Pop!_OS to NixOS, and back to btop&lt;/a&gt;&lt;/li&gt;&#10; &lt;li&gt;&lt;a href="#the-controller-that-wouldnt-stop-vibrating"&gt;The controller that wouldn&amp;rsquo;t stop vibrating&lt;/a&gt;&lt;/li&gt;&#10; &lt;li&gt;&lt;a href="#turning-an-ai-server-into-a-gaming-pc"&gt;Turning an AI server into a gaming PC&lt;/a&gt;&lt;/li&gt;&#10; &lt;li&gt;&lt;a href="#a-flake-for-shared-linux-rigs"&gt;A flake for shared Linux rigs&lt;/a&gt;&lt;/li&gt;&#10; &lt;li&gt;&lt;a href="#ready-for-the-next-game-night"&gt;Ready for the next game night&lt;/a&gt;&lt;/li&gt;&#10; &lt;/ul&gt;&#10;&lt;/nav&gt;&lt;/details&gt;&#10;&#10;&lt;h2 id="from-pop_os-to-nixos-and-back-to-btop"&gt;From Pop!_OS to NixOS, and back to btop &lt;a class="anchor" href="#from-pop_os-to-nixos-and-back-to-btop" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;I started with &lt;a href="https://system76.com/pop/" target="_blank" rel="noopener"&gt;Pop!_OS&lt;/a&gt; because everyone recommended it for gaming.&#10;I had heard NVIDIA drivers on Linux had a bad reputation, though I didn&amp;rsquo;t really appreciate why until I lived it.&#10;I didn&amp;rsquo;t know Pop!_OS ships &lt;span class="hover-tip" data-tooltip="Pop!_OS installs NVIDIA drivers through its system76-driver-nvidia package, from System76&amp;#39;s own apt repositories." tabindex="0"&gt;its own NVIDIA driver&lt;/span&gt;, matched to its kernel, from its own repositories.&#10;So when I installed a driver from somewhere else, the two clashed and I broke everything.&#10;I ended up debugging a black screen in GRUB with long commands an AI gave me.&#10;Once it worked again, the dread of never reproducing that setup pushed me to NixOS, and I fell in love (&lt;a href="https://www.nijho.lt/post/proxmox-to-nixos/"&gt;the full story&lt;/a&gt;).&lt;/p&gt;&#10;&lt;p&gt;NixOS fixed reproducibility, but it didn&amp;rsquo;t fix game night.&#10;When you only game every couple of months, something has always changed since last time.&#10;Sometimes my local AI services were hogging everything.&#10;Other times a background process was crash-looping.&#10;Once, my self-hosted services ate all the IP addresses on my home network, so the Xbox couldn&amp;rsquo;t even get online.&#10;It&amp;rsquo;s the classic Linux gaming scene.&#10;I&amp;rsquo;d sit on the couch with my phone, SSH&amp;rsquo;d into the office PC.&#10;I&amp;rsquo;d have a coding agent open in one terminal and &lt;a href="https://github.com/aristocratos/btop" target="_blank" rel="noopener"&gt;&lt;code&gt;btop&lt;/code&gt;&lt;/a&gt; in another, to spot whatever was acting up mid-game.&#10;Most nights, we were lucky if our gaming time matched our debugging time.&lt;/p&gt;&#10;&lt;h2 id="the-controller-that-wouldnt-stop-vibrating"&gt;The controller that wouldn&amp;rsquo;t stop vibrating &lt;a class="anchor" href="#the-controller-that-wouldnt-stop-vibrating" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Getting this setup to a good place took months of small fixes, like automatically switching to a 4K &lt;span class="hover-tip" data-tooltip="A tiny HDMI adapter that tells the GPU a 4K screen is connected, so it renders at full resolution with no monitor attached." tabindex="0"&gt;HDMI dummy plug&lt;/span&gt; and sorting out scaling.&#10;Yesterday, I sat down to knock out the remaining annoyances after setting the PC to &lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/nixos/optional/desktop.nix#L31-L36" target="_blank" rel="noopener"&gt;auto-login into&lt;/a&gt; &lt;span class="hover-tip" data-tooltip="I spent a lot of time tuning a Hyprland setup, and it&amp;#39;s still installed. Since I spend most of my time on macOS and rarely sit at the Linux desktop, I kept forgetting how everything worked, so I set GNOME as the default login instead." tabindex="0"&gt;GNOME&lt;/span&gt;.&#10;I turned on Moonlight, and the Xbox controller in my hand started vibrating uncontrollably.&#10;I figured it was broken and grabbed a second controller.&#10;It did the exact same thing.&lt;/p&gt;&#10;&lt;p&gt;This is the part that still amazes me.&#10;I described the symptom into my phone to my agent in &lt;a href="https://www.nijho.lt/post/mindroom/"&gt;MindRoom&lt;/a&gt;.&#10;Two minutes later, the controller stopped vibrating and the bug was fixed.&lt;/p&gt;&#10;&lt;p&gt;The agent found the cause in the kernel logs.&#10;My PC runs &lt;a href="https://github.com/atar-axis/xpadneo" target="_blank" rel="noopener"&gt;&lt;code&gt;xpadneo&lt;/code&gt;&lt;/a&gt;, a driver for Bluetooth Xbox controllers, and it was grabbing Sunshine&amp;rsquo;s virtual gamepad and trapping it in its connection rumble.&#10;Switching Sunshine&amp;rsquo;s virtual controller to an older Xbox 360 profile (&lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/sunshine/sunshine.conf" target="_blank" rel="noopener"&gt;&lt;code&gt;gamepad = x360&lt;/code&gt;&lt;/a&gt;) bypassed &lt;code&gt;xpadneo&lt;/code&gt; entirely.&lt;/p&gt;&#10;&lt;p&gt;With that out of the way, I had the agent finish porting my &lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/hypr/scripts/sunshine-mode.sh" target="_blank" rel="noopener"&gt;display-switching script&lt;/a&gt; to GNOME and clean up the last few headless headaches, like waking a sleeping display and skipping desktop permission popups.&lt;sup id="fnref:1"&gt;&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref"&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;&#10;&lt;h2 id="turning-an-ai-server-into-a-gaming-pc"&gt;Turning an AI server into a gaming PC &lt;a class="anchor" href="#turning-an-ai-server-into-a-gaming-pc" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Most days, the office PC is tuned to be a quiet AI server.&#10;Both 3090s sit at a &lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/nixos/hosts/pc/nvidia-undervolt.nix" target="_blank" rel="noopener"&gt;270 W power limit&lt;/a&gt; instead of their stock 350 W, mostly to keep heat down.&#10;That trims 23% off the power ceiling while costing only a small slice of performance, roughly 5 to 10%.&#10;Meanwhile, &lt;code&gt;llama-swap&lt;/code&gt; keeps models ready, and the CPU saves power.&#10;That&amp;rsquo;s a great AI server, though for gaming I want the primary GPU uncapped and out of the AI services&amp;rsquo; way.&lt;/p&gt;&#10;&lt;p&gt;Now starting an app in Moonlight flips the PC into gaming mode automatically.&#10;It pauses the AI services and blocks &lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/nixos/common/comin.nix" target="_blank" rel="noopener"&gt;automated deploys&lt;/a&gt; from waking them mid-game.&#10;It raises GPU 0&amp;rsquo;s power limit to 350 W and puts the CPU in performance mode.&#10;It also switches the display to the 4K HDMI dummy plug that Sunshine streams from.&#10;Quitting the app, or a Sunshine crash, puts everything back.&lt;sup id="fnref:2"&gt;&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref"&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;&#10;&lt;figure class="plot-figure"&gt;&#10; &lt;div class="plot-container" role="img" aria-label="The two modes of my office PC. Starting an app in Moonlight flips it into gaming mode. Quitting the app, or a Sunshine crash, flips it back." data-plot-module="/post/gaming-on-nixos/plots.js" data-plot-name="modeLifecycle"&gt;&lt;/div&gt;&#10; &lt;figcaption&gt;The two modes of my office PC. Starting an app in Moonlight flips it into gaming mode. Quitting the app, or a Sunshine crash, flips it back.&lt;/figcaption&gt;&#10; &lt;noscript&gt;This chart needs JavaScript.&lt;/noscript&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;script type="module" src="https://www.nijho.lt/js/plot.7cb86dc2e3ef25b56bc93730b2620745a7f02b5715de87f94e61908f60e51690.js" integrity="sha256-fLhtwuPvJbVryTcwsmIHRafwK1cV3of5TmGQj2DlFpA=" crossorigin="anonymous"&gt;&lt;/script&gt;&#10;&#10;&#10;&lt;p&gt;The switch itself is a small &lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/nixos/hosts/pc/gaming-mode.py" target="_blank" rel="noopener"&gt;&lt;code&gt;gaming-mode&lt;/code&gt;&lt;/a&gt; script, wired into NixOS via &lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/nixos/hosts/pc/gaming.nix" target="_blank" rel="noopener"&gt;&lt;code&gt;gaming.nix&lt;/code&gt;&lt;/a&gt;, that I can also run by hand from my shell.&lt;/p&gt;&#10;&lt;h2 id="a-flake-for-shared-linux-rigs"&gt;A flake for shared Linux rigs &lt;a class="anchor" href="#a-flake-for-shared-linux-rigs" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;My first instinct was to wish for a built-in gaming mode in NixOS.&#10;But every shared box is different.&#10;Your workloads and GPUs won&amp;rsquo;t match mine, so NixOS itself shouldn&amp;rsquo;t guess one standard mode.&lt;/p&gt;&#10;&lt;p&gt;A small standalone &lt;span class="hover-tip" data-tooltip="A self-contained, versioned bundle of Nix code that anyone can import into their own NixOS config." tabindex="0"&gt;flake&lt;/span&gt; fits much better.&#10;You&amp;rsquo;d declare your own services to pause, GPU power limits, and CPU profile.&#10;The flake would generate the toggle script, the narrow sudo rule, the deploy guard, and the crash-safe undo hook.&lt;/p&gt;&#10;&lt;p&gt;I already run Feral&amp;rsquo;s &lt;a href="https://github.com/FeralInteractive/gamemode" target="_blank" rel="noopener"&gt;&lt;code&gt;gamemode&lt;/code&gt;&lt;/a&gt;, and it&amp;rsquo;s great for per-game tweaks.&#10;It can even run custom scripts when a game starts and ends.&#10;It doesn&amp;rsquo;t orchestrate the whole host with paused services, deploy guards, and crash teardown.&#10;If other people want it, I might pull my own &lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/nixos/hosts/pc/gaming.nix" target="_blank" rel="noopener"&gt;&lt;code&gt;gaming.nix&lt;/code&gt;&lt;/a&gt; out into a small flake like this.&lt;/p&gt;&#10;&lt;h2 id="ready-for-the-next-game-night"&gt;Ready for the next game night &lt;a class="anchor" href="#ready-for-the-next-game-night" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;In my tests, everything now works as expected.&#10;One rough edge remains: in Moonlight, I have to pick &amp;ldquo;Quit App&amp;rdquo; instead of &amp;ldquo;Disconnect&amp;rdquo; for the undo hook to run.&#10;Until I do, my AI services stay paused and GPU 0&amp;rsquo;s power limit stays at 350 W.&lt;/p&gt;&#10;&lt;p&gt;Of course, the real test is when my friend and I game again, hopefully soon but more realistically in a month or two.&#10;If my phone stays in my pocket instead of open on &lt;code&gt;btop&lt;/code&gt;, I&amp;rsquo;ll call it a win.&lt;/p&gt;&#10;&lt;div class="footnotes" role="doc-endnotes"&gt;&#10;&lt;hr&gt;&#10;&lt;ol&gt;&#10;&lt;li id="fn:1"&gt;&#10;&lt;p&gt;For the curious, Sunshine now captures frames straight from the GPU with KMS (&lt;code&gt;capture = kms&lt;/code&gt; in &lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/sunshine/sunshine.conf" target="_blank" rel="noopener"&gt;&lt;code&gt;sunshine.conf&lt;/code&gt;&lt;/a&gt;), so GNOME&amp;rsquo;s ScreenCast permission dialog never appears.&#10;A systemd &lt;code&gt;ExecStartPre&lt;/code&gt; hook wakes blanked displays, and a &lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/nixos/hosts/pc/gaming.nix#L85-L95" target="_blank" rel="noopener"&gt;one-line NixOS patch&lt;/a&gt; stops the first launch after a blank from failing with HTTP 503.&#10;During a stream, &lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/hypr/scripts/sunshine-mode.sh#L194-L235" target="_blank" rel="noopener"&gt;&lt;code&gt;sunshine-mode.sh&lt;/code&gt;&lt;/a&gt; uses GNOME&amp;rsquo;s &lt;code&gt;gdctl&lt;/code&gt; to show only the dummy plug at 4K and scale 1, then restores my office monitor afterwards.&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li id="fn:2"&gt;&#10;&lt;p&gt;The details live in &lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/nixos/hosts/pc/gaming.nix#L103-L121" target="_blank" rel="noopener"&gt;&lt;code&gt;gaming.nix&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/nixos/hosts/pc/gaming-mode.py#L63-L84" target="_blank" rel="noopener"&gt;&lt;code&gt;gaming-mode.py&lt;/code&gt;&lt;/a&gt;, and &lt;a href="https://github.com/basnijholt/dotfiles/blob/1838764a207315658ed950b0bd89a80cbbac5373/configs/nixos/hosts/pc/nvidia-undervolt.nix" target="_blank" rel="noopener"&gt;&lt;code&gt;nvidia-undervolt.nix&lt;/code&gt;&lt;/a&gt;.&#10;A narrow &lt;code&gt;NOPASSWD&lt;/code&gt; sudo rule allows only &lt;code&gt;gaming-mode on&lt;/code&gt; and &lt;code&gt;gaming-mode off&lt;/code&gt;.&#10;&lt;code&gt;ConditionPathExists = &amp;quot;!/run/gaming-mode.active&amp;quot;&lt;/code&gt; stops deploys from restarting the AI services, and &lt;code&gt;ExecStopPost&lt;/code&gt; on &lt;code&gt;sunshine.service&lt;/code&gt; runs the undo after a crash.&#10;On the way back, it writes &lt;code&gt;powersave&lt;/code&gt; before &lt;code&gt;balance_performance&lt;/code&gt;, because AMD&amp;rsquo;s &lt;code&gt;amd-pstate-epp&lt;/code&gt; driver rejects that hint under the &lt;code&gt;performance&lt;/code&gt; governor.&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;/div&gt;&#10;</description></item></channel></rss>