From efaf703830cb0dbe9ae9f85751d0a7df5f440924 Mon Sep 17 00:00:00 2001 From: Gabriel Ebner Date: Sun, 29 Nov 2020 14:23:32 +0100 Subject: [PATCH 1/8] pipewire: 0.3.16 -> 0.3.17 --- pkgs/development/libraries/pipewire/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/libraries/pipewire/default.nix b/pkgs/development/libraries/pipewire/default.nix index f03f9ea88f40..35306a926c74 100644 --- a/pkgs/development/libraries/pipewire/default.nix +++ b/pkgs/development/libraries/pipewire/default.nix @@ -39,7 +39,7 @@ let in stdenv.mkDerivation rec { pname = "pipewire"; - version = "0.3.16"; + version = "0.3.17"; outputs = [ "out" @@ -56,7 +56,7 @@ stdenv.mkDerivation rec { owner = "pipewire"; repo = "pipewire"; rev = version; - sha256 = "0ivfx3rbg2iwjdh412zjpk9y5mzw7zh6asv4sji8lq0dzhwbz1qc"; + sha256 = "1gzdahji23fsgjycc08h7zzv8filmzdrkyvpkljc881l4cb5l58n"; }; patches = [ From 6850681fa2fe04edea3476541a8c28c6bf8ebd56 Mon Sep 17 00:00:00 2001 From: Gabriel Ebner Date: Sun, 29 Nov 2020 14:47:20 +0100 Subject: [PATCH 2/8] pipewire: enable hsphfpd support by default hsphfpd is packaged in nixpkgs now. --- pkgs/development/libraries/pipewire/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/libraries/pipewire/default.nix b/pkgs/development/libraries/pipewire/default.nix index 35306a926c74..9347b7674cf0 100644 --- a/pkgs/development/libraries/pipewire/default.nix +++ b/pkgs/development/libraries/pipewire/default.nix @@ -27,7 +27,7 @@ , bluezSupport ? true, bluez ? null, sbc ? null , nativeHspSupport ? true , ofonoSupport ? true -, hsphfpdSupport ? false +, hsphfpdSupport ? true }: let From 53029a15ccc239d8f6d150d672f35239b2ae2d95 Mon Sep 17 00:00:00 2001 From: Gabriel Ebner Date: Sun, 29 Nov 2020 15:08:38 +0100 Subject: [PATCH 3/8] nixos/pipewire: enable sound on alsa support Otherwise sound.extraConfig has no effect. --- nixos/modules/services/desktops/pipewire.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nixos/modules/services/desktops/pipewire.nix b/nixos/modules/services/desktops/pipewire.nix index c4923cfd3f00..f08b5cc19b7f 100644 --- a/nixos/modules/services/desktops/pipewire.nix +++ b/nixos/modules/services/desktops/pipewire.nix @@ -79,6 +79,7 @@ in { services.udev.packages = [ pkgs.pipewire ]; # If any paths are updated here they must also be updated in the package test. + sound.enable = mkIf cfg.alsa.enable true; sound.extraConfig = mkIf cfg.alsa.enable '' pcm_type.pipewire { libs.native = ${pkgs.pipewire.lib}/lib/alsa-lib/libasound_module_pcm_pipewire.so ; From ce28fd3d22313a2d4daef605c9d4f314bfb6456a Mon Sep 17 00:00:00 2001 From: Gabriel Ebner Date: Sun, 29 Nov 2020 15:20:43 +0100 Subject: [PATCH 4/8] nixos/pipewire: add media-session.d files --- nixos/modules/services/desktops/pipewire.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nixos/modules/services/desktops/pipewire.nix b/nixos/modules/services/desktops/pipewire.nix index f08b5cc19b7f..7b9ecf038754 100644 --- a/nixos/modules/services/desktops/pipewire.nix +++ b/nixos/modules/services/desktops/pipewire.nix @@ -99,5 +99,9 @@ in { }; environment.sessionVariables.LD_LIBRARY_PATH = lib.optional cfg.jack.enable "/run/current-system/sw/lib/pipewire"; + + environment.etc."pipewire/media-session.d/with-alsa" = mkIf cfg.alsa.enable { text = ""; }; + environment.etc."pipewire/media-session.d/with-pulseaudio" = mkIf cfg.pulse.enable { text = ""; }; + environment.etc."pipewire/media-session.d/with-jack" = mkIf cfg.jack.enable { text = ""; }; }; } From 015583027548ef7554d6053f39ec6ef77d9487e2 Mon Sep 17 00:00:00 2001 From: Gabriel Ebner Date: Sun, 29 Nov 2020 15:25:40 +0100 Subject: [PATCH 5/8] nixos/pipewire: allow overriding the pipewire derivation --- nixos/modules/services/desktops/pipewire.nix | 24 ++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/nixos/modules/services/desktops/pipewire.nix b/nixos/modules/services/desktops/pipewire.nix index 7b9ecf038754..57f37b0e525a 100644 --- a/nixos/modules/services/desktops/pipewire.nix +++ b/nixos/modules/services/desktops/pipewire.nix @@ -15,7 +15,7 @@ let # This doesn't work in general because of missing development information. jack-libs = pkgs.runCommand "jack-libs" {} '' mkdir -p "$out/lib" - ln -s "${pkgs.pipewire.jack}/lib" "$out/lib/pipewire" + ln -s "${cfg.package.jack}/lib" "$out/lib/pipewire" ''; in { @@ -28,6 +28,16 @@ in { services.pipewire = { enable = mkEnableOption "pipewire service"; + package = mkOption { + type = types.package; + default = pkgs.pipewire; + defaultText = "pkgs.pipewire"; + example = literalExample "pkgs.pipewire"; + description = '' + The pipewire derivation to use. + ''; + }; + socketActivation = mkOption { default = true; type = types.bool; @@ -65,24 +75,24 @@ in { } ]; - environment.systemPackages = [ pkgs.pipewire ] + environment.systemPackages = [ cfg.package ] ++ lib.optional cfg.jack.enable jack-libs; - systemd.packages = [ pkgs.pipewire ] - ++ lib.optional cfg.pulse.enable pkgs.pipewire.pulse; + systemd.packages = [ cfg.package ] + ++ lib.optional cfg.pulse.enable cfg.package.pulse; # PipeWire depends on DBUS but doesn't list it. Without this booting # into a terminal results in the service crashing with an error. systemd.user.sockets.pipewire.wantedBy = lib.mkIf cfg.socketActivation [ "sockets.target" ]; systemd.user.sockets.pipewire-pulse.wantedBy = lib.mkIf (cfg.socketActivation && cfg.pulse.enable) ["sockets.target"]; systemd.user.services.pipewire.bindsTo = [ "dbus.service" ]; - services.udev.packages = [ pkgs.pipewire ]; + services.udev.packages = [ cfg.package ]; # If any paths are updated here they must also be updated in the package test. sound.enable = mkIf cfg.alsa.enable true; sound.extraConfig = mkIf cfg.alsa.enable '' pcm_type.pipewire { - libs.native = ${pkgs.pipewire.lib}/lib/alsa-lib/libasound_module_pcm_pipewire.so ; + libs.native = ${cfg.package.lib}/lib/alsa-lib/libasound_module_pcm_pipewire.so ; ${optionalString enable32BitAlsaPlugins "libs.32Bit = ${pkgs.pkgsi686Linux.pipewire.lib}/lib/alsa-lib/libasound_module_pcm_pipewire.so ;"} } @@ -95,7 +105,7 @@ in { } ''; environment.etc."alsa/conf.d/50-pipewire.conf" = mkIf cfg.alsa.enable { - source = "${pkgs.pipewire}/share/alsa/alsa.conf.d/50-pipewire.conf"; + source = "${cfg.package}/share/alsa/alsa.conf.d/50-pipewire.conf"; }; environment.sessionVariables.LD_LIBRARY_PATH = lib.optional cfg.jack.enable "/run/current-system/sw/lib/pipewire"; From 2c39a011c756c94c019031696dd3032f4977ce28 Mon Sep 17 00:00:00 2001 From: Gabriel Ebner Date: Sun, 29 Nov 2020 19:19:59 +0100 Subject: [PATCH 6/8] pipewire: look for configuration in /etc --- .../libraries/pipewire/default.nix | 3 ++ .../pipewire/pipewire-config-dir.patch | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 pkgs/development/libraries/pipewire/pipewire-config-dir.patch diff --git a/pkgs/development/libraries/pipewire/default.nix b/pkgs/development/libraries/pipewire/default.nix index 9347b7674cf0..d07c77f4e2eb 100644 --- a/pkgs/development/libraries/pipewire/default.nix +++ b/pkgs/development/libraries/pipewire/default.nix @@ -66,6 +66,8 @@ stdenv.mkDerivation rec { ./installed-tests-path.patch # Change the path of the pipewire-pulse binary in the service definition. ./pipewire-pulse-path.patch + # Add flag to specify configuration directory (different from the installation directory). + ./pipewire-config-dir.patch ]; nativeBuildInputs = [ @@ -106,6 +108,7 @@ stdenv.mkDerivation rec { "-Dbluez5-backend-native=${mesonBool nativeHspSupport}" "-Dbluez5-backend-ofono=${mesonBool ofonoSupport}" "-Dbluez5-backend-hsphfpd=${mesonBool hsphfpdSupport}" + "-Dpipewire_config_dir=/etc/pipewire" ]; FONTCONFIG_FILE = fontsConf; # Fontconfig error: Cannot load default config file diff --git a/pkgs/development/libraries/pipewire/pipewire-config-dir.patch b/pkgs/development/libraries/pipewire/pipewire-config-dir.patch new file mode 100644 index 000000000000..ad1ae93684b1 --- /dev/null +++ b/pkgs/development/libraries/pipewire/pipewire-config-dir.patch @@ -0,0 +1,30 @@ +diff --git a/meson.build b/meson.build +index 0073eb13..0ffc6863 100644 +--- a/meson.build ++++ b/meson.build +@@ -34,7 +34,10 @@ pipewire_libexecdir = join_paths(prefix, get_option('libexecdir')) + pipewire_localedir = join_paths(prefix, get_option('localedir')) + pipewire_sysconfdir = join_paths(prefix, get_option('sysconfdir')) + +-pipewire_configdir = join_paths(pipewire_sysconfdir, 'pipewire') ++pipewire_configdir = get_option('pipewire_config_dir') ++if pipewire_configdir == '' ++ pipewire_configdir = join_paths(pipewire_sysconfdir, 'pipewire') ++endif + modules_install_dir = join_paths(pipewire_libdir, pipewire_name) + + if host_machine.system() == 'linux' +diff --git a/meson_options.txt b/meson_options.txt +index 4b9e46b8..8c301459 100644 +--- a/meson_options.txt ++++ b/meson_options.txt +@@ -56,6 +56,9 @@ option('pipewire-pulseaudio', + option('libpulse-path', + description: 'Where to install the libpulse.so library', + type: 'string') ++option('pipewire_config_dir', ++ type : 'string', ++ description : 'Directory for pipewire configuration (defaults to /etc/pipewire)') + option('spa-plugins', + description: 'Enable spa plugins integration', + type: 'boolean', From b28f2f73863ea8c92c8a8a3a97c99968cbfc9d7d Mon Sep 17 00:00:00 2001 From: Gabriel Ebner Date: Sun, 29 Nov 2020 19:20:07 +0100 Subject: [PATCH 7/8] nixos/pipewire: generate configuration file --- nixos/modules/services/desktops/pipewire.nix | 64 ++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/nixos/modules/services/desktops/pipewire.nix b/nixos/modules/services/desktops/pipewire.nix index 57f37b0e525a..7ba04a36b8d3 100644 --- a/nixos/modules/services/desktops/pipewire.nix +++ b/nixos/modules/services/desktops/pipewire.nix @@ -46,6 +46,32 @@ in { ''; }; + extraConfig = mkOption { + type = types.lines; + default = ""; + description = '' + Literal string to append to /etc/pipewire/pipewire.conf. + ''; + }; + + sessionManager = mkOption { + type = types.nullOr types.string; + default = null; + example = literalExample ''"''${pipewire}/bin/pipewire-media-session"''; + description = '' + Path to the pipewire session manager executable. + ''; + }; + + sessionManagerArguments = mkOption { + type = types.listOf types.string; + default = []; + example = literalExample ''[ "-p" "bluez5.msbc-support=true" ]''; + description = '' + Arguments passed to the pipewire session manager. + ''; + }; + alsa = { enable = mkEnableOption "ALSA support"; support32Bit = mkEnableOption "32-bit ALSA support on 64-bit systems"; @@ -75,6 +101,8 @@ in { } ]; + services.pipewire.sessionManager = mkDefault "${cfg.package}/bin/pipewire-media-session"; + environment.systemPackages = [ cfg.package ] ++ lib.optional cfg.jack.enable jack-libs; @@ -110,6 +138,42 @@ in { environment.sessionVariables.LD_LIBRARY_PATH = lib.optional cfg.jack.enable "/run/current-system/sw/lib/pipewire"; + environment.etc."pipewire/pipewire.conf" = { + # Adapted from src/daemon/pipewire.conf.in + text = '' + set-prop link.max-buffers 16 # version < 3 clients can't handle more + + add-spa-lib audio.convert* audioconvert/libspa-audioconvert + add-spa-lib api.alsa.* alsa/libspa-alsa + add-spa-lib api.v4l2.* v4l2/libspa-v4l2 + add-spa-lib api.libcamera.* libcamera/libspa-libcamera + add-spa-lib api.bluez5.* bluez5/libspa-bluez5 + add-spa-lib api.vulkan.* vulkan/libspa-vulkan + add-spa-lib api.jack.* jack/libspa-jack + add-spa-lib support.* support/libspa-support + + load-module libpipewire-module-rtkit # rt.prio=20 rt.time.soft=200000 rt.time.hard=200000 + load-module libpipewire-module-protocol-native + load-module libpipewire-module-profiler + load-module libpipewire-module-metadata + load-module libpipewire-module-spa-device-factory + load-module libpipewire-module-spa-node-factory + load-module libpipewire-module-client-node + load-module libpipewire-module-client-device + load-module libpipewire-module-portal + load-module libpipewire-module-access + load-module libpipewire-module-adapter + load-module libpipewire-module-link-factory + load-module libpipewire-module-session-manager + + create-object spa-node-factory factory.name=support.node.driver node.name=Dummy priority.driver=8000 + + exec ${cfg.sessionManager} ${lib.concatStringsSep " " cfg.sessionManagerArguments} + + ${cfg.extraConfig} + ''; + }; + environment.etc."pipewire/media-session.d/with-alsa" = mkIf cfg.alsa.enable { text = ""; }; environment.etc."pipewire/media-session.d/with-pulseaudio" = mkIf cfg.pulse.enable { text = ""; }; environment.etc."pipewire/media-session.d/with-jack" = mkIf cfg.jack.enable { text = ""; }; From 906d68cf134de8d4995fac334e32c55156cad394 Mon Sep 17 00:00:00 2001 From: Gabriel Ebner Date: Sun, 29 Nov 2020 19:26:26 +0100 Subject: [PATCH 8/8] nixos/pipewire: enable volume control via alsa --- nixos/modules/services/desktops/pipewire.nix | 32 +++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/nixos/modules/services/desktops/pipewire.nix b/nixos/modules/services/desktops/pipewire.nix index 7ba04a36b8d3..0ef988d9e69f 100644 --- a/nixos/modules/services/desktops/pipewire.nix +++ b/nixos/modules/services/desktops/pipewire.nix @@ -117,24 +117,26 @@ in { services.udev.packages = [ cfg.package ]; # If any paths are updated here they must also be updated in the package test. - sound.enable = mkIf cfg.alsa.enable true; - sound.extraConfig = mkIf cfg.alsa.enable '' - pcm_type.pipewire { - libs.native = ${cfg.package.lib}/lib/alsa-lib/libasound_module_pcm_pipewire.so ; - ${optionalString enable32BitAlsaPlugins - "libs.32Bit = ${pkgs.pkgsi686Linux.pipewire.lib}/lib/alsa-lib/libasound_module_pcm_pipewire.so ;"} - } - pcm.!default { - @func getenv - vars [ PCM ] - default "plug:pipewire" - playback_mode "-1" - capture_mode "-1" - } - ''; + environment.etc."alsa/conf.d/49-pipewire-modules.conf" = mkIf cfg.alsa.enable { + text = '' + pcm_type.pipewire { + libs.native = ${cfg.package.lib}/lib/alsa-lib/libasound_module_pcm_pipewire.so ; + ${optionalString enable32BitAlsaPlugins + "libs.32Bit = ${pkgs.pkgsi686Linux.pipewire.lib}/lib/alsa-lib/libasound_module_pcm_pipewire.so ;"} + } + ctl_type.pipewire { + libs.native = ${cfg.package.lib}/lib/alsa-lib/libasound_module_ctl_pipewire.so ; + ${optionalString enable32BitAlsaPlugins + "libs.32Bit = ${pkgs.pkgsi686Linux.pipewire.lib}/lib/alsa-lib/libasound_module_ctl_pipewire.so ;"} + } + ''; + }; environment.etc."alsa/conf.d/50-pipewire.conf" = mkIf cfg.alsa.enable { source = "${cfg.package}/share/alsa/alsa.conf.d/50-pipewire.conf"; }; + environment.etc."alsa/conf.d/99-pipewire-default.conf" = mkIf cfg.alsa.enable { + source = "${cfg.package}/share/alsa/alsa.conf.d/99-pipewire-default.conf"; + }; environment.sessionVariables.LD_LIBRARY_PATH = lib.optional cfg.jack.enable "/run/current-system/sw/lib/pipewire";