···
{ config, lib, pkgs, ... }:
+
inherit (builtins) concatMap;
inherit (lib) maintainers;
+
inherit (lib.attrsets) attrByPath mapAttrsToList;
inherit (lib.lists) flatten optional;
inherit (lib.modules) mkIf;
inherit (lib.options) literalExpression mkOption;
+
inherit (lib.strings) concatStringsSep makeSearchPath;
+
inherit (lib.types) bool listOf attrsOf package lines;
+
inherit (lib.path) subpath;
pwCfg = config.services.pipewire;
pwUsedForAudio = pwCfg.audio.enable;
+
json = pkgs.formats.json { };
+
configSectionsToConfFile = path: value:
+
(concatStringsSep "\n" (
+
(section: content: "${section} = " + (builtins.toJSON content))
+
mapConfigToFiles = config:
+
(name: value: configSectionsToConfFile "share/wireplumber/wireplumber.conf.d/${name}.conf" value)
+
mapScriptsToFiles = scripts:
+
(relativePath: value: pkgs.writeTextDir (subpath.join ["share/wireplumber/scripts" relativePath]) value)
meta.maintainers = [ maintainers.k900 ];
···
description = "The WirePlumber derivation to use.";
+
extraConfig = mkOption {
+
# Two layer attrset is necessary before using JSON, because of the whole
+
# config file not being a JSON object, but a concatenation of JSON objects
+
type = attrsOf (attrsOf json.type);
+
example = literalExpression ''{
+
"context.properties" = {
+
# Output Debug log messages as opposed to only the default level (Notice)
+
"wh-1000xm3-ldac-hq" = {
+
"monitor.bluez.rules" = [
+
# Match any bluetooth device with ids equal to that of a WH-1000XM3
+
"device.name" = "~bluez_card.*";
+
"device.product.id" = "0x0cd3";
+
"device.vendor.id" = "usb:054c";
+
# Set quality to high quality instead of the default of auto
+
"bluez5.a2dp.ldac.quality" = "hq";
+
Additional configuration for the WirePlumber daemon when run in
+
single-instance mode (the default in nixpkgs and currently the only
+
supported way to run WirePlumber configured via `extraConfig`).
+
- [The configuration file][docs-the-conf-file]
+
- [Modifying configuration][docs-modifying-config]
+
- [Locations of files][docs-file-locations]
+
- and the [configuration section][docs-config-section] of the docs in general
+
Note that WirePlumber (and PipeWire) use dotted attribute names like
+
`device.product.id`. These are not nested, but flat objects for WirePlumber/PipeWire,
+
so to write these in nix expressions, remember to quote them like `"device.product.id"`.
+
Have a look at the example for this.
+
[docs-the-conf-file]: https://pipewire.pages.freedesktop.org/wireplumber/daemon/configuration/conf_file.html
+
[docs-modifying-config]: https://pipewire.pages.freedesktop.org/wireplumber/daemon/configuration/modifying_configuration.html
+
[docs-file-locations]: https://pipewire.pages.freedesktop.org/wireplumber/daemon/configuration/locations.html
+
[docs-config-section]: https://pipewire.pages.freedesktop.org/wireplumber/daemon/configuration.html
+
extraScripts = mkOption {
+
"test/hello-world.lua" = ''
+
Additional scripts for WirePlumber to be used by configuration files.
+
Every item in this attrset becomes a separate lua file with the path
+
relative to the `scripts` directory specified in the name of the item.
+
The scripts get passed to the WirePlumber service via the `XDG_DATA_DIRS`
+
variable. Scripts specified here are preferred over those shipped with
+
WirePlumber if they occupy the same relative path.
+
For a script to be loaded, it needs to be specified as part of a component,
+
and that component needs to be required by an active profile (e.g. `main`).
+
Components can be defined in config files either via `extraConfig` or `configPackages`.
+
For the hello-world example, you'd have to add the following `extraConfig`:
+
services.pipewire.wireplumber.extraConfig."99-hello-world" = {
+
"wireplumber.components" = [
+
name = "test/hello-world.lua";
+
provides = "custom.hello-world";
+
"wireplumber.profiles" = {
+
"custom.hello-world" = "required";
+
- [Location of scripts][docs-file-locations-scripts]
+
- [Components & Profiles][docs-components-profiles]
+
- [Migration - Loading custom scripts][docs-migration-loading-custom-scripts]
+
[docs-file-locations-scripts]: https://pipewire.pages.freedesktop.org/wireplumber/daemon/locations.html#location-of-scripts
+
[docs-components-profiles]: https://pipewire.pages.freedesktop.org/wireplumber/daemon/configuration/components_and_profiles.html
+
[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
···
+
extraConfigPkg = pkgs.buildEnv {
+
name = "wireplumber-extra-config";
+
paths = mapConfigToFiles cfg.extraConfig;
+
pathsToLink = [ "/share/wireplumber/wireplumber.conf.d" ];
+
extraScriptsPkg = pkgs.buildEnv {
+
name = "wireplumber-extra-scrips";
+
paths = mapScriptsToFiles cfg.extraScripts;
+
pathsToLink = [ "/share/wireplumber/scripts" ];
configPackages = cfg.configPackages
+
++ [ extraConfigPkg extraScriptsPkg ]
+
++ optional (!pwUsedForAudio) pwNotForAudioConfigPkg
+
++ optional pwCfg.systemWide systemwideConfigPkg;
configs = pkgs.buildEnv {
name = "wireplumber-configs";
···
+
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";
environment.systemPackages = [ cfg.package ];
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";
+
# Make WirePlumber find our config/script files and lv2 plugins required by those
+
# (but also the configs/scripts shipped with WirePlumber)
+
XDG_DATA_DIRS = makeSearchPath "share" [ configs cfg.package ];
LV2_PATH = "${lv2Plugins}/lib/lv2";
+
systemd.user.services.wireplumber.environment = mkIf (!pwCfg.systemWide) {
+
XDG_DATA_DIRS = makeSearchPath "share" [ configs cfg.package ];
+
LV2_PATH = "${lv2Plugins}/lib/lv2";