2018-01-30 17:58:56 +00:00
|
|
|
# pipewire service.
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2018-07-06 05:00:10 +01:00
|
|
|
let
|
|
|
|
cfg = config.services.pipewire;
|
2020-07-23 19:47:11 +01:00
|
|
|
enable32BitAlsaPlugins = cfg.alsa.support32Bit
|
|
|
|
&& pkgs.stdenv.isx86_64
|
|
|
|
&& pkgs.pkgsi686Linux.pipewire != null;
|
2018-07-06 05:00:10 +01:00
|
|
|
|
2020-10-23 18:36:56 +01:00
|
|
|
# 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.
|
2020-07-25 04:28:07 +01:00
|
|
|
jack-libs = pkgs.runCommand "jack-libs" {} ''
|
|
|
|
mkdir -p "$out/lib"
|
2020-11-29 14:25:40 +00:00
|
|
|
ln -s "${cfg.package.jack}/lib" "$out/lib/pipewire"
|
2020-07-25 04:28:07 +01:00
|
|
|
'';
|
2018-07-06 05:00:10 +01:00
|
|
|
in {
|
2020-04-02 01:16:24 +01:00
|
|
|
|
|
|
|
meta = {
|
|
|
|
maintainers = teams.freedesktop.members;
|
|
|
|
};
|
|
|
|
|
2018-01-30 17:58:56 +00:00
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.pipewire = {
|
|
|
|
enable = mkEnableOption "pipewire service";
|
2018-07-06 05:00:10 +01:00
|
|
|
|
2020-11-29 14:25:40 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.pipewire;
|
|
|
|
defaultText = "pkgs.pipewire";
|
|
|
|
example = literalExample "pkgs.pipewire";
|
|
|
|
description = ''
|
|
|
|
The pipewire derivation to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-07-06 05:00:10 +01:00
|
|
|
socketActivation = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Automatically run pipewire when connections are made to the pipewire socket.
|
|
|
|
'';
|
|
|
|
};
|
2020-07-23 19:47:11 +01:00
|
|
|
|
2020-11-29 18:20:07 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-07-23 19:47:11 +01:00
|
|
|
alsa = {
|
2020-10-23 18:36:56 +01:00
|
|
|
enable = mkEnableOption "ALSA support";
|
|
|
|
support32Bit = mkEnableOption "32-bit ALSA support on 64-bit systems";
|
2020-07-23 19:47:11 +01:00
|
|
|
};
|
2020-07-25 04:28:07 +01:00
|
|
|
|
|
|
|
jack = {
|
2020-10-23 18:36:56 +01:00
|
|
|
enable = mkEnableOption "JACK audio emulation";
|
2020-07-25 04:28:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pulse = {
|
2020-11-22 02:42:02 +00:00
|
|
|
enable = mkEnableOption "PulseAudio server emulation";
|
2020-07-25 04:28:07 +01:00
|
|
|
};
|
2018-01-30 17:58:56 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
2018-07-06 05:00:10 +01:00
|
|
|
config = mkIf cfg.enable {
|
2020-10-23 18:36:56 +01:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.pulse.enable -> !config.hardware.pulseaudio.enable;
|
2021-01-06 02:25:48 +00:00
|
|
|
message = "PipeWire based PulseAudio server emulation replaces PulseAudio. This option requires `hardware.pulseaudio.enable` to be set to false";
|
2020-10-23 18:36:56 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.jack.enable -> !config.services.jack.jackd.enable;
|
2021-01-06 02:25:48 +00:00
|
|
|
message = "PipeWire based JACK emulation doesn't use the JACK service. This option requires `services.jack.jackd.enable` to be set to false";
|
2020-10-23 18:36:56 +01:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2020-11-29 18:20:07 +00:00
|
|
|
services.pipewire.sessionManager = mkDefault "${cfg.package}/bin/pipewire-media-session";
|
|
|
|
|
2020-11-29 14:25:40 +00:00
|
|
|
environment.systemPackages = [ cfg.package ]
|
2020-11-22 02:42:02 +00:00
|
|
|
++ lib.optional cfg.jack.enable jack-libs;
|
2018-07-06 05:00:10 +01:00
|
|
|
|
2020-11-29 14:25:40 +00:00
|
|
|
systemd.packages = [ cfg.package ]
|
|
|
|
++ lib.optional cfg.pulse.enable cfg.package.pulse;
|
2018-01-30 17:58:56 +00:00
|
|
|
|
2020-10-23 18:36:56 +01:00
|
|
|
# PipeWire depends on DBUS but doesn't list it. Without this booting
|
|
|
|
# into a terminal results in the service crashing with an error.
|
2018-07-06 05:00:10 +01:00
|
|
|
systemd.user.sockets.pipewire.wantedBy = lib.mkIf cfg.socketActivation [ "sockets.target" ];
|
2020-11-22 02:42:02 +00:00
|
|
|
systemd.user.sockets.pipewire-pulse.wantedBy = lib.mkIf (cfg.socketActivation && cfg.pulse.enable) ["sockets.target"];
|
2020-09-10 17:54:48 +01:00
|
|
|
systemd.user.services.pipewire.bindsTo = [ "dbus.service" ];
|
2020-11-29 14:25:40 +00:00
|
|
|
services.udev.packages = [ cfg.package ];
|
2018-01-30 17:58:56 +00:00
|
|
|
|
2020-08-05 19:48:37 +01:00
|
|
|
# If any paths are updated here they must also be updated in the package test.
|
2020-11-29 18:26:26 +00:00
|
|
|
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 ;"}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2020-07-23 19:47:11 +01:00
|
|
|
environment.etc."alsa/conf.d/50-pipewire.conf" = mkIf cfg.alsa.enable {
|
2020-11-29 14:25:40 +00:00
|
|
|
source = "${cfg.package}/share/alsa/alsa.conf.d/50-pipewire.conf";
|
2020-07-23 19:47:11 +01:00
|
|
|
};
|
2020-11-29 18:26:26 +00:00
|
|
|
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";
|
|
|
|
};
|
2020-10-23 18:36:56 +01:00
|
|
|
environment.sessionVariables.LD_LIBRARY_PATH =
|
2020-11-22 02:42:02 +00:00
|
|
|
lib.optional cfg.jack.enable "/run/current-system/sw/lib/pipewire";
|
2020-11-29 14:20:43 +00:00
|
|
|
|
2020-11-29 18:20:07 +00:00
|
|
|
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}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-11-29 14:20:43 +00:00
|
|
|
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 = ""; };
|
2020-07-23 19:47:11 +01:00
|
|
|
};
|
2018-01-30 17:58:56 +00:00
|
|
|
}
|