Merge pull request #165231 from K900/the-unplumbening

nixos/pipewire: unbreak mixed Pulse/Pipewire setups
This commit is contained in:
Jan Tojnar 2022-03-26 11:42:15 +01:00 committed by GitHub
commit 95968e616c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 3 deletions

View file

@ -110,6 +110,11 @@ in {
source = json.generate "v4l2-monitor.conf" configs.v4l2-monitor;
};
environment.etc."pipewire/media-session.d/with-audio" =
mkIf config.services.pipewire.audio.enable {
text = "";
};
environment.etc."pipewire/media-session.d/with-alsa" =
mkIf config.services.pipewire.alsa.enable {
text = "";

View file

@ -116,6 +116,16 @@ in {
};
};
audio = {
enable = lib.mkOption {
type = lib.types.bool;
# this is for backwards compatibility
default = cfg.alsa.enable || cfg.jack.enable || cfg.pulse.enable;
defaultText = lib.literalExpression "config.services.pipewire.alsa.enable || config.services.pipewire.jack.enable || config.services.pipewire.pulse.enable";
description = "Whether to use PipeWire as the primary sound server";
};
};
alsa = {
enable = mkEnableOption "ALSA support";
support32Bit = mkEnableOption "32-bit ALSA support on 64-bit systems";
@ -152,13 +162,18 @@ 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 = cfg.audio.enable -> !config.hardware.pulseaudio.enable;
message = "Using PipeWire as the 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;
message = "PipeWire based JACK emulation doesn't use the JACK service. This option requires `services.jack.jackd.enable` to be set to false";
}
{
# JACK intentionally not checked, as PW-on-JACK setups are a thing that some people may want
assertion = (cfg.alsa.enable || cfg.pulse.enable) -> cfg.audio.enable;
message = "Using PipeWire's ALSA/PulseAudio compatibility layers requires running PipeWire as the sound server. Set `services.pipewire.audio.enable` to true.";
}
];
environment.systemPackages = [ cfg.package ]

View file

@ -1,7 +1,9 @@
{ config, lib, pkgs, ... }:
let
cfg = config.services.pipewire.wireplumber;
pwCfg = config.services.pipewire;
cfg = pwCfg.wireplumber;
pwUsedForAudio = pwCfg.audio.enable;
in
{
meta.maintainers = [ lib.maintainers.k900 ];
@ -33,6 +35,14 @@ in
];
environment.systemPackages = [ cfg.package ];
environment.etc."wireplumber/main.lua.d/80-nixos.lua" = lib.mkIf (!pwUsedForAudio) {
text = ''
# Pipewire is not used for audio, so prevent it from grabbing audio devices
alsa_monitor.enable = function() end
'';
};
systemd.packages = [ cfg.package ];
systemd.services.wireplumber.enable = config.services.pipewire.systemWide;