pulseaudio module: Use pid-file for system-wide daemon, add loglevel option
This commit is contained in:
parent
0f9499887e
commit
cfa5b5778c
@ -7,18 +7,20 @@ let
|
|||||||
|
|
||||||
cfg = config.hardware.pulseaudio;
|
cfg = config.hardware.pulseaudio;
|
||||||
|
|
||||||
|
systemWide = cfg.enable && cfg.systemWide;
|
||||||
|
nonSystemWide = cfg.enable && !cfg.systemWide;
|
||||||
|
|
||||||
uid = config.ids.uids.pulseaudio;
|
uid = config.ids.uids.pulseaudio;
|
||||||
gid = config.ids.gids.pulseaudio;
|
gid = config.ids.gids.pulseaudio;
|
||||||
|
|
||||||
pulseRuntimePath = "/var/run/pulse";
|
stateDir = "/run/pulse";
|
||||||
|
|
||||||
# Create pulse/client.conf even if PulseAudio is disabled so
|
# Create pulse/client.conf even if PulseAudio is disabled so
|
||||||
# that we can disable the autospawn feature in programs that
|
# that we can disable the autospawn feature in programs that
|
||||||
# are built with PulseAudio support (like KDE).
|
# are built with PulseAudio support (like KDE).
|
||||||
clientConf = writeText "client.conf" ''
|
clientConf = writeText "client.conf" ''
|
||||||
autospawn=${if (cfg.enable && !cfg.systemWide) then "yes" else "no"}
|
autospawn=${if nonSystemWide then "yes" else "no"}
|
||||||
${optionalString (cfg.enable && !cfg.systemWide)
|
${optionalString nonSystemWide "daemon-binary=${cfg.package}/bin/pulseaudio"}
|
||||||
"daemon-binary=${cfg.package}/bin/pulseaudio"}
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Write an /etc/asound.conf that causes all ALSA applications to
|
# Write an /etc/asound.conf that causes all ALSA applications to
|
||||||
@ -68,7 +70,7 @@ in {
|
|||||||
|
|
||||||
configFile = mkOption {
|
configFile = mkOption {
|
||||||
type = types.uniq types.path;
|
type = types.uniq types.path;
|
||||||
default = "${pulseaudio}/etc/pulse/default.pa";
|
default = "${cfg.package}/etc/pulse/default.pa";
|
||||||
description = ''
|
description = ''
|
||||||
The path to the configuration the PulseAudio server
|
The path to the configuration the PulseAudio server
|
||||||
should use. By default, the "default.pa" configuration
|
should use. By default, the "default.pa" configuration
|
||||||
@ -86,6 +88,17 @@ in {
|
|||||||
default PulseAudio in Nixpkgs.
|
default PulseAudio in Nixpkgs.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
daemon = {
|
||||||
|
logLevel = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "notice";
|
||||||
|
description = ''
|
||||||
|
The log level that the system-wide pulseaudio daemon should use,
|
||||||
|
if activated.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -111,21 +124,20 @@ in {
|
|||||||
security.rtkit.enable = true;
|
security.rtkit.enable = true;
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf (cfg.enable && !cfg.systemWide) {
|
(mkIf nonSystemWide {
|
||||||
environment.etc = singleton {
|
environment.etc = singleton {
|
||||||
target = "pulse/default.pa";
|
target = "pulse/default.pa";
|
||||||
source = cfg.configFile;
|
source = cfg.configFile;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf (cfg.enable && cfg.systemWide) {
|
(mkIf systemWide {
|
||||||
users.extraUsers.pulse = {
|
users.extraUsers.pulse = {
|
||||||
# For some reason, PulseAudio wants UID == GID.
|
# For some reason, PulseAudio wants UID == GID.
|
||||||
uid = assert uid == gid; uid;
|
uid = assert uid == gid; uid;
|
||||||
group = "pulse";
|
group = "pulse";
|
||||||
extraGroups = [ "audio" ];
|
extraGroups = [ "audio" ];
|
||||||
description = "PulseAudio system service user";
|
description = "PulseAudio system service user";
|
||||||
home = pulseRuntimePath;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
users.extraGroups.pulse.gid = gid;
|
users.extraGroups.pulse.gid = gid;
|
||||||
@ -134,15 +146,15 @@ in {
|
|||||||
description = "PulseAudio System-Wide Server";
|
description = "PulseAudio System-Wide Server";
|
||||||
wantedBy = [ "sound.target" ];
|
wantedBy = [ "sound.target" ];
|
||||||
before = [ "sound.target" ];
|
before = [ "sound.target" ];
|
||||||
path = [ cfg.package ];
|
environment.PULSE_RUNTIME_PATH = stateDir;
|
||||||
environment.PULSE_RUNTIME_PATH = pulseRuntimePath;
|
|
||||||
preStart = ''
|
preStart = ''
|
||||||
mkdir -p --mode 755 ${pulseRuntimePath}
|
mkdir -p --mode 755 ${stateDir}
|
||||||
chown -R pulse:pulse ${pulseRuntimePath}
|
chown -R pulse:pulse ${stateDir}
|
||||||
'';
|
|
||||||
script = ''
|
|
||||||
exec pulseaudio --system -n --file="${cfg.configFile}"
|
|
||||||
'';
|
'';
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = "${cfg.package}/bin/pulseaudio -D --log-level=${cfg.daemon.logLevel} --system --use-pid-file -n --file=${cfg.configFile}";
|
||||||
|
PIDFile = "${stateDir}/pid";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user