From 1dbc26d995026ed943f939800a36abe8e1c3140c Mon Sep 17 00:00:00 2001 From: K900 Date: Tue, 22 Mar 2022 11:10:47 +0300 Subject: [PATCH] nixos/pipewire: unbreak mixed Pulse/Pipewire setups Fixes #163066 --- nixos/modules/services/desktops/pipewire/pipewire.nix | 6 ++++-- .../modules/services/desktops/pipewire/wireplumber.nix | 10 +++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/desktops/pipewire/pipewire.nix b/nixos/modules/services/desktops/pipewire/pipewire.nix index 59e9342a6ea1..e8b778b5fe77 100644 --- a/nixos/modules/services/desktops/pipewire/pipewire.nix +++ b/nixos/modules/services/desktops/pipewire/pipewire.nix @@ -39,6 +39,8 @@ let pipewire = recursiveUpdate (if useSessionManager then defaults.pipewire else defaults.minimal) cfg.config.pipewire; pipewire-pulse = recursiveUpdate defaults.pipewire-pulse cfg.config.pipewire-pulse; }; + + usedForAudio = cfg.pulse.enable || cfg.alsa.enable || cfg.jack.enable; in { meta = { @@ -152,8 +154,8 @@ in { config = mkIf cfg.enable { assertions = [ { - assertion = cfg.pulse.enable -> !config.hardware.pulseaudio.enable; - message = "PipeWire based PulseAudio server emulation replaces PulseAudio. This option requires `hardware.pulseaudio.enable` to be set to false"; + assertion = usedForAudio -> !config.hardware.pulseaudio.enable; + message = "Using PipeWire as a sound server conflicts with PulseAudio. This option requires `hardware.pulseaudio.enable` to be set to false"; } { assertion = cfg.jack.enable -> !config.services.jack.jackd.enable; diff --git a/nixos/modules/services/desktops/pipewire/wireplumber.nix b/nixos/modules/services/desktops/pipewire/wireplumber.nix index 52ec17b95db4..35f3c4737eae 100644 --- a/nixos/modules/services/desktops/pipewire/wireplumber.nix +++ b/nixos/modules/services/desktops/pipewire/wireplumber.nix @@ -1,7 +1,9 @@ { config, lib, pkgs, ... }: let - cfg = config.services.pipewire.wireplumber; + pwCfg = config.services.pipewire; + cfg = pwCfg.wireplumber; + pwUsedForAudio = pwCfg.pulse.enable || pwCfg.alsa.enable || pwCfg.jack.enable; in { meta.maintainers = [ lib.maintainers.k900 ]; @@ -33,6 +35,12 @@ in ]; environment.systemPackages = [ cfg.package ]; + + environment.etc.wireplumber."main.lua.d"."80-nixos.lua".text = if !pwUsedForAudio then '' + # Pipewire is not used for audio, so prevent it from grabbing audio devices + alsa_monitor.enable = function() end + '' else ""; + systemd.packages = [ cfg.package ]; systemd.services.wireplumber.enable = config.services.pipewire.systemWide;