Skip to content

nixos/pipewire: add option to restart when config changes - #549706

Open
gepbird wants to merge 2 commits into
NixOS:masterfrom
gepbird:nixos/pipewire/restart-on-config-change
Open

gepbird wants to merge 2 commits into
NixOS:masterfrom
gepbird:nixos/pipewire/restart-on-config-change

Conversation

@gepbird

@gepbird gepbird commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Previously after changing some pipewire configuration and switching to the new system config, the new pipewire config didn't get loaded and the user had to manually restart the service (after figuring out that their config was not applied by the module automatically).

Reproduce the problem
  1. query some pipewire config, e.g. pw-cli info 0 | grep default.clock.rate -> 48000
  2. override the previous config with this module and switch-to-configuration:
{
  services.pipewire.extraConfig.pipewire."10-clock-rate" = {
    "context.properties" = {
      "default.clock.rate" = 44100;
    };
  };
}
  1. observe that the same query still returns the old value: pw-cli info 0 | grep default.clock.rate -> 48000
  2. systemctl --user restart pipewire.service
  3. now it gives the new value: pw-cli info 0 | grep default.clock.rate -> 44100

I've seen socket activation + proper config reload needing stopIfChanged = false, but I'm not exactly sure why yet. Sometimes the new config applies without it, sometimes it doesn't.
The core behaviour matches the docs, where with stopIfChanged = false, switch-to-configuration says that the pipewire.service and pipewire.socket is being restarted, with stopIfChanged = true it says that these 2 are being stopped and pipewire.socket is being started, except the service logs don't mention any events for the latter.
Related issue which I only glanced at before sleep: #74899

I can imagine that config (and package?) changes were intentionally not restarting the services to avoid breaking apps (e.g. by manually restarting pipewire and pipewire-pulse while a video was playing in a browser, I had to reload the page to get audio working again), I wonder if we'd get mass reports that music/videos stopped playing after a system update's switch-to-configuration, and in worse cases a full app restart is needed.
If this was the intention, I recommend we document it instead in the options' descriptions, and put the reload functionality behind a new option.

Things done

@nixpkgs-ci
nixpkgs-ci Bot requested review from a team and K900 August 6, 2026 00:23
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Aug 6, 2026
@K900

K900 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

We don't want to break people's sound when they switch to a new config. This works the same way as most other desktop related things, with the same standard caveats.

@gepbird
gepbird force-pushed the nixos/pipewire/restart-on-config-change branch from dcbf1ca to 1af8679 Compare August 6, 2026 20:04
@gepbird

gepbird commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

I put those behind a new restartOnConfigChange option, so people can opt-in to config changes restarting the services. Also documented individual options where a service restart is needed.

Note that (regardless of this PR), systemd.user.services.pipewire.restartIfChanged evaluates to true, which means a package update can restart the pipewire service. Just to double check, is this the expected behaviour? Personally on graphical systems after a staging next merge I only boot into the new generation to avoid problems (which I had months ago with switch, some services failed to restart but worked after reboot). Here's how I tested:

Test package update restarting service
  • change the package in some way:
  services.pipewire.package = pkgs.pipewire.overrideAttrs {
    postFixup = "echo test";
  };
  • switch to config, in the log the service is said to be restarted, and it's actually restarted (without having to change stopIfChanged to false)
reloading user units for gep...
stopping the following user units: pipewire.service, pipewire.socket
reloading the following user units: dbus-broker.service
starting the following user units: pipewire.socket
restarting the following user units: nixos-activation.service
restarting sysinit-reactivation.target
reloading the following units: dbus-broker.service
restarting the following units: systemd-udevd.service
starting the following units: accounts-daemon.service, polkit.service

gepbird added a commit to gepbird/dotfiles that referenced this pull request Aug 16, 2026
Flake lock file updates:

• Added input 'nixpkgs-patch-pipewire-auto-restart':
    'NixOS/nixpkgs#549706'
@gepbird gepbird changed the title nixos/pipewire: restart when config changes nixos/pipewire: add option to restart when config changes Aug 16, 2026
gepbird added a commit to tchfoo/raspi-dotfiles that referenced this pull request Aug 17, 2026
Flake lock file updates:

• Updated input 'gep-dotfiles':
    'git+https://git.tchfoo.com/gepbird/dotfiles?ref=refs/heads/main&rev=0ceeb004ce1f20400990104fd76b78d18cc1af35' (2026-08-13)
  → 'git+https://git.tchfoo.com/gepbird/dotfiles?ref=refs/heads/main&rev=6fd88e37317163738bcdff8e06361f97222b5b1e' (2026-08-17)
• Added input 'gep-dotfiles/nixpkgs-patch-pipewire-auto-restart':
    'NixOS/nixpkgs#549706'
• Updated input 'gep-dotfiles/nvim-gep':
    'git+https://git.tchfoo.com/gepbird/nvim?ref=refs/heads/main&rev=5cd5dafa27f814f6bc5539f9bf7bcb4e41c0e27d' (2026-08-13)
  → 'git+https://git.tchfoo.com/gepbird/nvim?ref=refs/heads/main&rev=882e73700cc73e2bbb930d336d5df9f9d325437c' (2026-08-16)
• Updated input 'gep-dotfiles/nvim-gep/neovim-nightly':
    'github:nix-community/neovim-nightly-overlay/3c7255e535760cd414f64af0ebf7715dfd683673' (2026-08-13)
  → 'github:nix-community/neovim-nightly-overlay/3dc8fa3b0b2220ffd0836012407b15aa6747d3fe' (2026-08-16)
• Updated input 'gep-dotfiles/nvim-gep/neovim-nightly/neovim-src':
    'github:neovim/neovim/a63393396cd0901050849b72caaa8583949b6ebf' (2026-08-12)
  → 'github:neovim/neovim/2edb1c000958952c87edda596ed9ed53628084ed' (2026-08-15)
• Updated input 'gep-dotfiles/nvim-gep/nixvim':
    'github:nix-community/nixvim/738351a7813be094fb00fce1a149bcc25e936c36' (2026-08-12)
  → 'github:nix-community/nixvim/f1311e1d8c101bf3fbce6804de144ca1546d0901' (2026-08-16)
• Updated input 'home-manager':
    'github:nix-community/home-manager/0668fdbc15bd602e463cab37ff64346021193652' (2026-08-13)
  → 'github:nix-community/home-manager/353742587cbaf079b3caee743115d037bc51fea6' (2026-08-17)
• Updated input 'nix-index-database':
    'github:nix-community/nix-index-database/14d55b8069119e3b88da7aa2f6c97f86a2cd3cd6' (2026-08-09)
  → 'github:nix-community/nix-index-database/c7962dc97b45129df8d751bedaf37beb5a17706e' (2026-08-16)
• Updated input 'nixos-hardware':
    'github:NixOS/nixos-hardware/3e7edd9afe17e45521300e041c65de3015f4a302' (2026-08-12)
  → 'github:NixOS/nixos-hardware/ff17823245ab9ff7bcae6acf950bd89cba82c38c' (2026-08-16)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/867dcbc30bafe3c862ef88620f2e7a109d7d3be5' (2026-08-12)
  → 'github:NixOS/nixpkgs/e5bdc4a41d4c072fe1e3787eaa0320a384741d44' (2026-08-16)
• Updated input 'nur':
    'github:nix-community/NUR/a5ef785fafbf01c361372d7dc8e0f1591aeeacd3' (2026-08-13)
  → 'github:nix-community/NUR/8be43012c2bacae916ce6ab341257cdd18fa96f0' (2026-08-17)
• Updated input 'sops-nix':
    'github:Mic92/sops-nix/d1337e05ba0a8e88a75d2c0e1595d82f3b3e2ac4' (2026-08-10)
  → 'github:Mic92/sops-nix/a8627b21b9107c5711c96b84f32a9a4b3d45295f' (2026-08-13)
• Updated input 'tangled-core':
    'git+https://tangled.org/tangled.org/core?ref=refs/heads/master&rev=ad9724b3271a170ee5b0fd81e5e3098303599623' (2026-08-12)
  → 'git+https://tangled.org/tangled.org/core?ref=refs/heads/master&rev=0d028cd5c5cca78937fc17c17418c507fbb6dc0f' (2026-08-17)
• Updated input 'treefmt-nix':
    'github:numtide/treefmt-nix/ae7910970dddc408fe6ab1c8e4b277bb21d72dc0' (2026-08-05)
  → 'github:numtide/treefmt-nix/27b3b12a8e6375f28ebe122f07d230ca5459bbfa' (2026-08-16)

@ferris-qq ferris-qq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested in a NixOS VM (x86_64-linux, nixpkgs e158d9e with this PR's pipewire.nix swapped in through disabledModules). A user with linger = true runs pipewire, pipewire-pulse and wireplumber, and the test switches between specialisations with switch-to-configuration test, checking each unit's InvocationID and the live value with pw-metadata.

change restartOnConfigChange = false (default) restartOnConfigChange = true
extraConfig.pipewire (default.clock.rate = 44100) nothing restarted, clock.rate stays 48000 pipewire and pipewire-pulse restarted (wireplumber with them), clock.rate is 44100
wireplumber.extraConfig only wireplumber restarted, new setting live same
wireplumber.configPackages (a package with only share/wireplumber files) only wireplumber restarted wireplumber, and also pipewire and pipewire-pulse

So the option works, and the default stays as it is. Two things I noticed:

  1. WirePlumber doesn't need the option. wireplumber.nix passes its config through XDG_DATA_DIRS in the unit's environment (wireplumber.nix#L300-L306), so any change to wireplumber.extraConfig or wireplumber.configPackages changes wireplumber.service itself, and the switch already restarts it (stopping the following user units: wireplumber.service, then starting). A sentence about that in the option description might save people from looking for a WirePlumber equivalent.

  2. With the option on, a WirePlumber-only config package also restarts PipeWire. The trigger is configs, and that buildEnv takes wireplumber.configPackages as inputs (pipewire.nix#L78-L85) even though it only links share/pipewire. Since restarting PipeWire is what interrupts playback, I'd trigger on PipeWire's own inputs instead (suggestion inline). With that, extraConfig.pipewire and services.pipewire.configPackages still restart pipewire and pipewire-pulse (evaluated, and run in the VM for extraConfig), and the WirePlumber-only package restarts only wireplumber (VM). The trade-off: PipeWire config shipped inside a wireplumber.configPackages entry would no longer restart PipeWire.

systemWide = true was only evaluated, not run: the system units change the same way.

Disclosure: tested and drafted with help from Claude Code (Claude Opus 5.5).

Comment on lines +449 to +452
systemd.services.pipewire.restartTriggers = mkIf cfg.restartOnConfigChange [ configs ];
systemd.user.services.pipewire.restartTriggers = mkIf cfg.restartOnConfigChange [ configs ];
systemd.services.pipewire-pulse.restartTriggers = mkIf cfg.restartOnConfigChange [ configs ];
systemd.user.services.pipewire-pulse.restartTriggers = mkIf cfg.restartOnConfigChange [ configs ];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triggering on PipeWire's own config inputs, without wireplumber.configPackages (nixfmt-formatted):

Suggested change
systemd.services.pipewire.restartTriggers = mkIf cfg.restartOnConfigChange [ configs ];
systemd.user.services.pipewire.restartTriggers = mkIf cfg.restartOnConfigChange [ configs ];
systemd.services.pipewire-pulse.restartTriggers = mkIf cfg.restartOnConfigChange [ configs ];
systemd.user.services.pipewire-pulse.restartTriggers = mkIf cfg.restartOnConfigChange [ configs ];
systemd.services.pipewire.restartTriggers = mkIf cfg.restartOnConfigChange (
configPackages ++ [ extraConfigPkg ]
);
systemd.user.services.pipewire.restartTriggers = mkIf cfg.restartOnConfigChange (
configPackages ++ [ extraConfigPkg ]
);
systemd.services.pipewire-pulse.restartTriggers = mkIf cfg.restartOnConfigChange (
configPackages ++ [ extraConfigPkg ]
);
systemd.user.services.pipewire-pulse.restartTriggers = mkIf cfg.restartOnConfigChange (
configPackages ++ [ extraConfigPkg ]
);

gepbird added a commit to tchfoo/raspi-dotfiles that referenced this pull request Nov 2, 2026
Flake lock file updates:

• Updated input 'gep-dotfiles/nixpkgs-patch-pipewire-auto-restart':
    'NixOS/nixpkgs#549706'
  → follows 'null'
• Updated input 'tangled-core/flake-compat':
    'https://git.lix.systems/api/v1/repos/lix-project/flake-compat/archive/549f2762aebeff29a2e5ece7a7dc0f955281a1d1.tar.gz?narHash=sha256-NKw96t%2BBgHIYzHUjkTK95FqYRVKB8DHpVhefWSz/kTw%3D&rev=549f2762aebeff29a2e5ece7a7dc0f955281a1d1' (2025-07-05)
  → follows 'null'
• Updated input 'tangled-core/gomod2nix':
    'github:nix-community/gomod2nix/02e63a239d6eabd595db56852535992c898eba72' (2025-11-24)
  → follows 'null'
• Removed input 'tangled-core/gomod2nix/flake-utils'
• Removed input 'tangled-core/gomod2nix/flake-utils/systems'
• Removed input 'tangled-core/gomod2nix/nixpkgs'
• Updated input 'tangled-core/hydrant':
    'git+https://tangled.org/ptr.pet/hydrant?ref=refs/heads/main&rev=0128352f6b73d26e7ffaa5a79446ef556e452617' (2026-10-21)
  → follows 'null'
• Updated input 'tangled-core/hydrant-dev':
    'git+https://tangled.org/ptr.pet/hydrant?ref=refs/heads/main&rev=0128352f6b73d26e7ffaa5a79446ef556e452617' (2026-10-21)
  → follows 'null'
• Updated input 'tangled-core/ibm-plex-mono-src':
    'https://github.com/IBM/plex/releases/download/@ibm/[email protected]/ibm-plex-mono.zip?narHash=sha256-OwUmrPfEehLDz0fl2ChYLK8FQM2p0G1%2BEMrGsYEq%2B6g%3D' (2024-11-12)
  → follows 'null'
• Updated input 'tangled-core/indigo':
    'github:oppiliappan/indigo/5f170569da9360f57add450a278d73538092d8ca' (2025-07-28)
  → follows 'null'
• Updated input 'tangled-core/microvm':
    'github:microvm-nix/microvm.nix/0d49083ba2d7419b22908ac392777c16df9a032e' (2026-05-28)
  → follows 'null'
• Removed input 'tangled-core/microvm/nixpkgs'
• Removed input 'tangled-core/microvm/spectrum'
• Updated input 'tangled-core/nixpkgs-pds':
    'github:nixos/nixpkgs/7fd4004d0511991fff3a0524856a9be09e28c5f0' (2026-10-11)
  → follows 'null'
• Updated input 'tangled-core/sqlite-lib-src':
    'https://sqlite.org/2024/sqlite-amalgamation-3450100.zip?narHash=sha256-bJoMjirsBjm2Qk9KPiy3yV3%2B8b/POlYe76/FQbciHro%3D' (2024-01-30)
  → follows 'null'
• Updated input 'tangled-core/timeless-fonts-src':
    'https://media.timeless.co/type/Timeless-Type-Family-1.094.zip?narHash=sha256-zYpoDkE/YrICzYaHF4/NSuINczFWB41YymTxaL6KqLY%3D' (2026-10-03)
  → follows 'null'
• Updated input 'ymstnt-dotfiles/blip':
    'github:blip-net/nix/92ae525425b38b2873d8d52a564a9c146fccba08' (2026-10-27)
  → follows 'null'
• Removed input 'ymstnt-dotfiles/blip/nixpkgs'
gepbird added a commit to gepbird/dotfiles that referenced this pull request Nov 12, 2026
Flake lock file updates:

• Updated input 'home-manager':
    'github:nix-community/home-manager/a9752a621164e9f84eb2a15858f1d54fd3cedab8' (2026-11-09)
  → 'github:nix-community/home-manager/82ce401aa350502897c3f2e85f384d61cd3b0b6d' (2026-11-10)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/f4a03c008967841f2a0b3cb7c436fc6fc31671f6' (2026-11-07)
  → 'github:NixOS/nixpkgs/177d0540942fb205af6993b1d5fa0b57799e09f8' (2026-11-09)
• Removed input 'nixpkgs-patch-discord-vencord-1-15-16'
• Updated input 'nixpkgs-patch-hytale-launcher':
    'NixOS/nixpkgs#479368'
  → 'NixOS/nixpkgs#479368'
• Updated input 'nixpkgs-patch-pipewire-auto-restart':
    'NixOS/nixpkgs#549706'
  → 'NixOS/nixpkgs#549706'
• Updated input 'nixpkgs-patch-rustdesk-flutter-fix-build':
    'NixOS/nixpkgs#585583'
  → 'NixOS/nixpkgs#585583'
• Updated input 'nur':
    'github:nix-community/NUR/d5b727db34219332642086dba98e08f371d31c5e' (2026-11-10)
  → 'github:nix-community/NUR/7b921c747644347cbb458826f751416c2a7d96d3' (2026-11-12)
gepbird added a commit to gepbird/dotfiles that referenced this pull request Nov 12, 2026
Flake lock file updates:

• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/177d0540942fb205af6993b1d5fa0b57799e09f8' (2026-11-09)
  → 'github:NixOS/nixpkgs/d4f25a3e562008648d45bcf2d70bcc7422cad84e' (2026-11-11)
• Updated input 'nixpkgs-patch-hytale-launcher':
    'NixOS/nixpkgs#479368'
  → 'NixOS/nixpkgs#479368'
• Updated input 'nixpkgs-patch-pipewire-auto-restart':
    'NixOS/nixpkgs#549706'
  → 'NixOS/nixpkgs#549706'
• Removed input 'nixpkgs-patch-rustdesk-flutter-fix-build'
• Updated input 'nur':
    'github:nix-community/NUR/7b921c747644347cbb458826f751416c2a7d96d3' (2026-11-12)
  → 'github:nix-community/NUR/655f5e9ff6a3705fb0252445b3d4b29efc4bfea0' (2026-11-12)
gepbird added a commit to gepbird/dotfiles that referenced this pull request Nov 20, 2026
Flake lock file updates:

• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/04906337b6d53e8bb0eaf0470ae9f070a4d4eb55' (2026-11-17)
  → 'github:NixOS/nixpkgs/0bb8272318b4ca41bf0edc6224df3e3e3046b70d' (2026-11-19)
• Updated input 'nixpkgs-patch-hytale-launcher':
    'NixOS/nixpkgs#479368'
  → 'NixOS/nixpkgs#479368'
• Removed input 'nixpkgs-patch-openasar-fix-videos-and-gifs-not-playing'
• Updated input 'nixpkgs-patch-pipewire-auto-restart':
    'NixOS/nixpkgs#549706'
  → 'NixOS/nixpkgs#549706'
• Removed input 'nixpkgs-patch-rom-0-6-1'
• Updated input 'nur':
    'github:nix-community/NUR/68c0a7bac471d7250057557c7c722f69cc28a976' (2026-11-18)
  → 'github:nix-community/NUR/97d4d8f1cd0131576043b02f644d404b1789aa28' (2026-11-20)
• Updated input 'treefmt-nix':
    'github:numtide/treefmt-nix/0d6d739a833ba9a9c93034862e4a7b061a062a1c' (2026-10-13)
  → 'github:numtide/treefmt-nix/a0a97e31a897a3537eea5c49df4f8adaa83b3b37' (2026-11-20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants