streamer: disable WiFi power-save on wlan0 - #1
Conversation
Random AirPlay dropouts were root-caused to downlink-delivery stalls, not the DAC: 2.4 GHz microwave interference on channel 6 collapsed the RX rate and starved shairport's ~0.35 s playout buffer. The primary fix was retuning the AP to channel 1; WiFi power-save is a secondary RX-latency source (DTIM buffering) worth removing on a mains-powered receiver. brcmfmac re-enables power-save on every boot/driver reload, so pin it off with a systemd oneshot bound to the wlan0 device appearing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HG3QGvyhN8nWR6h7XjDNuq
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe streamer role adds a systemd oneshot service that runs when ChangesWiFi power-save control
Estimated code review effort: 2 (Simple) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@modules/roles/streamer.nix`:
- Around line 105-111: Update the systemd.services.wifi-powersave-off definition
to add bindsTo for the sys-subsystem-net-devices-wlan0.device unit while
retaining the existing after dependency, so device disappearance and
reappearance reruns the oneshot.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6e5c2833-5197-484b-92f5-fc65aea116b7
📒 Files selected for processing (1)
modules/roles/streamer.nix
| systemd.services.wifi-powersave-off = { | ||
| wantedBy = [ "sys-subsystem-net-devices-wlan0.device" ]; | ||
| after = [ "sys-subsystem-net-devices-wlan0.device" ]; | ||
| serviceConfig = { | ||
| Type = "oneshot"; | ||
| RemainAfterExit = true; | ||
| ExecStart = "${pkgs.iw}/bin/iw dev wlan0 set power_save off"; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
systemctl show wifi-powersave-off.service \
-p BindsTo -p After -p RemainAfterExit -p ExecStartRepository: kelchm/rpi-nixos
Length of output: 201
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
# Locate the service definition and related references.
git ls-files | rg 'modules/roles/streamer\.nix|wifi-powersave-off|wlan0'
# Show the relevant section with line numbers.
sed -n '85,130p' modules/roles/streamer.nix
# Search for other device-bound systemd services in the repo for pattern comparison.
rg -n "bindsTo|BindsTo|sys-subsystem-net-devices-wlan0\.device|RemainAfterExit|wifi-powersave-off" .Repository: kelchm/rpi-nixos
Length of output: 1974
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
# Determine whether this repo contains any NixOS module/tests/docs that spell out
# how `systemd.services.<name>.bindsTo` is translated or used.
rg -n "bindsTo|BindsTo|systemd\.services\..*bindsTo" modules nixos . || trueRepository: kelchm/rpi-nixos
Length of output: 200
Bind wifi-powersave-off to wlan0 so reloads rerun iw.
wantedBy and after only handle the first activation. With RemainAfterExit = true, the oneshot stays active after iw exits, so a wlan0 disappear/reappear cycle during a driver reload will not start it again. Add bindsTo on the device unit and keep after:
Proposed fix
wantedBy = [ "sys-subsystem-net-devices-wlan0.device" ];
after = [ "sys-subsystem-net-devices-wlan0.device" ];
+ bindsTo = [ "sys-subsystem-net-devices-wlan0.device" ];📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| systemd.services.wifi-powersave-off = { | |
| wantedBy = [ "sys-subsystem-net-devices-wlan0.device" ]; | |
| after = [ "sys-subsystem-net-devices-wlan0.device" ]; | |
| serviceConfig = { | |
| Type = "oneshot"; | |
| RemainAfterExit = true; | |
| ExecStart = "${pkgs.iw}/bin/iw dev wlan0 set power_save off"; | |
| systemd.services.wifi-powersave-off = { | |
| wantedBy = [ "sys-subsystem-net-devices-wlan0.device" ]; | |
| after = [ "sys-subsystem-net-devices-wlan0.device" ]; | |
| bindsTo = [ "sys-subsystem-net-devices-wlan0.device" ]; | |
| serviceConfig = { | |
| Type = "oneshot"; | |
| RemainAfterExit = true; | |
| ExecStart = "${pkgs.iw}/bin/iw dev wlan0 set power_save off"; |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@modules/roles/streamer.nix` around lines 105 - 111, Update the
systemd.services.wifi-powersave-off definition to add bindsTo for the
sys-subsystem-net-devices-wlan0.device unit while retaining the existing after
dependency, so device disappearance and reappearance reruns the oneshot.
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Disables WiFi power-save on the streamer’s wlan0 using a systemd oneshot unit triggered by the wlan0 device appearing, with the goal of reducing RX-latency spikes that can contribute to AirPlay dropouts.
Changes:
- Added a
wifi-powersave-offsystemd oneshot that runsiw … set power_save offwhenwlan0appears. - Documented the operational motivation and root-cause notes inline in the NixOS role.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| systemd.services.wifi-powersave-off = { | ||
| wantedBy = [ "sys-subsystem-net-devices-wlan0.device" ]; | ||
| after = [ "sys-subsystem-net-devices-wlan0.device" ]; | ||
| serviceConfig = { | ||
| Type = "oneshot"; | ||
| RemainAfterExit = true; | ||
| ExecStart = "${pkgs.iw}/bin/iw dev wlan0 set power_save off"; | ||
| }; |
What
Disable WiFi power-save on the workbench streamer's
wlan0via a systemd oneshot bound to the interface appearing.Why
Random AirPlay dropouts were root-caused (caught live with
pw-top+ shairport journal) to downlink-delivery stalls, not the DAC:Notes
brcmfmacre-enables power-save on every boot/driver reload, hence the interface-bound oneshot rather than a one-time toggle.dwc2: the DAC runs on FIQ-accelerateddwc_otg(split-transaction FSM / microframe scheduler / NAK holdoff), which is the right path for full-speed isochronous USB audio (0 DAC xruns in 3 weeks).🤖 Generated with Claude Code