From 992582fdf8c0104f3d36af2bc956842dab3cbad2 Mon Sep 17 00:00:00 2001 From: Hans Christian Schmitz Date: Fri, 23 Feb 2024 08:28:48 +0100 Subject: [PATCH 1/4] nixos/pipewire: Fix capitalization In docs PipeWire and WirePlumber should be capitalized as in this sentence. --- nixos/modules/services/desktops/pipewire/pipewire.nix | 8 ++++---- .../modules/services/desktops/pipewire/wireplumber.nix | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nixos/modules/services/desktops/pipewire/pipewire.nix b/nixos/modules/services/desktops/pipewire/pipewire.nix index da409030b3a3..e52ee97401ee 100644 --- a/nixos/modules/services/desktops/pipewire/pipewire.nix +++ b/nixos/modules/services/desktops/pipewire/pipewire.nix @@ -1,4 +1,4 @@ -# pipewire service. +# PipeWire service. { config, lib, pkgs, ... }: with lib; @@ -25,7 +25,7 @@ in { ###### interface options = { services.pipewire = { - enable = mkEnableOption (lib.mdDoc "pipewire service"); + enable = mkEnableOption (lib.mdDoc "PipeWire service"); package = mkPackageOption pkgs "pipewire" { }; @@ -33,7 +33,7 @@ in { default = true; type = types.bool; description = lib.mdDoc '' - Automatically run pipewire when connections are made to the pipewire socket. + Automatically run PipeWire when connections are made to the PipeWire socket. ''; }; @@ -301,7 +301,7 @@ in { "audio" "video" ] ++ lib.optional config.security.rtkit.enable "rtkit"; - description = "Pipewire system service user"; + description = "PipeWire system service user"; isSystemUser = true; home = "/var/lib/pipewire"; createHome = true; diff --git a/nixos/modules/services/desktops/pipewire/wireplumber.nix b/nixos/modules/services/desktops/pipewire/wireplumber.nix index 95a7ece26c5d..eee06f09ba20 100644 --- a/nixos/modules/services/desktops/pipewire/wireplumber.nix +++ b/nixos/modules/services/desktops/pipewire/wireplumber.nix @@ -14,14 +14,14 @@ in type = lib.types.bool; default = config.services.pipewire.enable; defaultText = lib.literalExpression "config.services.pipewire.enable"; - description = lib.mdDoc "Whether to enable Wireplumber, a modular session / policy manager for PipeWire"; + description = lib.mdDoc "Whether to enable WirePlumber, a modular session / policy manager for PipeWire"; }; package = lib.mkOption { type = lib.types.package; default = pkgs.wireplumber; defaultText = lib.literalExpression "pkgs.wireplumber"; - description = lib.mdDoc "The wireplumber derivation to use."; + description = lib.mdDoc "The WirePlumber derivation to use."; }; }; }; @@ -30,7 +30,7 @@ in assertions = [ { 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"; + message = "Using WirePlumber conflicts with hsphfpd, as it provides the same functionality. `hardware.bluetooth.hsphfpd.enable` needs be set to false"; } ]; @@ -38,7 +38,7 @@ in 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 + -- PipeWire is not used for audio, so prevent it from grabbing audio devices alsa_monitor.enable = function() end ''; }; @@ -66,7 +66,7 @@ in systemd.user.services.wireplumber.wantedBy = [ "pipewire.service" ]; systemd.services.wireplumber.environment = lib.mkIf config.services.pipewire.systemWide { - # Force wireplumber to use system dbus. + # Force WirePlumber to use system dbus. DBUS_SESSION_BUS_ADDRESS = "unix:path=/run/dbus/system_bus_socket"; }; }; From 054bba560af06ef9ba53c00e154be2ad3238f811 Mon Sep 17 00:00:00 2001 From: Hans Christian Schmitz Date: Fri, 19 Jan 2024 13:34:17 +0100 Subject: [PATCH 2/4] nixos/pipewire: add config packages option --- .../services/desktops/pipewire/pipewire.nix | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/nixos/modules/services/desktops/pipewire/pipewire.nix b/nixos/modules/services/desktops/pipewire/pipewire.nix index e52ee97401ee..7effd8df9a17 100644 --- a/nixos/modules/services/desktops/pipewire/pipewire.nix +++ b/nixos/modules/services/desktops/pipewire/pipewire.nix @@ -5,7 +5,11 @@ with lib; let json = pkgs.formats.json {}; - mapToFiles = location: config: concatMapAttrs (name: value: { "pipewire/${location}.conf.d/${name}.conf".source = json.generate "${name}" value;}) config; + mapToFiles = location: config: concatMapAttrs (name: value: { "share/pipewire/${location}.conf.d/${name}.conf" = json.generate "${name}" value; }) config; + extraConfigPkgFromFiles = locations: filesSet: pkgs.runCommand "pipewire-extra-config" { } '' + mkdir -p ${lib.concatMapStringsSep " " (l: "$out/share/pipewire/${l}.conf.d") locations} + ${lib.concatMapStringsSep ";" ({name, value}: "ln -s ${value} $out/${name}") (lib.attrsToList filesSet)} + ''; cfg = config.services.pipewire; enable32BitAlsaPlugins = cfg.alsa.support32Bit && pkgs.stdenv.isx86_64 @@ -19,6 +23,24 @@ let mkdir -p "$out/lib" ln -s "${cfg.package.jack}/lib" "$out/lib/pipewire" ''; + + configPackages = cfg.configPackages; + + extraConfigPkg = extraConfigPkgFromFiles + [ "pipewire" "client" "client-rt" "jack" "pipewire-pulse" ] + ( + mapToFiles "pipewire" cfg.extraConfig.pipewire + // mapToFiles "client" cfg.extraConfig.client + // mapToFiles "client-rt" cfg.extraConfig.client-rt + // mapToFiles "jack" cfg.extraConfig.jack + // mapToFiles "pipewire-pulse" cfg.extraConfig.pipewire-pulse + ); + + configs = pkgs.buildEnv { + name = "pipewire-configs"; + paths = configPackages ++ [ extraConfigPkg ]; + pathsToLink = [ "/share/pipewire" ]; + }; in { meta.maintainers = teams.freedesktop.members ++ [ lib.maintainers.k900 ]; @@ -200,6 +222,15 @@ in { ''; }; }; + + configPackages = lib.mkOption { + type = lib.types.listOf lib.types.package; + default = []; + description = lib.mdDoc '' + List of packages that provide PipeWire configuration, in the form of + `share/pipewire/*/*.conf` files. + ''; + }; }; }; @@ -283,12 +314,8 @@ in { "alsa/conf.d/99-pipewire-default.conf" = mkIf cfg.alsa.enable { source = "${cfg.package}/share/alsa/alsa.conf.d/99-pipewire-default.conf"; }; - } - // mapToFiles "pipewire" cfg.extraConfig.pipewire - // mapToFiles "client" cfg.extraConfig.client - // mapToFiles "client-rt" cfg.extraConfig.client-rt - // mapToFiles "jack" cfg.extraConfig.jack - // mapToFiles "pipewire-pulse" cfg.extraConfig.pipewire-pulse; + pipewire.source = "${configs}/share/pipewire"; + }; environment.sessionVariables.LD_LIBRARY_PATH = lib.mkIf cfg.jack.enable [ "${cfg.package.jack}/lib" ]; From 5bf2637b489091b787944d9d60b4e04878ac1b89 Mon Sep 17 00:00:00 2001 From: Hans Christian Schmitz Date: Fri, 19 Jan 2024 13:50:11 +0100 Subject: [PATCH 3/4] nixos/wireplumber: add config packages option --- .../services/desktops/pipewire/pipewire.nix | 4 +- .../desktops/pipewire/wireplumber.nix | 79 +++++++++++-------- 2 files changed, 51 insertions(+), 32 deletions(-) diff --git a/nixos/modules/services/desktops/pipewire/pipewire.nix b/nixos/modules/services/desktops/pipewire/pipewire.nix index 7effd8df9a17..238259c212bb 100644 --- a/nixos/modules/services/desktops/pipewire/pipewire.nix +++ b/nixos/modules/services/desktops/pipewire/pipewire.nix @@ -38,7 +38,9 @@ let configs = pkgs.buildEnv { name = "pipewire-configs"; - paths = configPackages ++ [ extraConfigPkg ]; + paths = configPackages + ++ [ extraConfigPkg ] + ++ lib.optionals cfg.wireplumber.enable cfg.wireplumber.configPackages; pathsToLink = [ "/share/pipewire" ]; }; in { diff --git a/nixos/modules/services/desktops/pipewire/wireplumber.nix b/nixos/modules/services/desktops/pipewire/wireplumber.nix index eee06f09ba20..584cbf1486ef 100644 --- a/nixos/modules/services/desktops/pipewire/wireplumber.nix +++ b/nixos/modules/services/desktops/pipewire/wireplumber.nix @@ -23,51 +23,68 @@ in defaultText = lib.literalExpression "pkgs.wireplumber"; description = lib.mdDoc "The WirePlumber derivation to use."; }; + + configPackages = lib.mkOption { + type = lib.types.listOf lib.types.package; + default = [ ]; + description = lib.mdDoc '' + List of packages that provide WirePlumber configuration, in the form of + `share/wireplumber/*/*.lua` files. + ''; + }; }; }; - config = lib.mkIf cfg.enable { - assertions = [ - { - 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"; - } - ]; + config = + let + configPackages = cfg.configPackages; - environment.systemPackages = [ cfg.package ]; - - environment.etc."wireplumber/main.lua.d/80-nixos.lua" = lib.mkIf (!pwUsedForAudio) { - text = '' + pwNotForAudioConfigPkg = pkgs.writeTextDir "share/wireplumber/main.lua.d/80-pw-not-for-audio.lua" '' -- PipeWire is not used for audio, so prevent it from grabbing audio devices alsa_monitor.enable = function() end ''; - }; - environment.etc."wireplumber/main.lua.d/80-systemwide.lua" = lib.mkIf config.services.pipewire.systemWide { - text = '' + systemwideConfigPkg = pkgs.writeTextDir "wireplumber/main.lua.d/80-systemwide.lua" '' -- When running system-wide, these settings need to be disabled (they -- use functions that aren't available on the system dbus). alsa_monitor.properties["alsa.reserve"] = false default_access.properties["enable-flatpak-portal"] = false ''; - }; - environment.etc."wireplumber/bluetooth.lua.d/80-systemwide.lua" = lib.mkIf config.services.pipewire.systemWide { - text = '' + systemwideBluetoothConfigPkg = pkgs.writeTextDir "wireplumber/bluetooth.lua.d/80-systemwide.lua" '' -- When running system-wide, logind-integration needs to be disabled. bluez_monitor.properties["with-logind"] = false ''; + + configs = pkgs.buildEnv { + name = "wireplumber-configs"; + paths = configPackages + ++ lib.optional (!pwUsedForAudio) pwNotForAudioConfigPkg + ++ lib.optionals config.services.pipewire.systemWide [ systemwideConfigPkg systemwideBluetoothConfigPkg ]; + pathsToLink = [ "/share/wireplumber" ]; + }; + in + lib.mkIf cfg.enable { + assertions = [ + { + 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 ]; + + environment.etc.wireplumber.source = "${configs}/share/wireplumber"; + + systemd.packages = [ cfg.package ]; + + systemd.services.wireplumber.enable = config.services.pipewire.systemWide; + systemd.user.services.wireplumber.enable = !config.services.pipewire.systemWide; + + systemd.services.wireplumber.wantedBy = [ "pipewire.service" ]; + systemd.user.services.wireplumber.wantedBy = [ "pipewire.service" ]; + + systemd.services.wireplumber.environment = lib.mkIf config.services.pipewire.systemWide { + # Force WirePlumber to use system dbus. + DBUS_SESSION_BUS_ADDRESS = "unix:path=/run/dbus/system_bus_socket"; + }; }; - - systemd.packages = [ cfg.package ]; - - systemd.services.wireplumber.enable = config.services.pipewire.systemWide; - systemd.user.services.wireplumber.enable = !config.services.pipewire.systemWide; - - systemd.services.wireplumber.wantedBy = [ "pipewire.service" ]; - systemd.user.services.wireplumber.wantedBy = [ "pipewire.service" ]; - - systemd.services.wireplumber.environment = lib.mkIf config.services.pipewire.systemWide { - # Force WirePlumber to use system dbus. - DBUS_SESSION_BUS_ADDRESS = "unix:path=/run/dbus/system_bus_socket"; - }; - }; } From e722c5616095cf5cacc25acfb76ebf165be25feb Mon Sep 17 00:00:00 2001 From: Hans Christian Schmitz Date: Sat, 20 Jan 2024 16:54:35 +0100 Subject: [PATCH 4/4] nixos/wireplumber: add required lv2 plugins to service path --- .../desktops/pipewire/wireplumber.nix | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/nixos/modules/services/desktops/pipewire/wireplumber.nix b/nixos/modules/services/desktops/pipewire/wireplumber.nix index 584cbf1486ef..dc4d726d7632 100644 --- a/nixos/modules/services/desktops/pipewire/wireplumber.nix +++ b/nixos/modules/services/desktops/pipewire/wireplumber.nix @@ -32,13 +32,26 @@ in `share/wireplumber/*/*.lua` files. ''; }; + + extraLv2Packages = lib.mkOption { + type = lib.types.listOf lib.types.package; + default = []; + example = lib.literalExpression "[ pkgs.lsp-plugins ]"; + description = lib.mdDoc '' + List of packages that provide LV2 plugins in `lib/lv2` that should + be made available to WirePlumber for [filter chains][wiki-filter-chain]. + + Config packages have their required LV2 plugins added automatically, + so they don't need to be specified here. + + [wiki-filter-chain]: https://docs.pipewire.org/page_module_filter_chain.html + ''; + }; }; }; config = let - configPackages = cfg.configPackages; - pwNotForAudioConfigPkg = pkgs.writeTextDir "share/wireplumber/main.lua.d/80-pw-not-for-audio.lua" '' -- PipeWire is not used for audio, so prevent it from grabbing audio devices alsa_monitor.enable = function() end @@ -54,13 +67,30 @@ in bluez_monitor.properties["with-logind"] = false ''; - configs = pkgs.buildEnv { - name = "wireplumber-configs"; - paths = configPackages + configPackages = cfg.configPackages ++ lib.optional (!pwUsedForAudio) pwNotForAudioConfigPkg ++ lib.optionals config.services.pipewire.systemWide [ systemwideConfigPkg systemwideBluetoothConfigPkg ]; + + configs = pkgs.buildEnv { + name = "wireplumber-configs"; + paths = configPackages; pathsToLink = [ "/share/wireplumber" ]; }; + + requiredLv2Packages = lib.flatten + ( + lib.concatMap + (p: + lib.attrByPath ["passthru" "requiredLv2Packages"] [] p + ) + configPackages + ); + + lv2Plugins = pkgs.buildEnv { + name = "wireplumber-lv2-plugins"; + paths = cfg.extraLv2Packages ++ requiredLv2Packages; + pathsToLink = [ "/lib/lv2" ]; + }; in lib.mkIf cfg.enable { assertions = [ @@ -85,6 +115,10 @@ in systemd.services.wireplumber.environment = lib.mkIf config.services.pipewire.systemWide { # Force WirePlumber to use system dbus. DBUS_SESSION_BUS_ADDRESS = "unix:path=/run/dbus/system_bus_socket"; + LV2_PATH = "${lv2Plugins}/lib/lv2"; }; + + systemd.user.services.wireplumber.environment.LV2_PATH = + lib.mkIf (!config.services.pipewire.systemWide) "${lv2Plugins}/lib/lv2"; }; }