diff options
author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2021-02-17 12:20:08 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-17 12:20:08 +0000 |
commit | 41b30ed9a69ebfe4720d4365712697025dc1791d (patch) | |
tree | 8340bd46d01a594e88fbedba885a8e897f6933a6 /nixos/modules/services | |
parent | 1afd76b098580824e329d879e3dfaff4cff04c4c (diff) | |
parent | f68cf6f574533f43813f7892940b127ed4f4ac40 (diff) | |
download | nixpkgs-41b30ed9a69ebfe4720d4365712697025dc1791d.tar nixpkgs-41b30ed9a69ebfe4720d4365712697025dc1791d.tar.gz nixpkgs-41b30ed9a69ebfe4720d4365712697025dc1791d.tar.bz2 nixpkgs-41b30ed9a69ebfe4720d4365712697025dc1791d.tar.lz nixpkgs-41b30ed9a69ebfe4720d4365712697025dc1791d.tar.xz nixpkgs-41b30ed9a69ebfe4720d4365712697025dc1791d.tar.zst nixpkgs-41b30ed9a69ebfe4720d4365712697025dc1791d.zip |
Merge staging-next into staging
Diffstat (limited to 'nixos/modules/services')
-rw-r--r-- | nixos/modules/services/desktops/pipewire.nix | 183 | ||||
-rw-r--r-- | nixos/modules/services/desktops/pipewire/pipewire-media-session.nix | 340 | ||||
-rw-r--r-- | nixos/modules/services/desktops/pipewire/pipewire.nix | 265 |
3 files changed, 605 insertions, 183 deletions
diff --git a/nixos/modules/services/desktops/pipewire.nix b/nixos/modules/services/desktops/pipewire.nix deleted file mode 100644 index 134becf6b0c..00000000000 --- a/nixos/modules/services/desktops/pipewire.nix +++ /dev/null @@ -1,183 +0,0 @@ -# pipewire service. -{ config, lib, pkgs, ... }: - -with lib; - -let - cfg = config.services.pipewire; - enable32BitAlsaPlugins = cfg.alsa.support32Bit - && pkgs.stdenv.isx86_64 - && pkgs.pkgsi686Linux.pipewire != null; - - # The package doesn't output to $out/lib/pipewire directly so that the - # overlays can use the outputs to replace the originals in FHS environments. - # - # This doesn't work in general because of missing development information. - jack-libs = pkgs.runCommand "jack-libs" {} '' - mkdir -p "$out/lib" - ln -s "${cfg.package.jack}/lib" "$out/lib/pipewire" - ''; -in { - - meta = { - maintainers = teams.freedesktop.members; - }; - - ###### interface - options = { - 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; - description = '' - Automatically run pipewire when connections are made to the pipewire socket. - ''; - }; - - 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"; - }; - - jack = { - enable = mkEnableOption "JACK audio emulation"; - }; - - pulse = { - enable = mkEnableOption "PulseAudio server emulation"; - }; - }; - }; - - - ###### implementation - config = mkIf cfg.enable { - assertions = [ - { - assertion = cfg.pulse.enable -> !config.hardware.pulseaudio.enable; - message = "PipeWire based PulseAudio server emulation replaces PulseAudio. This option requires `hardware.pulseaudio.enable` to be set to false"; - } - { - assertion = cfg.jack.enable -> !config.services.jack.jackd.enable; - message = "PipeWire based JACK emulation doesn't use the JACK service. This option requires `services.jack.jackd.enable` to be set to false"; - } - ]; - - services.pipewire.sessionManager = mkDefault "${cfg.package}/bin/pipewire-media-session"; - - environment.systemPackages = [ cfg.package ] - ++ lib.optional cfg.jack.enable jack-libs; - - 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 = [ cfg.package ]; - - # If any paths are updated here they must also be updated in the package test. - 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"; - - 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 = ""; }; - }; -} diff --git a/nixos/modules/services/desktops/pipewire/pipewire-media-session.nix b/nixos/modules/services/desktops/pipewire/pipewire-media-session.nix new file mode 100644 index 00000000000..168cf13a88c --- /dev/null +++ b/nixos/modules/services/desktops/pipewire/pipewire-media-session.nix @@ -0,0 +1,340 @@ +# pipewire example session manager. +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.pipewire.media-session; + enable32BitAlsaPlugins = cfg.alsa.support32Bit + && pkgs.stdenv.isx86_64 + && pkgs.pkgsi686Linux.pipewire != null; + + # 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 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)}") + attrs + ) + ); + + toSPAJSON = attrs: lib.concatStringsSep "\n" (mkSPAKeyValue attrs); +in { + + meta = { + maintainers = teams.freedesktop.members; + }; + + ###### interface + options = { + services.pipewire.media-session = { + enable = mkOption { + type = types.bool; + default = true; + description = "Example pipewire session manager"; + }; + + package = mkOption { + type = types.package; + default = pkgs.pipewire.mediaSession; + example = literalExample "pkgs.pipewire.mediaSession"; + description = '' + The pipewire-media-session derivation to use. + ''; + }; + + 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" + ]; + }; + }; + }; + + 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; + }; + }; + } + ]; + }; + }; + + 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; + }; + }; + } + ]; + }; + }; + + 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; + }; + }; + } + ]; + }; + }; + }; + }; + + ###### implementation + config = mkIf cfg.enable { + environment.systemPackages = [ cfg.package ]; + services.pipewire.sessionManagerExecutable = "${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/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/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/with-jack" = mkIf config.services.pipewire.jack.enable { text = ""; }; + }; +} diff --git a/nixos/modules/services/desktops/pipewire/pipewire.nix b/nixos/modules/services/desktops/pipewire/pipewire.nix new file mode 100644 index 00000000000..044120de7c7 --- /dev/null +++ b/nixos/modules/services/desktops/pipewire/pipewire.nix @@ -0,0 +1,265 @@ +# pipewire service. +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.pipewire; + enable32BitAlsaPlugins = cfg.alsa.support32Bit + && pkgs.stdenv.isx86_64 + && pkgs.pkgsi686Linux.pipewire != null; + + # The package doesn't output to $out/lib/pipewire directly so that the + # overlays can use the outputs to replace the originals in FHS environments. + # + # This doesn't work in general because of missing development information. + jack-libs = pkgs.runCommand "jack-libs" {} '' + mkdir -p "$out/lib" + ln -s "${cfg.package.jack}/lib" "$out/lib/pipewire" + ''; + + # 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 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)}") + attrs + ) + ); + + toSPAJSON = attrs: lib.concatStringsSep "\n" (mkSPAKeyValue attrs); +in { + + meta = { + maintainers = teams.freedesktop.members; + }; + + ###### interface + options = { + 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; + description = '' + Automatically run pipewire when connections are made to the pipewire socket. + ''; + }; + + config = mkOption { + type = types.attrs; + description = '' + Configuration for the pipewire daemon. + ''; + default = { + properties = { + ## set-prop is used to configure properties in the system + # + # "library.name.system" = "support/libspa-support"; + # "context.data-loop.library.name.system" = "support/libspa-support"; + "link.max-buffers" = 16; # version < 3 clients can't handle more than 16 + #"mem.allow-mlock" = false; + #"mem.mlock-all" = true; + ## https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/master/src/pipewire/pipewire.h#L93 + #"log.level" = 2; # 5 is trace, which is verbose as hell, default is 2 which is warnings, 4 is debug output, 3 is info + + ## Properties for the DSP configuration + # + #"default.clock.rate" = 48000; + #"default.clock.quantum" = 1024; + #"default.clock.min-quantum" = 32; + #"default.clock.max-quantum" = 8192; + #"default.video.width" = 640; + #"default.video.height" = 480; + #"default.video.rate.num" = 25; + #"default.video.rate.denom" = 1; + }; + + spa-libs = { + ## add-spa-lib <factory-name regex> <library-name> + # + # used to find spa factory names. It maps an spa factory name + # regular expression to a library name that should contain + # that factory. + # + "audio.convert*" = "audioconvert/libspa-audioconvert"; + "api.alsa.*" = "alsa/libspa-alsa"; + "api.v4l2.*" = "v4l2/libspa-v4l2"; + "api.libcamera.*" = "libcamera/libspa-libcamera"; + "api.bluez5.*" = "bluez5/libspa-bluez5"; + "api.vulkan.*" = "vulkan/libspa-vulkan"; + "api.jack.*" = "jack/libspa-jack"; + "support.*" = "support/libspa-support"; + # "videotestsrc" = "videotestsrc/libspa-videotestsrc"; + # "audiotestsrc" = "audiotestsrc/libspa-audiotestsrc"; + }; + + modules = { + ## <module-name> = { [args = "<key>=<value> ..."] + # [flags = ifexists] } + # [flags = [ifexists]|[nofail]} + # + # Loads a module with the given parameters. + # If ifexists is given, the module is ignoed when it is not found. + # If nofail is given, module initialization failures are ignored. + # + libpipewire-module-rtkit = { + args = { + #rt.prio = 20; + #rt.time.soft = 200000; + #rt.time.hard = 200000; + #nice.level = -11; + }; + flags = "ifexists|nofail"; + }; + libpipewire-module-protocol-native = { _priority = -100; _content = "null"; }; + libpipewire-module-profiler = "null"; + libpipewire-module-metadata = "null"; + libpipewire-module-spa-device-factory = "null"; + libpipewire-module-spa-node-factory = "null"; + libpipewire-module-client-node = "null"; + libpipewire-module-client-device = "null"; + libpipewire-module-portal = "null"; + libpipewire-module-access = { + args.access = { + allowed = ["${builtins.unsafeDiscardStringContext cfg.sessionManagerExecutable}"]; + rejected = []; + restricted = []; + force = "flatpak"; + }; + }; + libpipewire-module-adapter = "null"; + libpipewire-module-link-factory = "null"; + libpipewire-module-session-manager = "null"; + }; + + objects = { + ## create-object [-nofail] <factory-name> [<key>=<value> ...] + # + # Creates an object from a PipeWire factory with the given parameters. + # If -nofail is given, errors are ignored (and no object is created) + # + }; + + + exec = { + ## exec <program-name> + # + # Execute the given program. This is usually used to start the + # session manager. run the session manager with -h for options + # + "${builtins.unsafeDiscardStringContext cfg.sessionManagerExecutable}" = { args = "\"${lib.concatStringsSep " " cfg.sessionManagerArguments}\""; }; + }; + }; + }; + + sessionManagerExecutable = mkOption { + type = types.str; + default = ""; + example = literalExample ''${pkgs.pipewire.mediaSession}/bin/pipewire-media-session''; + description = '' + Path to the session manager executable. + ''; + }; + + sessionManagerArguments = mkOption { + type = types.listOf types.str; + 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"; + }; + + jack = { + enable = mkEnableOption "JACK audio emulation"; + }; + + pulse = { + enable = mkEnableOption "PulseAudio server emulation"; + }; + }; + }; + + + ###### implementation + config = mkIf cfg.enable { + assertions = [ + { + assertion = cfg.pulse.enable -> !config.hardware.pulseaudio.enable; + message = "PipeWire based PulseAudio server emulation replaces PulseAudio. This option requires `hardware.pulseaudio.enable` to be set to false"; + } + { + assertion = cfg.jack.enable -> !config.services.jack.jackd.enable; + message = "PipeWire based JACK emulation doesn't use the JACK service. This option requires `services.jack.jackd.enable` to be set to false"; + } + ]; + + environment.systemPackages = [ cfg.package ] + ++ lib.optional cfg.jack.enable jack-libs; + + 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 = [ cfg.package ]; + + # If any paths are updated here they must also be updated in the package test. + 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"; + + # https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/464#note_723554 + systemd.user.services.pipewire.environment = { + "PIPEWIRE_LINK_PASSIVE" = "1"; + "PIPEWIRE_CONFIG_FILE" = pkgs.writeText "pipewire.conf" (toSPAJSON cfg.config); + }; + }; +} |