summary refs log tree commit diff
path: root/nixos/modules/services/desktops/pipewire/pipewire-media-session.nix
diff options
context:
space:
mode:
authorJan Solanti <jhs@psonet.com>2021-02-25 16:22:40 +0200
committerJan Solanti <jan.solanti@tuni.fi>2021-03-05 00:39:32 +0200
commit78bfbdd77aa9e42302ed71072cf0b3110f350f46 (patch)
tree008806c2df8ae35df1e3093bcf224841a13c4720 /nixos/modules/services/desktops/pipewire/pipewire-media-session.nix
parent96e9a7c30b79ff633eb2c48ab42428e63997429f (diff)
downloadnixpkgs-78bfbdd77aa9e42302ed71072cf0b3110f350f46.tar
nixpkgs-78bfbdd77aa9e42302ed71072cf0b3110f350f46.tar.gz
nixpkgs-78bfbdd77aa9e42302ed71072cf0b3110f350f46.tar.bz2
nixpkgs-78bfbdd77aa9e42302ed71072cf0b3110f350f46.tar.lz
nixpkgs-78bfbdd77aa9e42302ed71072cf0b3110f350f46.tar.xz
nixpkgs-78bfbdd77aa9e42302ed71072cf0b3110f350f46.tar.zst
nixpkgs-78bfbdd77aa9e42302ed71072cf0b3110f350f46.zip
pipewire: 0.3.21 -> 0.3.22
Diffstat (limited to 'nixos/modules/services/desktops/pipewire/pipewire-media-session.nix')
-rw-r--r--nixos/modules/services/desktops/pipewire/pipewire-media-session.nix319
1 files changed, 53 insertions, 266 deletions
diff --git a/nixos/modules/services/desktops/pipewire/pipewire-media-session.nix b/nixos/modules/services/desktops/pipewire/pipewire-media-session.nix
index 81f4762e1e6..b324bfa1b74 100644
--- a/nixos/modules/services/desktops/pipewire/pipewire-media-session.nix
+++ b/nixos/modules/services/desktops/pipewire/pipewire-media-session.nix
@@ -9,18 +9,36 @@ let
                            && pkgs.stdenv.isx86_64
                            && pkgs.pkgsi686Linux.pipewire != null;
 
+  prioritizeNativeProtocol = {
+    "context.modules" = {
+      "libpipewire-module-protocol-native" = {
+        _priority = -100;
+        _content = null;
+      };
+    };
+  };
+
+  # Use upstream config files passed through spa-json-dump as the base
+  # Patched here as necessary for them to work with this module
+  defaults = {
+    alsa-monitor = (builtins.fromJSON (builtins.readFile ./alsa-monitor.conf.json));
+    bluez-monitor = (builtins.fromJSON (builtins.readFile ./bluez-monitor.conf.json));
+    media-session = recursiveUpdate (builtins.fromJSON (builtins.readFile ./media-session.conf.json)) prioritizeNativeProtocol;
+    v4l2-monitor = (builtins.fromJSON (builtins.readFile ./v4l2-monitor.conf.json));
+  };
   # Helpers for generating the pipewire JSON config file
   mkSPAValueString = v:
   if builtins.isList v then "[${lib.concatMapStringsSep " " mkSPAValueString v}]"
   else if lib.types.attrs.check v then
     "{${lib.concatStringsSep " " (mkSPAKeyValue v)}}"
+  else if builtins.isString v then "\"${lib.generators.mkValueStringDefault { } v}\""
   else lib.generators.mkValueStringDefault { } v;
 
   mkSPAKeyValue = attrs: map (def: def.content) (
   lib.sortProperties
     (
       lib.mapAttrsToList
-        (k: v: lib.mkOrder (v._priority or 1000) "${lib.escape [ "=" ] k} = ${mkSPAValueString (v._content or v)}")
+        (k: v: lib.mkOrder (v._priority or 1000) "${lib.escape [ "=" ":" ] k} = ${mkSPAValueString (v._content or v)}")
         attrs
     )
   );
@@ -51,272 +69,41 @@ in {
         '';
       };
 
-      config = mkOption {
-        type = types.attrs;
-        description = ''
-          Configuration for the media session core.
-        '';
-        default = {
-          # media-session config file
-          properties = {
-            # Properties to configure the session and some
-            # modules
-            #mem.mlock-all = false;
-            #context.profile.modules = "default,rtkit";
-          };
-
-          spa-libs = {
-            # Mapping from factory name to library.
-            "api.bluez5.*" = "bluez5/libspa-bluez5";
-            "api.alsa.*" = "alsa/libspa-alsa";
-            "api.v4l2.*" = "v4l2/libspa-v4l2";
-            "api.libcamera.*" = "libcamera/libspa-libcamera";
-          };
-
-          modules = {
-            # These are the modules that are enabled when a file with
-            # the key name is found in the media-session.d config directory.
-            # the default bundle is always enabled.
-
-            default = [
-              "flatpak"			# manages flatpak access
-              "portal"			# manage portal permissions
-              "v4l2"			# video for linux udev detection
-              #"libcamera"		# libcamera udev detection
-              "suspend-node"		# suspend inactive nodes
-              "policy-node"		# configure and link nodes
-              #"metadata"		# export metadata API
-              #"default-nodes"		# restore default nodes
-              #"default-profile"	# restore default profiles
-              #"default-routes"		# restore default route
-              #"streams-follow-default"	# move streams when default changes
-              #"alsa-seq"		# alsa seq midi support
-              #"alsa-monitor"		# alsa udev detection
-              #"bluez5"			# bluetooth support
-              #"restore-stream"		# restore stream settings
-            ];
-            "with-audio" = [
-              "metadata"
-              "default-nodes"
-              "default-profile"
-              "default-routes"
-              "alsa-seq"
-              "alsa-monitor"
-            ];
-            "with-alsa" = [
-              "with-audio"
-            ];
-            "with-jack" = [
-              "with-audio"
-            ];
-            "with-pulseaudio" = [
-              "with-audio"
-              "bluez5"
-              "restore-stream"
-              "streams-follow-default"
-            ];
-          };
+      config = {
+        media-session = mkOption {
+          type = types.attrs;
+          description = ''
+            Configuration for the media session core. For details see
+            https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/${cfg.package.version}/src/daemon/media-session.d/media-session.conf
+          '';
+          default = {};
         };
-      };
-
-      alsaMonitorConfig = mkOption {
-        type = types.attrs;
-        description = ''
-          Configuration for the alsa monitor.
-        '';
-        default = {
-          # alsa-monitor config file
-          properties = {
-            #alsa.jack-device = true
-          };
 
-          rules = [
-          # an array of matches/actions to evaluate
-          {
-            # rules for matching a device or node. It is an array of
-            # properties that all need to match the regexp. If any of the
-            # matches work, the actions are executed for the object.
-            matches = [
-              {
-                # this matches all cards
-                device.name = "~alsa_card.*";
-              }
-            ];
-            actions = {
-              # actions can update properties on the matched object.
-              update-props = {
-                api.alsa.use-acp = true;
-                #api.alsa.use-ucm = true;
-                #api.alsa.soft-mixer = false;
-                #api.alsa.ignore-dB = false;
-                #device.profile-set = "profileset-name";
-                #device.profile = "default profile name";
-                api.acp.auto-profile = false;
-                api.acp.auto-port = false;
-                #device.nick = "My Device";
-              };
-            };
-          }
-          {
-            matches = [
-              {
-                # matches all sinks
-                node.name = "~alsa_input.*";
-              }
-              {
-                # matches all sources
-                node.name = "~alsa_output.*";
-              }
-            ];
-            actions = {
-              update-props = {
-                #node.nick = 			"My Node";
-                #node.nick = 			null;
-                #priority.driver = 		100;
-                #priority.session = 		100;
-                #node.pause-on-idle = 		false;
-                #resample.quality = 		4;
-                #channelmix.normalize =		false;
-                #channelmix.mix-lfe = 		false;
-                #audio.channels = 		2;
-                #audio.format = 		"S16LE";
-                #audio.rate = 			44100;
-                #audio.position = 		"FL,FR";
-                #api.alsa.period-size =         1024;
-                #api.alsa.headroom =            0;
-                #api.alsa.disable-mmap =        false;
-                #api.alsa.disable-batch =       false;
-              };
-            };
-          }
-          ];
+        alsa-monitor = mkOption {
+          type = types.attrs;
+          description = ''
+            Configuration for the alsa monitor. For details see
+            https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/${cfg.package.version}/src/daemon/media-session.d/alsa-monitor.conf
+          '';
+          default = {};
         };
-      };
-
-      bluezMonitorConfig = mkOption {
-        type = types.attrs;
-        description = ''
-          Configuration for the bluez5 monitor.
-        '';
-        default = {
-          # bluez-monitor config file
-          properties = {
-            # msbc is not expected to work on all headset + adapter combinations.
-            #bluez5.msbc-support = true;
-            #bluez5.sbc-xq-support = true;
 
-            # Enabled headset roles (default: [ hsp_hs hfp_ag ]), this
-            # property only applies to native backend. Currently some headsets
-            # (Sony WH-1000XM3) are not working with both hsp_ag and hfp_ag
-            # enabled, disable either hsp_ag or hfp_ag to work around it.
-            #
-            # Supported headset roles: hsp_hs (HSP Headset),
-            #                          hsp_ag (HSP Audio Gateway),
-            #                          hfp_ag (HFP Audio Gateway)
-            #bluez5.headset-roles = [ "hsp_hs" "hsp_ag" "hfp_ag" ];
-
-            # Enabled A2DP codecs (default: all)
-            #bluez5.codecs = [ "sbc" "aac" "ldac" "aptx" "aptx_hd" ];
-          };
-
-          rules = [
-          # an array of matches/actions to evaluate
-          {
-            # rules for matching a device or node. It is an array of
-            # properties that all need to match the regexp. If any of the
-            # matches work, the actions are executed for the object.
-            matches = [
-              {
-                # this matches all cards
-                device.name = "~bluez_card.*";
-              }
-            ];
-            actions = {
-              # actions can update properties on the matched object.
-              update-props = {
-                #device.nick = 			"My Device";
-              };
-            };
-          }
-          {
-            matches = [
-              {
-                # matches all sinks
-                node.name = "~bluez_input.*";
-              }
-              {
-                # matches all sources
-                node.name = "~bluez_output.*";
-              }
-            ];
-            actions = {
-              update-props = {
-                #node.nick = 			"My Node"
-                #node.nick = 			null;
-                #priority.driver = 		100;
-                #priority.session = 		100;
-                #node.pause-on-idle = 		false;
-                #resample.quality = 		4;
-                #channelmix.normalize =		false;
-                #channelmix.mix-lfe = 		false;
-              };
-            };
-          }
-          ];
+        bluez-monitor = mkOption {
+          type = types.attrs;
+          description = ''
+            Configuration for the bluez5 monitor. For details see
+            https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/${cfg.package.version}/src/daemon/media-session.d/bluez-monitor.conf
+          '';
+          default = {};
         };
-      };
-
-      v4l2MonitorConfig = mkOption {
-        type = types.attrs;
-        description = ''
-          Configuration for the V4L2 monitor.
-        '';
-        default = {
-          # v4l2-monitor config file
-          properties = {
-          };
 
-          rules = [
-            # an array of matches/actions to evaluate
-            {
-              # rules for matching a device or node. It is an array of
-              # properties that all need to match the regexp. If any of the
-              # matches work, the actions are executed for the object.
-              matches = [
-                {
-                  # this matches all devices
-                  device.name = "~v4l2_device.*";
-                }
-              ];
-              actions = {
-                # actions can update properties on the matched object.
-                update-props = {
-                  #device.nick = 			"My Device";
-                };
-              };
-            }
-            {
-              matches = [
-                {
-                  # matches all sinks
-                  node.name = "~v4l2_input.*";
-                }
-                {
-                  # matches all sources
-                  node.name = "~v4l2_output.*";
-                }
-              ];
-              actions = {
-                update-props = {
-                  #node.nick = 			"My Node";
-                  #node.nick = 			null;
-                  #priority.driver = 		100;
-                  #priority.session = 		100;
-                  #node.pause-on-idle = 		true;
-                };
-              };
-            }
-          ];
+        v4l2-monitor = mkOption {
+          type = types.attrs;
+          description = ''
+            Configuration for the V4L2 monitor. For details see
+            https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/${cfg.package.version}/src/daemon/media-session.d/v4l2-monitor.conf
+          '';
+          default = {};
         };
       };
     };
@@ -325,16 +112,16 @@ in {
   ###### implementation
   config = mkIf cfg.enable {
     environment.systemPackages = [ cfg.package ];
-    services.pipewire.sessionManagerExecutable = "${cfg.package}/bin/pipewire-media-session";
+    services.pipewire.sessionManagerExecutable = builtins.unsafeDiscardStringContext "${cfg.package}/bin/pipewire-media-session";
 
-    environment.etc."pipewire/media-session.d/media-session.conf" = { text = toSPAJSON cfg.config; };
-    environment.etc."pipewire/media-session.d/v4l2-monitor.conf" = { text = toSPAJSON cfg.v4l2MonitorConfig; };
+    environment.etc."pipewire/media-session.d/media-session.conf" = { text = toSPAJSON (recursiveUpdate defaults.media-session cfg.config.media-session); };
+    environment.etc."pipewire/media-session.d/v4l2-monitor.conf" = { text = toSPAJSON (recursiveUpdate defaults.v4l2-monitor cfg.config.v4l2-monitor); };
 
     environment.etc."pipewire/media-session.d/with-alsa" = mkIf config.services.pipewire.alsa.enable { text = ""; };
-    environment.etc."pipewire/media-session.d/alsa-monitor.conf" = mkIf config.services.pipewire.alsa.enable { text = toSPAJSON cfg.alsaMonitorConfig; };
+    environment.etc."pipewire/media-session.d/alsa-monitor.conf" = mkIf config.services.pipewire.alsa.enable { text = toSPAJSON (recursiveUpdate defaults.alsa-monitor cfg.config.alsa-monitor); };
 
     environment.etc."pipewire/media-session.d/with-pulseaudio" = mkIf config.services.pipewire.pulse.enable { text = ""; };
-    environment.etc."pipewire/media-session.d/bluez-monitor.conf" = mkIf config.services.pipewire.pulse.enable { text = toSPAJSON cfg.bluezMonitorConfig; };
+    environment.etc."pipewire/media-session.d/bluez-monitor.conf" = mkIf config.services.pipewire.pulse.enable { text = toSPAJSON (recursiveUpdate defaults.bluez-monitor cfg.config.bluez-monitor); };
 
     environment.etc."pipewire/media-session.d/with-jack" = mkIf config.services.pipewire.jack.enable { text = ""; };
   };