summary refs log tree commit diff
path: root/nixos/modules/services/desktops/pipewire/pipewire.nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2022-01-03 21:05:30 +0100
committertv <tv@krebsco.de>2022-01-04 16:07:07 +0100
commit7678a5848c057ec8298c84902b5de7213a56fdea (patch)
treedb3dc1b5ed670f18af403c3cab1297d056e0cc8c /nixos/modules/services/desktops/pipewire/pipewire.nix
parent31d923d222ebd188c90a2d5ed6d086e7d8e36bc0 (diff)
downloadnixpkgs-7678a5848c057ec8298c84902b5de7213a56fdea.tar
nixpkgs-7678a5848c057ec8298c84902b5de7213a56fdea.tar.gz
nixpkgs-7678a5848c057ec8298c84902b5de7213a56fdea.tar.bz2
nixpkgs-7678a5848c057ec8298c84902b5de7213a56fdea.tar.lz
nixpkgs-7678a5848c057ec8298c84902b5de7213a56fdea.tar.xz
nixpkgs-7678a5848c057ec8298c84902b5de7213a56fdea.tar.zst
nixpkgs-7678a5848c057ec8298c84902b5de7213a56fdea.zip
nixos/pipewire: add systemWide option
Diffstat (limited to 'nixos/modules/services/desktops/pipewire/pipewire.nix')
-rw-r--r--nixos/modules/services/desktops/pipewire/pipewire.nix44
1 files changed, 43 insertions, 1 deletions
diff --git a/nixos/modules/services/desktops/pipewire/pipewire.nix b/nixos/modules/services/desktops/pipewire/pipewire.nix
index 55755ecd645..2e2fe464d81 100644
--- a/nixos/modules/services/desktops/pipewire/pipewire.nix
+++ b/nixos/modules/services/desktops/pipewire/pipewire.nix
@@ -123,6 +123,22 @@ in {
       pulse = {
         enable = mkEnableOption "PulseAudio server emulation";
       };
+
+      systemWide = lib.mkOption {
+        type = lib.types.bool;
+        default = false;
+        description = ''
+          If true, a system-wide PipeWire service and socket is enabled
+          allowing all users in the "pipewire" group to use it simultaneously.
+          If false, then user units are used instead, restricting access to
+          only one user.
+
+          Enabling system-wide PipeWire is however not recommended and disabled
+          by default according to
+          https://github.com/PipeWire/pipewire/blob/master/NEWS
+        '';
+      };
+
     };
   };
 
@@ -148,9 +164,20 @@ in {
 
     # PipeWire depends on DBUS but doesn't list it. Without this booting
     # into a terminal results in the service crashing with an error.
+    systemd.services.pipewire.bindsTo = [ "dbus.service" ];
+    systemd.user.services.pipewire.bindsTo = [ "dbus.service" ];
+
+    # Enable either system or user units.  Note that for pipewire-pulse there
+    # are only user units, which work in both cases.
+    systemd.sockets.pipewire.enable = cfg.systemWide;
+    systemd.services.pipewire.enable = cfg.systemWide;
+    systemd.user.sockets.pipewire.enable = !cfg.systemWide;
+    systemd.user.services.pipewire.enable = !cfg.systemWide;
+
+    systemd.sockets.pipewire.wantedBy = lib.mkIf cfg.socketActivation [ "sockets.target" ];
     systemd.user.sockets.pipewire.wantedBy = lib.mkIf cfg.socketActivation [ "sockets.target" ];
     systemd.user.sockets.pipewire-pulse.wantedBy = lib.mkIf (cfg.socketActivation && cfg.pulse.enable) ["sockets.target"];
-    systemd.user.services.pipewire.bindsTo = [ "dbus.service" ];
+
     services.udev.packages = [ cfg.package ];
 
     # If any paths are updated here they must also be updated in the package test.
@@ -194,7 +221,22 @@ in {
     environment.sessionVariables.LD_LIBRARY_PATH =
       lib.optional cfg.jack.enable "${cfg.package.jack}/lib";
 
+    users = lib.mkIf cfg.systemWide {
+      users.pipewire = {
+        uid = config.ids.uids.pipewire;
+        group = "pipewire";
+        extraGroups = [
+          "audio"
+          "video"
+        ] ++ lib.optional config.security.rtkit.enable "rtkit";
+        description = "Pipewire system service user";
+        isSystemUser = true;
+      };
+      groups.pipewire.gid = config.ids.gids.pipewire;
+    };
+
     # https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/464#note_723554
+    systemd.services.pipewire.environment."PIPEWIRE_LINK_PASSIVE" = "1";
     systemd.user.services.pipewire.environment."PIPEWIRE_LINK_PASSIVE" = "1";
   };
 }