diff options
author | Jörg Thalheim <Mic92@users.noreply.github.com> | 2022-01-05 21:33:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-05 21:33:07 +0000 |
commit | 989238ec03360b6a2efc09f3ac969cd34a1d85ad (patch) | |
tree | 47f9505705106def6f69b38578954f4c8981e6aa /nixos/modules | |
parent | 06509d51b4e43c081ae8e5162d2805b53d3176b8 (diff) | |
parent | 7678a5848c057ec8298c84902b5de7213a56fdea (diff) | |
download | nixpkgs-989238ec03360b6a2efc09f3ac969cd34a1d85ad.tar nixpkgs-989238ec03360b6a2efc09f3ac969cd34a1d85ad.tar.gz nixpkgs-989238ec03360b6a2efc09f3ac969cd34a1d85ad.tar.bz2 nixpkgs-989238ec03360b6a2efc09f3ac969cd34a1d85ad.tar.lz nixpkgs-989238ec03360b6a2efc09f3ac969cd34a1d85ad.tar.xz nixpkgs-989238ec03360b6a2efc09f3ac969cd34a1d85ad.tar.zst nixpkgs-989238ec03360b6a2efc09f3ac969cd34a1d85ad.zip |
Merge pull request #153426 from 4z3/systemwide-pipewire
nixos/pipewire: add systemWide option
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/misc/ids.nix | 2 | ||||
-rw-r--r-- | nixos/modules/services/desktops/pipewire/pipewire-media-session.nix | 6 | ||||
-rw-r--r-- | nixos/modules/services/desktops/pipewire/pipewire.nix | 44 |
3 files changed, 51 insertions, 1 deletions
diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix index d7fc9ca87d4..61e7a6a8fc3 100644 --- a/nixos/modules/misc/ids.nix +++ b/nixos/modules/misc/ids.nix @@ -352,6 +352,7 @@ in moonraker = 320; distcc = 321; webdav = 322; + pipewire = 323; # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! @@ -658,6 +659,7 @@ in moonraker = 320; distcc = 321; webdav = 322; + pipewire = 323; # When adding a gid, make sure it doesn't match an existing # uid. Users and groups with the same name should have equal diff --git a/nixos/modules/services/desktops/pipewire/pipewire-media-session.nix b/nixos/modules/services/desktops/pipewire/pipewire-media-session.nix index 803438b6f7e..f7a03a4a3ea 100644 --- a/nixos/modules/services/desktops/pipewire/pipewire-media-session.nix +++ b/nixos/modules/services/desktops/pipewire/pipewire-media-session.nix @@ -96,6 +96,12 @@ in { config = mkIf cfg.enable { environment.systemPackages = [ cfg.package ]; systemd.packages = [ cfg.package ]; + + # Enable either system or user units. + systemd.services.pipewire-media-session.enable = config.services.pipewire.systemWide; + systemd.user.services.pipewire-media-session.enable = !config.services.pipewire.systemWide; + + systemd.services.pipewire-media-session.wantedBy = [ "pipewire.service" ]; systemd.user.services.pipewire-media-session.wantedBy = [ "pipewire.service" ]; environment.etc."pipewire/media-session.d/media-session.conf" = { diff --git a/nixos/modules/services/desktops/pipewire/pipewire.nix b/nixos/modules/services/desktops/pipewire/pipewire.nix index 372b4785f18..c3cfd46e61c 100644 --- a/nixos/modules/services/desktops/pipewire/pipewire.nix +++ b/nixos/modules/services/desktops/pipewire/pipewire.nix @@ -125,6 +125,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 + ''; + }; + }; }; @@ -150,9 +166,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. @@ -196,7 +223,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"; }; } |