From cfa5b5778c3318ccb2f6784632a37bbd847d3aa7 Mon Sep 17 00:00:00 2001 From: Rickard Nilsson Date: Mon, 21 Apr 2014 11:50:49 +0200 Subject: pulseaudio module: Use pid-file for system-wide daemon, add loglevel option --- nixos/modules/config/pulseaudio.nix | 42 ++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'nixos/modules/config/pulseaudio.nix') diff --git a/nixos/modules/config/pulseaudio.nix b/nixos/modules/config/pulseaudio.nix index eedc4ca2b2f2..9802b898a5d8 100644 --- a/nixos/modules/config/pulseaudio.nix +++ b/nixos/modules/config/pulseaudio.nix @@ -7,18 +7,20 @@ let cfg = config.hardware.pulseaudio; + systemWide = cfg.enable && cfg.systemWide; + nonSystemWide = cfg.enable && !cfg.systemWide; + uid = config.ids.uids.pulseaudio; gid = config.ids.gids.pulseaudio; - pulseRuntimePath = "/var/run/pulse"; + stateDir = "/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"} + autospawn=${if nonSystemWide then "yes" else "no"} + ${optionalString nonSystemWide "daemon-binary=${cfg.package}/bin/pulseaudio"} ''; # Write an /etc/asound.conf that causes all ALSA applications to @@ -68,7 +70,7 @@ in { configFile = mkOption { type = types.uniq types.path; - default = "${pulseaudio}/etc/pulse/default.pa"; + default = "${cfg.package}/etc/pulse/default.pa"; description = '' The path to the configuration the PulseAudio server should use. By default, the "default.pa" configuration @@ -86,6 +88,17 @@ in { 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; }) - (mkIf (cfg.enable && !cfg.systemWide) { + (mkIf nonSystemWide { environment.etc = singleton { target = "pulse/default.pa"; source = cfg.configFile; }; }) - (mkIf (cfg.enable && cfg.systemWide) { + (mkIf systemWide { users.extraUsers.pulse = { # For some reason, PulseAudio wants UID == GID. uid = assert uid == gid; uid; group = "pulse"; extraGroups = [ "audio" ]; description = "PulseAudio system service user"; - home = pulseRuntimePath; }; users.extraGroups.pulse.gid = gid; @@ -134,15 +146,15 @@ in { description = "PulseAudio System-Wide Server"; wantedBy = [ "sound.target" ]; before = [ "sound.target" ]; - path = [ cfg.package ]; - environment.PULSE_RUNTIME_PATH = pulseRuntimePath; + environment.PULSE_RUNTIME_PATH = stateDir; preStart = '' - mkdir -p --mode 755 ${pulseRuntimePath} - chown -R pulse:pulse ${pulseRuntimePath} - ''; - script = '' - exec pulseaudio --system -n --file="${cfg.configFile}" + mkdir -p --mode 755 ${stateDir} + chown -R pulse:pulse ${stateDir} ''; + serviceConfig = { + ExecStart = "${cfg.package}/bin/pulseaudio -D --log-level=${cfg.daemon.logLevel} --system --use-pid-file -n --file=${cfg.configFile}"; + PIDFile = "${stateDir}/pid"; + }; }; }) ]; -- cgit 1.4.1