summary refs log tree commit diff
path: root/nixos/modules/config/pulseaudio.nix
diff options
context:
space:
mode:
authorPeter Hoeg <peter@speartail.com>2016-04-02 23:05:21 +0800
committerPeter Hoeg <peter@speartail.com>2016-04-02 23:18:22 +0800
commitca3f82e2587c22d69150639b1eb6703dcc4515e2 (patch)
treee169576b60417d0f36679a4cbd3ed76fb9466f54 /nixos/modules/config/pulseaudio.nix
parent32b7b0009f168cb7e020d297c2f336ef352e9ec1 (diff)
downloadnixpkgs-ca3f82e2587c22d69150639b1eb6703dcc4515e2.tar
nixpkgs-ca3f82e2587c22d69150639b1eb6703dcc4515e2.tar.gz
nixpkgs-ca3f82e2587c22d69150639b1eb6703dcc4515e2.tar.bz2
nixpkgs-ca3f82e2587c22d69150639b1eb6703dcc4515e2.tar.lz
nixpkgs-ca3f82e2587c22d69150639b1eb6703dcc4515e2.tar.xz
nixpkgs-ca3f82e2587c22d69150639b1eb6703dcc4515e2.tar.zst
nixpkgs-ca3f82e2587c22d69150639b1eb6703dcc4515e2.zip
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.
Diffstat (limited to 'nixos/modules/config/pulseaudio.nix')
-rw-r--r--nixos/modules/config/pulseaudio.nix28
1 files changed, 26 insertions, 2 deletions
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";
         };
       };
     })