2021-02-17 17:02:09 +00:00
|
|
|
# pipewire service.
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2021-04-05 15:23:46 +00:00
|
|
|
json = pkgs.formats.json {};
|
2021-02-17 17:02:09 +00:00
|
|
|
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"
|
|
|
|
'';
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
# Use upstream config files passed through spa-json-dump as the base
|
|
|
|
# Patched here as necessary for them to work with this module
|
|
|
|
defaults = {
|
2021-12-06 16:07:01 +00:00
|
|
|
client = lib.importJSON ./daemon/client.conf.json;
|
|
|
|
client-rt = lib.importJSON ./daemon/client-rt.conf.json;
|
|
|
|
jack = lib.importJSON ./daemon/jack.conf.json;
|
2022-03-05 16:20:37 +00:00
|
|
|
minimal = lib.importJSON ./daemon/minimal.conf.json;
|
2021-12-06 16:07:01 +00:00
|
|
|
pipewire = lib.importJSON ./daemon/pipewire.conf.json;
|
|
|
|
pipewire-pulse = lib.importJSON ./daemon/pipewire-pulse.conf.json;
|
2021-03-09 03:18:52 +00:00
|
|
|
};
|
|
|
|
|
2022-03-05 16:20:37 +00:00
|
|
|
useSessionManager = cfg.wireplumber.enable || cfg.media-session.enable;
|
|
|
|
|
2021-04-05 15:23:46 +00:00
|
|
|
configs = {
|
|
|
|
client = recursiveUpdate defaults.client cfg.config.client;
|
|
|
|
client-rt = recursiveUpdate defaults.client-rt cfg.config.client-rt;
|
|
|
|
jack = recursiveUpdate defaults.jack cfg.config.jack;
|
2022-03-05 16:20:37 +00:00
|
|
|
pipewire = recursiveUpdate (if useSessionManager then defaults.pipewire else defaults.minimal) cfg.config.pipewire;
|
2021-04-05 15:23:46 +00:00
|
|
|
pipewire-pulse = recursiveUpdate defaults.pipewire-pulse cfg.config.pipewire-pulse;
|
|
|
|
};
|
2021-02-17 17:02:09 +00:00
|
|
|
in {
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
maintainers = teams.freedesktop.members;
|
2022-01-07 04:07:37 +00:00
|
|
|
# uses attributes of the linked package
|
|
|
|
buildDocsInSandbox = false;
|
2021-02-17 17:02:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.pipewire = {
|
|
|
|
enable = mkEnableOption "pipewire service";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.pipewire;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.pipewire";
|
2021-02-17 17:02:09 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
config = {
|
|
|
|
client = mkOption {
|
2021-04-05 15:23:46 +00:00
|
|
|
type = json.type;
|
2021-03-09 03:18:52 +00:00
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Configuration for pipewire clients. For details see
|
|
|
|
https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/${cfg.package.version}/src/daemon/client.conf.in
|
|
|
|
'';
|
|
|
|
};
|
2021-02-17 17:02:09 +00:00
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
client-rt = mkOption {
|
2021-04-05 15:23:46 +00:00
|
|
|
type = json.type;
|
2021-03-09 03:18:52 +00:00
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Configuration for realtime pipewire clients. For details see
|
|
|
|
https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/${cfg.package.version}/src/daemon/client-rt.conf.in
|
|
|
|
'';
|
|
|
|
};
|
2021-02-17 17:02:09 +00:00
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
jack = mkOption {
|
2021-04-05 15:23:46 +00:00
|
|
|
type = json.type;
|
2021-03-09 03:18:52 +00:00
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Configuration for the pipewire daemon's jack module. For details see
|
|
|
|
https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/${cfg.package.version}/src/daemon/jack.conf.in
|
|
|
|
'';
|
2021-02-17 17:02:09 +00:00
|
|
|
};
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
pipewire = mkOption {
|
2021-04-05 15:23:46 +00:00
|
|
|
type = json.type;
|
2021-03-09 03:18:52 +00:00
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Configuration for the pipewire daemon. For details see
|
|
|
|
https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/${cfg.package.version}/src/daemon/pipewire.conf.in
|
|
|
|
'';
|
|
|
|
};
|
2021-02-17 17:02:09 +00:00
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
pipewire-pulse = mkOption {
|
2021-04-05 15:23:46 +00:00
|
|
|
type = json.type;
|
2021-03-09 03:18:52 +00:00
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Configuration for the pipewire-pulse daemon. For details see
|
|
|
|
https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/${cfg.package.version}/src/daemon/pipewire-pulse.conf.in
|
|
|
|
'';
|
|
|
|
};
|
2021-02-17 17:02:09 +00:00
|
|
|
};
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
audio = {
|
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
# this is for backwards compatibility
|
|
|
|
default = cfg.alsa.enable || cfg.jack.enable || cfg.pulse.enable;
|
|
|
|
defaultText = lib.literalExpression "config.services.pipewire.alsa.enable || config.services.pipewire.jack.enable || config.services.pipewire.pulse.enable";
|
|
|
|
description = "Whether to use PipeWire as the primary sound server";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-02-17 17:02:09 +00:00
|
|
|
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";
|
|
|
|
};
|
2022-01-07 04:07:37 +00:00
|
|
|
|
|
|
|
systemWide = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If true, a system-wide PipeWire service and socket is enabled
|
|
|
|
allowing all users in the "pipewire" group to use it simultaneously.
|
|
|
|
If false, then user units are used instead, restricting access to
|
|
|
|
only one user.
|
|
|
|
|
|
|
|
Enabling system-wide PipeWire is however not recommended and disabled
|
|
|
|
by default according to
|
|
|
|
https://github.com/PipeWire/pipewire/blob/master/NEWS
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-02-17 17:02:09 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
{
|
2022-03-30 09:31:56 +00:00
|
|
|
assertion = cfg.audio.enable -> !config.hardware.pulseaudio.enable;
|
|
|
|
message = "Using PipeWire as the sound server conflicts with PulseAudio. This option requires `hardware.pulseaudio.enable` to be set to false";
|
2021-02-17 17:02:09 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
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";
|
|
|
|
}
|
2022-03-30 09:31:56 +00:00
|
|
|
{
|
|
|
|
# JACK intentionally not checked, as PW-on-JACK setups are a thing that some people may want
|
|
|
|
assertion = (cfg.alsa.enable || cfg.pulse.enable) -> cfg.audio.enable;
|
|
|
|
message = "Using PipeWire's ALSA/PulseAudio compatibility layers requires running PipeWire as the sound server. Set `services.pipewire.audio.enable` to true.";
|
|
|
|
}
|
2021-02-17 17:02:09 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
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.
|
2022-01-07 04:07:37 +00:00
|
|
|
systemd.services.pipewire.bindsTo = [ "dbus.service" ];
|
|
|
|
systemd.user.services.pipewire.bindsTo = [ "dbus.service" ];
|
|
|
|
|
|
|
|
# Enable either system or user units. Note that for pipewire-pulse there
|
|
|
|
# are only user units, which work in both cases.
|
|
|
|
systemd.sockets.pipewire.enable = cfg.systemWide;
|
|
|
|
systemd.services.pipewire.enable = cfg.systemWide;
|
|
|
|
systemd.user.sockets.pipewire.enable = !cfg.systemWide;
|
|
|
|
systemd.user.services.pipewire.enable = !cfg.systemWide;
|
|
|
|
|
|
|
|
systemd.sockets.pipewire.wantedBy = lib.mkIf cfg.socketActivation [ "sockets.target" ];
|
2021-02-17 17:02:09 +00:00
|
|
|
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"];
|
2022-01-07 04:07:37 +00:00
|
|
|
|
2021-02-17 17:02:09 +00:00
|
|
|
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";
|
|
|
|
};
|
|
|
|
|
2021-04-05 15:23:46 +00:00
|
|
|
environment.etc."pipewire/client.conf" = {
|
|
|
|
source = json.generate "client.conf" configs.client;
|
|
|
|
};
|
|
|
|
environment.etc."pipewire/client-rt.conf" = {
|
|
|
|
source = json.generate "client-rt.conf" configs.client-rt;
|
|
|
|
};
|
|
|
|
environment.etc."pipewire/jack.conf" = {
|
|
|
|
source = json.generate "jack.conf" configs.jack;
|
|
|
|
};
|
|
|
|
environment.etc."pipewire/pipewire.conf" = {
|
|
|
|
source = json.generate "pipewire.conf" configs.pipewire;
|
|
|
|
};
|
2022-06-16 17:23:12 +00:00
|
|
|
environment.etc."pipewire/pipewire-pulse.conf" = mkIf cfg.pulse.enable {
|
2021-04-05 15:23:46 +00:00
|
|
|
source = json.generate "pipewire-pulse.conf" configs.pipewire-pulse;
|
|
|
|
};
|
2021-03-09 03:18:52 +00:00
|
|
|
|
2021-02-17 17:02:09 +00:00
|
|
|
environment.sessionVariables.LD_LIBRARY_PATH =
|
2022-06-16 17:23:12 +00:00
|
|
|
lib.mkIf cfg.jack.enable [ "${cfg.package.jack}/lib" ];
|
2021-02-17 17:02:09 +00:00
|
|
|
|
2022-01-07 04:07:37 +00:00
|
|
|
users = lib.mkIf cfg.systemWide {
|
|
|
|
users.pipewire = {
|
|
|
|
uid = config.ids.uids.pipewire;
|
|
|
|
group = "pipewire";
|
|
|
|
extraGroups = [
|
|
|
|
"audio"
|
|
|
|
"video"
|
|
|
|
] ++ lib.optional config.security.rtkit.enable "rtkit";
|
|
|
|
description = "Pipewire system service user";
|
|
|
|
isSystemUser = true;
|
2022-06-16 17:23:12 +00:00
|
|
|
home = "/var/lib/pipewire";
|
|
|
|
createHome = true;
|
2022-01-07 04:07:37 +00:00
|
|
|
};
|
|
|
|
groups.pipewire.gid = config.ids.gids.pipewire;
|
|
|
|
};
|
|
|
|
|
2021-02-17 17:02:09 +00:00
|
|
|
# https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/464#note_723554
|
2022-01-07 04:07:37 +00:00
|
|
|
systemd.services.pipewire.environment."PIPEWIRE_LINK_PASSIVE" = "1";
|
2021-03-09 03:18:52 +00:00
|
|
|
systemd.user.services.pipewire.environment."PIPEWIRE_LINK_PASSIVE" = "1";
|
2022-06-16 17:23:12 +00:00
|
|
|
|
|
|
|
# pipewire-pulse default config expects pactl to be in PATH
|
|
|
|
systemd.user.services.pipewire-pulse.path = lib.mkIf cfg.pulse.enable [ pkgs.pulseaudio ];
|
2021-02-17 17:02:09 +00:00
|
|
|
};
|
|
|
|
}
|