2020-04-24 23:36:52 +00:00
|
|
|
# pipewire service.
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.pipewire;
|
2020-10-27 00:29:36 +00:00
|
|
|
enable32BitAlsaPlugins = cfg.alsa.support32Bit
|
|
|
|
&& pkgs.stdenv.isx86_64
|
|
|
|
&& pkgs.pkgsi686Linux.pipewire != null;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-10-27 00:29:36 +00: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.
|
|
|
|
jack-libs = pkgs.runCommand "jack-libs" {} ''
|
|
|
|
mkdir -p "$out/lib"
|
|
|
|
ln -s "${pkgs.pipewire.jack}/lib" "$out/lib/pipewire"
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
in {
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
maintainers = teams.freedesktop.members;
|
|
|
|
};
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.pipewire = {
|
|
|
|
enable = mkEnableOption "pipewire service";
|
|
|
|
|
|
|
|
socketActivation = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Automatically run pipewire when connections are made to the pipewire socket.
|
|
|
|
'';
|
|
|
|
};
|
2020-10-27 00:29:36 +00:00
|
|
|
|
|
|
|
alsa = {
|
|
|
|
enable = mkEnableOption "ALSA support";
|
|
|
|
support32Bit = mkEnableOption "32-bit ALSA support on 64-bit systems";
|
|
|
|
};
|
|
|
|
|
|
|
|
jack = {
|
|
|
|
enable = mkEnableOption "JACK audio emulation";
|
|
|
|
};
|
|
|
|
|
|
|
|
pulse = {
|
2020-11-30 08:33:03 +00:00
|
|
|
enable = mkEnableOption "PulseAudio server emulation";
|
2020-10-27 00:29:36 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable {
|
2020-10-27 00:29:36 +00:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.pulse.enable -> !config.hardware.pulseaudio.enable;
|
2020-11-30 08:33:03 +00:00
|
|
|
message = "PipeWire based PulseAudio server emulation replaces PulseAudio";
|
2020-10-27 00:29:36 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.jack.enable -> !config.services.jack.jackd.enable;
|
2020-11-30 08:33:03 +00:00
|
|
|
message = "PipeWire based JACK emulation doesn't use the JACK service";
|
2020-10-27 00:29:36 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.pipewire ]
|
2020-11-30 08:33:03 +00:00
|
|
|
++ lib.optional cfg.jack.enable jack-libs;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-11-30 08:33:03 +00:00
|
|
|
systemd.packages = [ pkgs.pipewire ]
|
|
|
|
++ lib.optional cfg.pulse.enable pkgs.pipewire.pulse;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-10-27 00:29:36 +00:00
|
|
|
# PipeWire depends on DBUS but doesn't list it. Without this booting
|
|
|
|
# into a terminal results in the service crashing with an error.
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.user.sockets.pipewire.wantedBy = lib.mkIf cfg.socketActivation [ "sockets.target" ];
|
2020-11-30 08:33:03 +00:00
|
|
|
systemd.user.sockets.pipewire-pulse.wantedBy = lib.mkIf (cfg.socketActivation && cfg.pulse.enable) ["sockets.target"];
|
2020-10-27 00:29:36 +00:00
|
|
|
systemd.user.services.pipewire.bindsTo = [ "dbus.service" ];
|
|
|
|
services.udev.packages = [ pkgs.pipewire ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-10-27 00:29:36 +00:00
|
|
|
# If any paths are updated here they must also be updated in the package test.
|
|
|
|
sound.extraConfig = mkIf cfg.alsa.enable ''
|
|
|
|
pcm_type.pipewire {
|
|
|
|
libs.native = ${pkgs.pipewire.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/50-pipewire.conf" = mkIf cfg.alsa.enable {
|
|
|
|
source = "${pkgs.pipewire}/share/alsa/alsa.conf.d/50-pipewire.conf";
|
|
|
|
};
|
|
|
|
environment.sessionVariables.LD_LIBRARY_PATH =
|
2020-11-30 08:33:03 +00:00
|
|
|
lib.optional cfg.jack.enable "/run/current-system/sw/lib/pipewire";
|
2020-10-27 00:29:36 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|