summaryrefslogtreecommitdiffstats
path: root/tv/2configs/pulse.nix
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2015-11-27 21:44:47 +0100
committermakefu <github@syntax-fehler.de>2015-11-27 21:44:47 +0100
commit74ebb5b01c85234f0f9e25428dc042b02caa6584 (patch)
tree7c0d4dad6ddcc300efc80c31fc33de03b6724183 /tv/2configs/pulse.nix
parent42347456453b864d83d26ec952cfb770095d0a81 (diff)
parentd0913afc37d7da6c22d97b7da3c687d494567041 (diff)
Merge remote-tracking branch 'cd/master'
Diffstat (limited to 'tv/2configs/pulse.nix')
-rw-r--r--tv/2configs/pulse.nix83
1 files changed, 83 insertions, 0 deletions
diff --git a/tv/2configs/pulse.nix b/tv/2configs/pulse.nix
new file mode 100644
index 000000000..0ddc52789
--- /dev/null
+++ b/tv/2configs/pulse.nix
@@ -0,0 +1,83 @@
+{ config, lib, pkgs, ... }:
+
+let
+ pkg = pkgs.pulseaudioLight;
+ runDir = "/run/pulse";
+
+ alsaConf = pkgs.writeText "asound.conf" ''
+ ctl_type.pulse {
+ libs.native = ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_ctl_pulse.so;
+ }
+ pcm_type.pulse {
+ libs.native = ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_pcm_pulse.so;
+ }
+ ctl.!default {
+ type pulse
+ }
+ pcm.!default {
+ type pulse
+ }
+ '';
+
+ clientConf = pkgs.writeText "client.conf" ''
+ autospawn=no
+ default-server = unix:${runDir}/socket
+ '';
+
+ configFile = pkgs.writeText "default.pa" ''
+ .include ${pkg}/etc/pulse/default.pa
+ load-module ${toString [
+ "module-native-protocol-unix"
+ "auth-anonymous=1"
+ "socket=${runDir}/socket"
+ ]}
+ '';
+in
+
+{
+ systemd.tmpfiles.rules = [
+ "d ${runDir} 0750 pulse pulse - -"
+ "d ${runDir}/home 0700 pulse pulse - -"
+ ];
+
+ system.activationScripts.pulseaudio-hack = ''
+ ln -fns ${clientConf} /etc/pulse/client.conf
+ '';
+
+ environment = {
+ etc = {
+ "asound.conf".source = alsaConf;
+ #"pulse/client.conf" = lib.mkForce { source = clientConf; };
+ "pulse/default.pa".source = configFile;
+ };
+ systemPackages = [ pkg ];
+ };
+
+ # Allow PulseAudio to get realtime priority using rtkit.
+ security.rtkit.enable = true;
+
+ systemd.services.pulse = {
+ wantedBy = [ "sound.target" ];
+ before = [ "sound.target" ];
+ environment = {
+ PULSE_RUNTIME_PATH = "${runDir}/home";
+ #DISPLAY = ":${toString config.services.xserver.display}";
+ };
+ serviceConfig = {
+ ExecStart = "${pkg}/bin/pulseaudio";
+ User = "pulse";
+ };
+ };
+
+ users = let
+ id = 3768151709; # genid pulse
+ in {
+ groups.pulse.gid = id;
+ users.pulse = {
+ uid = id;
+ group = "pulse";
+ extraGroups = [ "audio" ];
+ home = "${runDir}/home";
+ };
+ };
+}