2022-12-09 00:31:56 +00:00
|
|
|
with import ./lib;
|
|
|
|
{ config, pkgs, ... }: let
|
2022-05-31 18:13:11 +00:00
|
|
|
pkg = pkgs.pulseaudio;
|
2015-11-25 00:51:35 +00:00
|
|
|
runDir = "/run/pulse";
|
|
|
|
|
2019-04-08 17:05:25 +00:00
|
|
|
pkgs_i686 = pkgs.pkgsi686Linux;
|
|
|
|
|
2017-07-12 21:45:02 +00:00
|
|
|
support32Bit =
|
|
|
|
pkgs.stdenv.isx86_64 &&
|
|
|
|
pkgs_i686.alsaLib != null &&
|
|
|
|
pkgs_i686.libpulseaudio != null;
|
|
|
|
|
2015-11-25 00:51:35 +00:00
|
|
|
alsaConf = pkgs.writeText "asound.conf" ''
|
|
|
|
ctl_type.pulse {
|
|
|
|
libs.native = ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_ctl_pulse.so;
|
2017-07-12 21:45:02 +00:00
|
|
|
${optionalString support32Bit
|
|
|
|
"libs.32Bit = ${pkgs_i686.alsaPlugins}/lib/alsa-lib/libasound_module_ctl_pulse.so;"}
|
2015-11-25 00:51:35 +00:00
|
|
|
}
|
|
|
|
pcm_type.pulse {
|
|
|
|
libs.native = ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_pcm_pulse.so;
|
2017-07-12 21:45:02 +00:00
|
|
|
${optionalString support32Bit
|
|
|
|
"libs.32Bit = ${pkgs_i686.alsaPlugins}/lib/alsa-lib/libasound_module_pcm_pulse.so;"}
|
2015-11-25 00:51:35 +00:00
|
|
|
}
|
|
|
|
ctl.!default {
|
|
|
|
type pulse
|
|
|
|
}
|
|
|
|
pcm.!default {
|
|
|
|
type pulse
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
clientConf = pkgs.writeText "client.conf" ''
|
|
|
|
autospawn=no
|
|
|
|
default-server = unix:${runDir}/socket
|
|
|
|
'';
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "default.pa" ''
|
|
|
|
.include ${pkg}/etc/pulse/default.pa
|
|
|
|
load-module ${toString [
|
|
|
|
"module-native-protocol-unix"
|
|
|
|
"auth-anonymous=1"
|
|
|
|
"socket=${runDir}/socket"
|
|
|
|
]}
|
2021-03-15 01:05:37 +00:00
|
|
|
${lib.optionalString (config.krebs.build.host.name == "au") ''
|
|
|
|
load-module ${toString [
|
|
|
|
"module-native-protocol-tcp"
|
|
|
|
"auth-ip-acl=127.0.0.1;10.23.1.0/24"
|
|
|
|
]}
|
|
|
|
''}
|
|
|
|
${lib.optionalString (config.krebs.build.host.name != "au") ''
|
|
|
|
load-module ${toString [
|
|
|
|
"module-tunnel-sink-new"
|
|
|
|
"server=au.hkw"
|
|
|
|
"sink_name=au"
|
|
|
|
"channels=2"
|
|
|
|
"rate=44100"
|
|
|
|
]}
|
|
|
|
''}
|
2015-11-25 00:51:35 +00:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
environment = {
|
|
|
|
etc = {
|
|
|
|
"asound.conf".source = alsaConf;
|
2016-01-14 14:48:16 +00:00
|
|
|
# XXX mkForce is not strong enough (and neither is mkOverride) to create
|
|
|
|
# /etc/pulse/client.conf, see pulseaudio-hack below for a solution.
|
|
|
|
#"pulse/client.conf" = mkForce { source = clientConf; };
|
|
|
|
#"pulse/client.conf".source = mkForce clientConf;
|
2015-11-25 00:51:35 +00:00
|
|
|
"pulse/default.pa".source = configFile;
|
|
|
|
};
|
2016-01-14 14:51:41 +00:00
|
|
|
systemPackages = [
|
|
|
|
pkg
|
|
|
|
] ++ optionals config.services.xserver.enable [
|
|
|
|
pkgs.pavucontrol
|
|
|
|
];
|
2015-11-25 00:51:35 +00:00
|
|
|
};
|
|
|
|
|
2017-07-12 21:45:02 +00:00
|
|
|
hardware.pulseaudio = {
|
|
|
|
inherit support32Bit;
|
|
|
|
};
|
|
|
|
|
2015-11-25 00:51:35 +00:00
|
|
|
# Allow PulseAudio to get realtime priority using rtkit.
|
|
|
|
security.rtkit.enable = true;
|
|
|
|
|
2016-01-14 14:48:16 +00:00
|
|
|
system.activationScripts.pulseaudio-hack = ''
|
|
|
|
ln -fns ${clientConf} /etc/pulse/client.conf
|
|
|
|
'';
|
|
|
|
|
2015-11-25 00:51:35 +00:00
|
|
|
systemd.services.pulse = {
|
|
|
|
wantedBy = [ "sound.target" ];
|
|
|
|
before = [ "sound.target" ];
|
|
|
|
environment = {
|
|
|
|
PULSE_RUNTIME_PATH = "${runDir}/home";
|
|
|
|
};
|
|
|
|
serviceConfig = {
|
2016-11-18 09:51:18 +00:00
|
|
|
ExecStart = "${pkg}/bin/pulseaudio --exit-idle-time=-1";
|
2016-06-13 00:04:22 +00:00
|
|
|
ExecStartPre = pkgs.writeDash "pulse-start" ''
|
2016-01-14 14:45:41 +00:00
|
|
|
install -o pulse -g pulse -m 0750 -d ${runDir}
|
|
|
|
install -o pulse -g pulse -m 0700 -d ${runDir}/home
|
|
|
|
'';
|
|
|
|
PermissionsStartOnly = "true";
|
2015-11-25 00:51:35 +00:00
|
|
|
User = "pulse";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-03-06 12:11:21 +00:00
|
|
|
# TODO assert that pulse is the only user with "audio" in group/extraGroups
|
|
|
|
# otherwise the audio device can be hijacked while the pulse service restarts
|
|
|
|
# (e.g. when mpv is running) and then the service will fail.
|
2015-12-26 04:55:13 +00:00
|
|
|
users = {
|
|
|
|
groups.pulse.gid = config.users.users.pulse.uid;
|
2015-11-25 00:51:35 +00:00
|
|
|
users.pulse = {
|
2018-12-02 18:25:56 +00:00
|
|
|
uid = genid_uint31 "pulse";
|
2015-11-25 00:51:35 +00:00
|
|
|
group = "pulse";
|
|
|
|
extraGroups = [ "audio" ];
|
|
|
|
home = "${runDir}/home";
|
2021-06-01 22:11:38 +00:00
|
|
|
isSystemUser = true;
|
2015-11-25 00:51:35 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|