1{ config, lib, pkgs, ... }:
2
3let
4 pwCfg = config.services.pipewire;
5 cfg = pwCfg.wireplumber;
6 pwUsedForAudio = pwCfg.audio.enable;
7in
8{
9 meta.maintainers = [ lib.maintainers.k900 ];
10
11 options = {
12 services.pipewire.wireplumber = {
13 enable = lib.mkOption {
14 type = lib.types.bool;
15 default = config.services.pipewire.enable;
16 defaultText = lib.literalExpression "config.services.pipewire.enable";
17 description = lib.mdDoc "Whether to enable Wireplumber, a modular session / policy manager for PipeWire";
18 };
19
20 package = lib.mkOption {
21 type = lib.types.package;
22 default = pkgs.wireplumber;
23 defaultText = lib.literalExpression "pkgs.wireplumber";
24 description = lib.mdDoc "The wireplumber derivation to use.";
25 };
26 };
27 };
28
29 config = lib.mkIf cfg.enable {
30 assertions = [
31 {
32 assertion = !config.hardware.bluetooth.hsphfpd.enable;
33 message = "Using Wireplumber conflicts with hsphfpd, as it provides the same functionality. `hardware.bluetooth.hsphfpd.enable` needs be set to false";
34 }
35 ];
36
37 environment.systemPackages = [ cfg.package ];
38
39 environment.etc."wireplumber/main.lua.d/80-nixos.lua" = lib.mkIf (!pwUsedForAudio) {
40 text = ''
41 -- Pipewire is not used for audio, so prevent it from grabbing audio devices
42 alsa_monitor.enable = function() end
43 '';
44 };
45 environment.etc."wireplumber/main.lua.d/80-systemwide.lua" = lib.mkIf config.services.pipewire.systemWide {
46 text = ''
47 -- When running system-wide, these settings need to be disabled (they
48 -- use functions that aren't available on the system dbus).
49 alsa_monitor.properties["alsa.reserve"] = false
50 default_access.properties["enable-flatpak-portal"] = false
51 '';
52 };
53 environment.etc."wireplumber/bluetooth.lua.d/80-systemwide.lua" = lib.mkIf config.services.pipewire.systemWide {
54 text = ''
55 -- When running system-wide, logind-integration needs to be disabled.
56 bluez_monitor.properties["with-logind"] = false
57 '';
58 };
59
60 systemd.packages = [ cfg.package ];
61
62 systemd.services.wireplumber.enable = config.services.pipewire.systemWide;
63 systemd.user.services.wireplumber.enable = !config.services.pipewire.systemWide;
64
65 systemd.services.wireplumber.wantedBy = [ "pipewire.service" ];
66 systemd.user.services.wireplumber.wantedBy = [ "pipewire.service" ];
67
68 systemd.services.wireplumber.environment = lib.mkIf config.services.pipewire.systemWide {
69 # Force wireplumber to use system dbus.
70 DBUS_SESSION_BUS_ADDRESS = "unix:path=/run/dbus/system_bus_socket";
71 };
72 };
73}