2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-07-26 02:51:56 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2013-02-28 18:40:07 +00:00
|
|
|
with pkgs;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.hardware.pulseaudio;
|
|
|
|
|
2014-04-21 10:50:49 +01:00
|
|
|
systemWide = cfg.enable && cfg.systemWide;
|
|
|
|
nonSystemWide = cfg.enable && !cfg.systemWide;
|
|
|
|
|
2013-02-28 18:40:07 +00:00
|
|
|
uid = config.ids.uids.pulseaudio;
|
|
|
|
gid = config.ids.gids.pulseaudio;
|
|
|
|
|
2014-04-21 10:50:49 +01:00
|
|
|
stateDir = "/run/pulse";
|
2013-02-28 18:40:07 +00:00
|
|
|
|
|
|
|
# Create pulse/client.conf even if PulseAudio is disabled so
|
|
|
|
# that we can disable the autospawn feature in programs that
|
|
|
|
# are built with PulseAudio support (like KDE).
|
|
|
|
clientConf = writeText "client.conf" ''
|
2014-04-21 10:50:49 +01:00
|
|
|
autospawn=${if nonSystemWide then "yes" else "no"}
|
|
|
|
${optionalString nonSystemWide "daemon-binary=${cfg.package}/bin/pulseaudio"}
|
2013-02-28 18:40:07 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
# Write an /etc/asound.conf that causes all ALSA applications to
|
|
|
|
# be re-routed to the PulseAudio server through ALSA's Pulse
|
|
|
|
# plugin.
|
|
|
|
alsaConf = writeText "asound.conf" ''
|
|
|
|
pcm_type.pulse {
|
|
|
|
lib ${alsaPlugins}/lib/alsa-lib/libasound_module_pcm_pulse.so
|
|
|
|
}
|
|
|
|
pcm.!default {
|
|
|
|
type pulse
|
|
|
|
hint.description "Default Audio Device (via PulseAudio)"
|
|
|
|
}
|
|
|
|
ctl_type.pulse {
|
|
|
|
lib ${alsaPlugins}/lib/alsa-lib/libasound_module_ctl_pulse.so
|
|
|
|
}
|
|
|
|
ctl.!default {
|
|
|
|
type pulse
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
2011-07-26 02:51:56 +01:00
|
|
|
|
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2013-02-28 18:40:07 +00:00
|
|
|
hardware.pulseaudio = {
|
|
|
|
enable = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.bool;
|
2013-02-28 18:40:07 +00:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the PulseAudio sound server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
systemWide = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If false, a PulseAudio server is launched automatically for
|
|
|
|
each user that tries to use the sound system. The server runs
|
2013-08-10 22:07:13 +01:00
|
|
|
with user privileges. This is the recommended and most secure
|
2013-02-28 18:40:07 +00:00
|
|
|
way to use PulseAudio. If true, one system-wide PulseAudio
|
|
|
|
server is launched on boot, running as the user "pulse".
|
|
|
|
Please read the PulseAudio documentation for more details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
configFile = mkOption {
|
|
|
|
type = types.uniq types.path;
|
2014-04-21 10:50:49 +01:00
|
|
|
default = "${cfg.package}/etc/pulse/default.pa";
|
2013-02-28 18:40:07 +00:00
|
|
|
description = ''
|
|
|
|
The path to the configuration the PulseAudio server
|
|
|
|
should use. By default, the "default.pa" configuration
|
|
|
|
from the PulseAudio distribution is used.
|
2013-10-30 16:37:45 +00:00
|
|
|
'';
|
2013-02-28 18:40:07 +00:00
|
|
|
};
|
2013-10-30 16:37:45 +00:00
|
|
|
|
2013-02-28 18:40:07 +00:00
|
|
|
package = mkOption {
|
2014-02-27 12:22:04 +00:00
|
|
|
type = types.package;
|
2013-02-28 18:40:07 +00:00
|
|
|
default = pulseaudio;
|
2013-10-30 16:37:45 +00:00
|
|
|
example = literalExample "pulseaudio.override { jackaudioSupport = true; }";
|
2013-02-28 18:40:07 +00:00
|
|
|
description = ''
|
|
|
|
The PulseAudio derivation to use. This can be used to enable
|
|
|
|
features (such as JACK support) that are not enabled in the
|
|
|
|
default PulseAudio in Nixpkgs.
|
|
|
|
'';
|
|
|
|
};
|
2014-04-21 10:50:49 +01:00
|
|
|
|
|
|
|
daemon = {
|
|
|
|
logLevel = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "notice";
|
|
|
|
description = ''
|
|
|
|
The log level that the system-wide pulseaudio daemon should use,
|
|
|
|
if activated.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2011-08-01 14:26:51 +01:00
|
|
|
};
|
|
|
|
|
2011-07-26 02:51:56 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-07-26 02:51:56 +01:00
|
|
|
|
2013-02-28 18:40:07 +00:00
|
|
|
config = mkMerge [
|
|
|
|
{
|
|
|
|
environment.etc = singleton {
|
|
|
|
target = "pulse/client.conf";
|
|
|
|
source = clientConf;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
(mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
environment.etc = singleton {
|
|
|
|
target = "asound.conf";
|
|
|
|
source = alsaConf;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Allow PulseAudio to get realtime priority using rtkit.
|
|
|
|
security.rtkit.enable = true;
|
|
|
|
})
|
|
|
|
|
2014-04-21 10:50:49 +01:00
|
|
|
(mkIf nonSystemWide {
|
2013-02-28 18:40:07 +00:00
|
|
|
environment.etc = singleton {
|
|
|
|
target = "pulse/default.pa";
|
|
|
|
source = cfg.configFile;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2014-04-21 10:50:49 +01:00
|
|
|
(mkIf systemWide {
|
2013-02-28 18:40:07 +00:00
|
|
|
users.extraUsers.pulse = {
|
|
|
|
# For some reason, PulseAudio wants UID == GID.
|
|
|
|
uid = assert uid == gid; uid;
|
|
|
|
group = "pulse";
|
|
|
|
extraGroups = [ "audio" ];
|
|
|
|
description = "PulseAudio system service user";
|
|
|
|
};
|
2013-10-30 16:37:45 +00:00
|
|
|
|
2013-02-28 18:40:07 +00:00
|
|
|
users.extraGroups.pulse.gid = gid;
|
2013-10-30 16:37:45 +00:00
|
|
|
|
2013-02-28 18:40:07 +00:00
|
|
|
systemd.services.pulseaudio = {
|
2013-11-09 19:06:01 +00:00
|
|
|
description = "PulseAudio System-Wide Server";
|
2013-02-28 18:40:07 +00:00
|
|
|
wantedBy = [ "sound.target" ];
|
|
|
|
before = [ "sound.target" ];
|
2014-04-21 10:50:49 +01:00
|
|
|
environment.PULSE_RUNTIME_PATH = stateDir;
|
2013-02-28 18:40:07 +00:00
|
|
|
preStart = ''
|
2014-04-21 10:50:49 +01:00
|
|
|
mkdir -p --mode 755 ${stateDir}
|
|
|
|
chown -R pulse:pulse ${stateDir}
|
2013-02-28 18:40:07 +00:00
|
|
|
'';
|
2014-04-21 10:50:49 +01:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${cfg.package}/bin/pulseaudio -D --log-level=${cfg.daemon.logLevel} --system --use-pid-file -n --file=${cfg.configFile}";
|
|
|
|
PIDFile = "${stateDir}/pid";
|
|
|
|
};
|
2013-02-28 18:40:07 +00:00
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
2011-07-26 02:51:56 +01:00
|
|
|
|
|
|
|
}
|