forked from mirrors/nixpkgs
Merge hardware.pulseaudio and services.pulseaudio
More specifically, this removes services.pulseaudio and adds the option hardware.pulseaudio.systemWide which defaults to false but can be used to turn on the system-wide PulseAudio server (previously defined in services.pulseaudio). Since the two PulseAudio modes are mutually exclusive anyway (maybe not strictly true, but I don't think is a good idea combining them) its nicer to be able to reuse server and ALSA configuration between them. Also the system-wide PulseAudio service has been adjusted to systemd, and a few things has been fixed (there was no alsa.conf before, for example). The bottomline is that people that was using hardware.pulseaudio before should be able to keep doing it in exactly the same way, and people that used services.pulseaudio must switch over to hardware.pulseaudio.systemWide instead.
This commit is contained in:
parent
6e20c697cd
commit
be698e93a4
|
@ -1,92 +1,148 @@
|
||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
with pkgs.lib;
|
with pkgs.lib;
|
||||||
|
with pkgs;
|
||||||
|
|
||||||
let cfg = config.hardware.pulseaudio; in
|
let
|
||||||
|
|
||||||
{
|
cfg = config.hardware.pulseaudio;
|
||||||
|
|
||||||
|
uid = config.ids.uids.pulseaudio;
|
||||||
|
gid = config.ids.gids.pulseaudio;
|
||||||
|
|
||||||
|
pulseRuntimePath = "/var/run/pulse";
|
||||||
|
|
||||||
|
# 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" ''
|
||||||
|
autospawn=${if (cfg.enable && !cfg.systemWide) then "yes" else "no"}
|
||||||
|
${optionalString (cfg.enable && !cfg.systemWide)
|
||||||
|
"daemon-binary=${cfg.package}/bin/pulseaudio"}
|
||||||
|
'';
|
||||||
|
|
||||||
|
# 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 {
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
hardware.pulseaudio.enable = mkOption {
|
hardware.pulseaudio = {
|
||||||
default = false;
|
enable = mkOption {
|
||||||
description = ''
|
default = false;
|
||||||
Whether to enable the PulseAudio sound server.
|
description = ''
|
||||||
'';
|
Whether to enable the PulseAudio sound server.
|
||||||
};
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
hardware.pulseaudio.package = mkOption {
|
systemWide = mkOption {
|
||||||
default = pkgs.pulseaudio;
|
type = types.bool;
|
||||||
example = "pkgs.pulseaudio.override { jackaudioSupport = true; }";
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
The PulseAudio derivation to use. This can be used to enable
|
If false, a PulseAudio server is launched automatically for
|
||||||
features (such as JACK support) that are not enabled in the
|
each user that tries to use the sound system. The server runs
|
||||||
default PulseAudio in Nixpkgs.
|
with user priviliges. This is the recommended and most secure
|
||||||
'';
|
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;
|
||||||
|
default = "${pulseaudio}/etc/pulse/default.pa";
|
||||||
|
description = ''
|
||||||
|
The path to the configuration the PulseAudio server
|
||||||
|
should use. By default, the "default.pa" configuration
|
||||||
|
from the PulseAudio distribution is used.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
package = mkOption {
|
||||||
|
default = pulseaudio;
|
||||||
|
example = "pulseaudio.override { jackaudioSupport = true; }";
|
||||||
|
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.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
config = mkMerge
|
config = mkMerge [
|
||||||
[ # Create pulse/client.conf even if PulseAudio is disabled so
|
{
|
||||||
# that we can disable the autospawn feature in programs that
|
environment.etc = singleton {
|
||||||
# are built with PulseAudio support (like KDE).
|
target = "pulse/client.conf";
|
||||||
{ environment.etc = singleton
|
source = clientConf;
|
||||||
{ target = "pulse/client.conf";
|
};
|
||||||
source = pkgs.writeText "client.conf"
|
}
|
||||||
''
|
|
||||||
autospawn=${if cfg.enable then "yes" else "no"}
|
|
||||||
${optionalString cfg.enable ''
|
|
||||||
daemon-binary=${cfg.package}/bin/pulseaudio
|
|
||||||
''}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
(mkIf cfg.enable {
|
(mkIf cfg.enable {
|
||||||
|
environment.systemPackages = [ cfg.package ];
|
||||||
|
|
||||||
environment.systemPackages = [ cfg.package ];
|
environment.etc = singleton {
|
||||||
|
target = "asound.conf";
|
||||||
|
source = alsaConf;
|
||||||
|
};
|
||||||
|
|
||||||
environment.etc =
|
# Allow PulseAudio to get realtime priority using rtkit.
|
||||||
[ # Write an /etc/asound.conf that causes all ALSA applications to
|
security.rtkit.enable = true;
|
||||||
# be re-routed to the PulseAudio server through ALSA's Pulse
|
})
|
||||||
# plugin.
|
|
||||||
{ target = "asound.conf";
|
|
||||||
source = pkgs.writeText "asound.conf"
|
|
||||||
''
|
|
||||||
pcm_type.pulse {
|
|
||||||
lib ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_pcm_pulse.so
|
|
||||||
}
|
|
||||||
|
|
||||||
pcm.!default {
|
(mkIf (cfg.enable && !cfg.systemWide) {
|
||||||
type pulse
|
environment.etc = singleton {
|
||||||
hint.description "Default Audio Device (via PulseAudio)"
|
target = "pulse/default.pa";
|
||||||
}
|
source = cfg.configFile;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
ctl_type.pulse {
|
(mkIf (cfg.enable && cfg.systemWide) {
|
||||||
lib ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_ctl_pulse.so
|
users.extraUsers.pulse = {
|
||||||
}
|
# For some reason, PulseAudio wants UID == GID.
|
||||||
|
uid = assert uid == gid; uid;
|
||||||
ctl.!default {
|
group = "pulse";
|
||||||
type pulse
|
extraGroups = [ "audio" ];
|
||||||
}
|
description = "PulseAudio system service user";
|
||||||
'';
|
home = pulseRuntimePath;
|
||||||
}
|
};
|
||||||
|
|
||||||
{ target = "pulse/default.pa";
|
users.extraGroups.pulse.gid = gid;
|
||||||
source = "${cfg.package}/etc/pulse/default.pa";
|
|
||||||
}
|
systemd.services.pulseaudio = {
|
||||||
|
description = "PulseAudio system-wide server";
|
||||||
{ target = "pulse/system.pa";
|
wantedBy = [ "sound.target" ];
|
||||||
source = "${cfg.package}/etc/pulse/system.pa";
|
before = [ "sound.target" ];
|
||||||
}
|
path = [ pulseaudio ];
|
||||||
];
|
environment.PULSE_RUNTIME_PATH = pulseRuntimePath;
|
||||||
|
preStart = ''
|
||||||
# Allow PulseAudio to get realtime priority using rtkit.
|
mkdir -p --mode 755 ${pulseRuntimePath}
|
||||||
security.rtkit.enable = true;
|
chown -R pulse:pulse ${pulseRuntimePath}
|
||||||
|
'';
|
||||||
})
|
script = ''
|
||||||
];
|
exec pulseaudio --system -n --file="${cfg.configFile}"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,6 @@
|
||||||
./services/audio/alsa.nix
|
./services/audio/alsa.nix
|
||||||
./services/audio/fuppes.nix
|
./services/audio/fuppes.nix
|
||||||
./services/audio/mpd.nix
|
./services/audio/mpd.nix
|
||||||
./services/audio/pulseaudio.nix
|
|
||||||
./services/backup/mysql-backup.nix
|
./services/backup/mysql-backup.nix
|
||||||
./services/backup/postgresql-backup.nix
|
./services/backup/postgresql-backup.nix
|
||||||
./services/backup/sitecopy-backup.nix
|
./services/backup/sitecopy-backup.nix
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
{ config, pkgs, ... }:
|
|
||||||
|
|
||||||
with pkgs.lib;
|
|
||||||
|
|
||||||
let
|
|
||||||
|
|
||||||
uid = config.ids.uids.pulseaudio;
|
|
||||||
gid = config.ids.gids.pulseaudio;
|
|
||||||
|
|
||||||
in
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
###### interface
|
|
||||||
|
|
||||||
options = {
|
|
||||||
|
|
||||||
services.pulseaudio = {
|
|
||||||
|
|
||||||
enable = mkOption {
|
|
||||||
default = false;
|
|
||||||
description = ''
|
|
||||||
Whether to enable the PulseAudio system-wide audio server.
|
|
||||||
Note that the documentation recommends running PulseAudio
|
|
||||||
daemons per-user rather than system-wide on desktop machines.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
logLevel = mkOption {
|
|
||||||
default = "notice";
|
|
||||||
example = "debug";
|
|
||||||
description = ''
|
|
||||||
A string denoting the log level: one of
|
|
||||||
<literal>error</literal>, <literal>warn</literal>,
|
|
||||||
<literal>notice</literal>, <literal>info</literal>,
|
|
||||||
or <literal>debug</literal>.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
###### implementation
|
|
||||||
|
|
||||||
config = mkIf config.services.pulseaudio.enable {
|
|
||||||
|
|
||||||
environment.systemPackages = [ pkgs.pulseaudio ];
|
|
||||||
|
|
||||||
users.extraUsers = singleton
|
|
||||||
{ name = "pulse";
|
|
||||||
# For some reason, PulseAudio wants UID == GID.
|
|
||||||
uid = assert uid == gid; uid;
|
|
||||||
group = "pulse";
|
|
||||||
description = "PulseAudio system-wide daemon";
|
|
||||||
home = "/var/run/pulse";
|
|
||||||
};
|
|
||||||
|
|
||||||
users.extraGroups = singleton
|
|
||||||
{ name = "pulse";
|
|
||||||
inherit gid;
|
|
||||||
};
|
|
||||||
|
|
||||||
jobs.pulseaudio =
|
|
||||||
{ description = "PulseAudio system-wide server";
|
|
||||||
|
|
||||||
startOn = "startup";
|
|
||||||
|
|
||||||
preStart =
|
|
||||||
''
|
|
||||||
test -d /var/run/pulse || \
|
|
||||||
( mkdir -p --mode 755 /var/run/pulse && \
|
|
||||||
chown pulse:pulse /var/run/pulse )
|
|
||||||
'';
|
|
||||||
|
|
||||||
exec =
|
|
||||||
''
|
|
||||||
${pkgs.pulseaudio}/bin/pulseaudio \
|
|
||||||
--system --daemonize \
|
|
||||||
--log-level="${config.services.pulseaudio.logLevel}"
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue