···
{ config, lib, pkgs, ... }:
4
-
inherit (builtins) attrNames concatMap length;
4
+
inherit (builtins) concatMap;
inherit (lib) maintainers;
6
-
inherit (lib.attrsets) attrByPath filterAttrs;
6
+
inherit (lib.attrsets) attrByPath mapAttrsToList;
inherit (lib.lists) flatten optional;
inherit (lib.modules) mkIf;
inherit (lib.options) literalExpression mkOption;
10
-
inherit (lib.strings) hasPrefix;
11
-
inherit (lib.types) bool listOf package;
10
+
inherit (lib.strings) concatStringsSep makeSearchPath;
11
+
inherit (lib.types) bool listOf attrsOf package lines;
12
+
inherit (lib.path) subpath;
pwCfg = config.services.pipewire;
pwUsedForAudio = pwCfg.audio.enable;
18
+
json = pkgs.formats.json { };
20
+
configSectionsToConfFile = path: value:
23
+
(concatStringsSep "\n" (
25
+
(section: content: "${section} = " + (builtins.toJSON content))
29
+
mapConfigToFiles = config:
31
+
(name: value: configSectionsToConfFile "share/wireplumber/wireplumber.conf.d/${name}.conf" value)
34
+
mapScriptsToFiles = scripts:
36
+
(relativePath: value: pkgs.writeTextDir (subpath.join ["share/wireplumber/scripts" relativePath]) value)
meta.maintainers = [ maintainers.k900 ];
···
description = "The WirePlumber derivation to use.";
58
+
extraConfig = mkOption {
59
+
# Two layer attrset is necessary before using JSON, because of the whole
60
+
# config file not being a JSON object, but a concatenation of JSON objects
62
+
type = attrsOf (attrsOf json.type);
64
+
example = literalExpression ''{
65
+
"log-level-debug" = {
66
+
"context.properties" = {
67
+
# Output Debug log messages as opposed to only the default level (Notice)
71
+
"wh-1000xm3-ldac-hq" = {
72
+
"monitor.bluez.rules" = [
76
+
# Match any bluetooth device with ids equal to that of a WH-1000XM3
77
+
"device.name" = "~bluez_card.*";
78
+
"device.product.id" = "0x0cd3";
79
+
"device.vendor.id" = "usb:054c";
84
+
# Set quality to high quality instead of the default of auto
85
+
"bluez5.a2dp.ldac.quality" = "hq";
93
+
Additional configuration for the WirePlumber daemon when run in
94
+
single-instance mode (the default in nixpkgs and currently the only
95
+
supported way to run WirePlumber configured via `extraConfig`).
98
+
- [The configuration file][docs-the-conf-file]
99
+
- [Modifying configuration][docs-modifying-config]
100
+
- [Locations of files][docs-file-locations]
101
+
- and the [configuration section][docs-config-section] of the docs in general
103
+
Note that WirePlumber (and PipeWire) use dotted attribute names like
104
+
`device.product.id`. These are not nested, but flat objects for WirePlumber/PipeWire,
105
+
so to write these in nix expressions, remember to quote them like `"device.product.id"`.
106
+
Have a look at the example for this.
108
+
[docs-the-conf-file]: https://pipewire.pages.freedesktop.org/wireplumber/daemon/configuration/conf_file.html
109
+
[docs-modifying-config]: https://pipewire.pages.freedesktop.org/wireplumber/daemon/configuration/modifying_configuration.html
110
+
[docs-file-locations]: https://pipewire.pages.freedesktop.org/wireplumber/daemon/configuration/locations.html
111
+
[docs-config-section]: https://pipewire.pages.freedesktop.org/wireplumber/daemon/configuration.html
115
+
extraScripts = mkOption {
116
+
type = attrsOf lines;
119
+
"test/hello-world.lua" = ''
120
+
print("Hello, world!")
124
+
Additional scripts for WirePlumber to be used by configuration files.
126
+
Every item in this attrset becomes a separate lua file with the path
127
+
relative to the `scripts` directory specified in the name of the item.
128
+
The scripts get passed to the WirePlumber service via the `XDG_DATA_DIRS`
129
+
variable. Scripts specified here are preferred over those shipped with
130
+
WirePlumber if they occupy the same relative path.
132
+
For a script to be loaded, it needs to be specified as part of a component,
133
+
and that component needs to be required by an active profile (e.g. `main`).
134
+
Components can be defined in config files either via `extraConfig` or `configPackages`.
136
+
For the hello-world example, you'd have to add the following `extraConfig`:
138
+
services.pipewire.wireplumber.extraConfig."99-hello-world" = {
139
+
"wireplumber.components" = [
141
+
name = "test/hello-world.lua";
142
+
type = "script/lua";
143
+
provides = "custom.hello-world";
147
+
"wireplumber.profiles" = {
149
+
"custom.hello-world" = "required";
156
+
- [Location of scripts][docs-file-locations-scripts]
157
+
- [Components & Profiles][docs-components-profiles]
158
+
- [Migration - Loading custom scripts][docs-migration-loading-custom-scripts]
160
+
[docs-file-locations-scripts]: https://pipewire.pages.freedesktop.org/wireplumber/daemon/locations.html#location-of-scripts
161
+
[docs-components-profiles]: https://pipewire.pages.freedesktop.org/wireplumber/daemon/configuration/components_and_profiles.html
162
+
[docs-migration-loading-custom-scripts]: https://pipewire.pages.freedesktop.org/wireplumber/daemon/configuration/migration.html#loading-custom-scripts
configPackages = mkOption {
···
extraLv2Packages = mkOption {
example = literalExpression "[ pkgs.lsp-plugins ]";
List of packages that provide LV2 plugins in `lib/lv2` that should
···
229
+
extraConfigPkg = pkgs.buildEnv {
230
+
name = "wireplumber-extra-config";
231
+
paths = mapConfigToFiles cfg.extraConfig;
232
+
pathsToLink = [ "/share/wireplumber/wireplumber.conf.d" ];
235
+
extraScriptsPkg = pkgs.buildEnv {
236
+
name = "wireplumber-extra-scrips";
237
+
paths = mapScriptsToFiles cfg.extraScripts;
238
+
pathsToLink = [ "/share/wireplumber/scripts" ];
configPackages = cfg.configPackages
100
-
++ optional (!pwUsedForAudio) pwNotForAudioConfigPkg
101
-
++ optional pwCfg.systemWide systemwideConfigPkg;
242
+
++ [ extraConfigPkg extraScriptsPkg ]
243
+
++ optional (!pwUsedForAudio) pwNotForAudioConfigPkg
244
+
++ optional pwCfg.systemWide systemwideConfigPkg;
configs = pkgs.buildEnv {
name = "wireplumber-configs";
···
113
-
attrByPath ["passthru" "requiredLv2Packages"] [] p
256
+
attrByPath [ "passthru" "requiredLv2Packages" ] [ ] p
···
assertion = !config.hardware.bluetooth.hsphfpd.enable;
message = "Using WirePlumber conflicts with hsphfpd, as it provides the same functionality. `hardware.bluetooth.hsphfpd.enable` needs be set to false";
136
-
hasPrefix "wireplumber/" name || name == "wireplumber"
138
-
config.environment.etc
140
-
message = "Using `environment.etc.\"wireplumber<...>\"` directly is no longer supported in 24.05. Use `services.pipewire.wireplumber.configPackages` instead.";
environment.systemPackages = [ cfg.package ];
146
-
environment.etc.wireplumber.source = "${configs}/share/wireplumber";
systemd.packages = [ cfg.package ];
systemd.services.wireplumber.enable = pwCfg.systemWide;
···
systemd.services.wireplumber.environment = mkIf pwCfg.systemWide {
# Force WirePlumber to use system dbus.
DBUS_SESSION_BUS_ADDRESS = "unix:path=/run/dbus/system_bus_socket";
289
+
# Make WirePlumber find our config/script files and lv2 plugins required by those
290
+
# (but also the configs/scripts shipped with WirePlumber)
291
+
XDG_DATA_DIRS = makeSearchPath "share" [ configs cfg.package ];
LV2_PATH = "${lv2Plugins}/lib/lv2";
162
-
systemd.user.services.wireplumber.environment.LV2_PATH =
163
-
mkIf (!pwCfg.systemWide) "${lv2Plugins}/lib/lv2";
295
+
systemd.user.services.wireplumber.environment = mkIf (!pwCfg.systemWide) {
296
+
XDG_DATA_DIRS = makeSearchPath "share" [ configs cfg.package ];
297
+
LV2_PATH = "${lv2Plugins}/lib/lv2";