From ca3f82e2587c22d69150639b1eb6703dcc4515e2 Mon Sep 17 00:00:00 2001 From: Peter Hoeg Date: Sat, 2 Apr 2016 23:05:21 +0800 Subject: pulseaudio nixos module: run as systemd user service instead Most of the desktop environments will spawn pulseaudio, but we can instead simply run it as a systemd service instead. This patch also makes the system wide service run in foreground as recommended by the systemd projects and allows it to use sd_notify to signal ready instead of reading a pid written to a file. It is now also restarted on failure. The user version has been tested with KDE and works fine there. The system-wide version runs, but I haven't actually used it and upstream does not recommend running in this mode. --- nixos/modules/config/pulseaudio.nix | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'nixos/modules/config/pulseaudio.nix') diff --git a/nixos/modules/config/pulseaudio.nix b/nixos/modules/config/pulseaudio.nix index 179e826ba05..8b4ad796d0d 100644 --- a/nixos/modules/config/pulseaudio.nix +++ b/nixos/modules/config/pulseaudio.nix @@ -150,6 +150,29 @@ in { target = "pulse/default.pa"; source = cfg.configFile; }; + + systemd.user = { + services.pulseaudio = { + description = "PulseAudio Server"; + # NixOS doesn't support "Also" so we bring it in manually + wantedBy = [ "default.target" ]; + serviceConfig = { + Type = "notify"; + ExecStart = "${cfg.package}/bin/pulseaudio --daemonize=no"; + Restart = "on-failure"; + }; + }; + + sockets.pulseaudio = { + description = "PulseAudio Socket"; + wantedBy = [ "sockets.target" ]; + socketConfig = { + Priority = 6; + Backlog = 5; + ListenStream = "%t/pulse/native"; + }; + }; + }; }) (mkIf systemWide { @@ -171,8 +194,9 @@ in { before = [ "sound.target" ]; environment.PULSE_RUNTIME_PATH = stateDir; serviceConfig = { - ExecStart = "${cfg.package}/bin/pulseaudio -D --log-level=${cfg.daemon.logLevel} --system --use-pid-file -n --file=${cfg.configFile}"; - PIDFile = "${stateDir}/pid"; + Type = "notify"; + ExecStart = "${cfg.package}/bin/pulseaudio --daemonize=no --log-level=${cfg.daemon.logLevel} --system -n --file=${cfg.configFile}"; + Restart = "on-failure"; }; }; }) -- cgit 1.4.1