Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

System wide pipewire with openrc

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
12 posts • Page 1 of 1
Author
Message
mazes80
n00b
n00b
User avatar
Posts: 13
Joined: Thu Feb 24, 2011 8:01 am
Location: toulouse - france

System wide pipewire with openrc

  • Quote

Post by mazes80 » Thu Jul 07, 2022 9:35 pm

Required packages

Code: Select all

emerge -C media-sound/jack-audio-connection-kit
USE="extra jack-sdk pipewire-alsa" emerge media-video/pipewire # extra is not mandatory
emerge acct-group/pipewire acct-user/pipewire

New files

/etc/init.d/pipewire

Code: Select all

#!/sbin/openrc-run
# Copyright 2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

PIPEWIRE_RUNTIME_DIR="/tmp/pipewire"
name="pipewire daemon"
description="Share sound and videos"
command=/usr/bin/pipewire
command_args="${pipewire_args}"
command_background=yes
command_user="pipewire:pipewire"
pidfile="${PIPEWIRE_RUNTIME_DIR}/pipewire.pid"

depend() {
        use alsasound pulseaudio
}

start_pre() {
       # The next 5 lines feels like it should be replaced by:
       # checkpath -d -m 2775 -o "${command_user}" "${PIPEWIRE_RUNTIME_DIR}"
       # Optionally replace -d with -D to clean out the directory (possible security thoughts)
        if [[ ! -e ${PIPEWIRE_RUNTIME_DIR} ]]; then
                mkdir ${PIPEWIRE_RUNTIME_DIR}
        fi
        chmod -R g+ws ${PIPEWIRE_RUNTIME_DIR}
        chown -R pipewire:pipewire ${PIPEWIRE_RUNTIME_DIR}
        export PIPEWIRE_RUNTIME_DIR
}

start_post() {
        einfo "Wait for the pipewire socket to be ready"
        sleep 3
        find ${PIPEWIRE_RUNTIME_DIR} -type s -exec chmod g+w '{}' ';'
        einfo "Socket file: $(find ${PIPEWIRE_RUNTIME_DIR} -type s)"
}
Thanks grknight for the review

/etc/X11/xinit/xinitrc.d/99-pipewire

Code: Select all

#!/bin/bash

if test -z "${XDG_RUNTIME_DIR}"; then
        export XDG_RUNTIME_DIR="$(mktemp -d /tmp/$(id -u)-runtime-dir.XXX)"
else
        export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR}"
fi
export PIPEWIRE_RUNTIME_DIR="/tmp/pipewire"
Tweaked files

Code: Select all

mkdir /etc/pipewire
cp /usr/share/pipewire/pipewire.conf /etc/pipewire/
sed -i '/path.*pipewire-media-session/{s/#//;s/pipewire-media-session/wireplumber/}'
Disable D-Bus

Code: Select all

sed -i '/with-logind/s/true/false/'           /etc/wireplumber/bluetooth.lua.d/50-bluez-config.lua
sed -i '/alsa.reserve/s/true/false/'          /etc/wireplumber/main.lua.d/50-alsa-config.lua
sed -i '/enable-flatpak-portal/s/true/false/' /etc/wireplumber/main.lua.d/50-default-access-config.lua
System settings

Start pipewire at boot

Code: Select all

rc-update add pipewire default
Add all user who can use sound to pipewire group

Code: Select all

usermod -a -G pipewire user1
usermod -a -G pipewire user2
usermod -a -G pipewire mpd
Extra step
You may also need to add to your .bashrc

Code: Select all

export PIPEWIRE_RUNTIME_DIR="/tmp/pipewire"
Restart your graphical sessions (wayland not covered here)

MPD
Set output as this in /etc/mpd.conf

Code: Select all

audio_output {
        type            "pipewire"
        name            "pipewire-0"
}
/etc/conf.d/mpd

Code: Select all

export PIPEWIRE_RUNTIME_DIR="/tmp/pipewire"
Last edited by mazes80 on Mon Sep 04, 2023 10:19 am, edited 2 times in total.
Top
grknight
Retired Dev
Retired Dev
Posts: 2560
Joined: Fri Feb 20, 2015 9:36 pm

Re: System wide pipewire with openrc

  • Quote

Post by grknight » Fri Jul 08, 2022 12:46 pm

I don't know if it is right or not, but this file should be modernized a bit:
/etc/init.d/pipewire

Code: Select all

#!/sbin/openrc-run
# Copyright 2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

PIPEWIRE_RUNTIME_DIR="/tmp/pipewire"
name="pipewire daemon"
description="Share sound and videos"
command=/usr/bin/pipewire
command_args="${pipewire_args}"
command_background=yes
command_user="pipewire:pipewire"
pidfile="${PIPEWIRE_RUNTIME_DIR}/pipewire.pid"

depend() {
        use alsasound pulseaudio
}

start_pre() {
       # The next 5 lines feels like it should be replaced by:
       # checkpath -d -m 2775 -o "${command_user}" "${PIPEWIRE_RUNTIME_DIR}"
       # Optionally replace -d with -D to clean out the directory (possible security thoughts)
        if [[ ! -e ${PIPEWIRE_RUNTIME_DIR} ]]; then
                mkdir ${PIPEWIRE_RUNTIME_DIR}
        fi
        chmod -R g+ws ${PIPEWIRE_RUNTIME_DIR}
        chown -R pipewire:pipewire ${PIPEWIRE_RUNTIME_DIR}
        export PIPEWIRE_RUNTIME_DIR
}

start_post() {
        einfo "Wait for the pipewire socket to be ready"
        sleep 3
        find ${PIPEWIRE_RUNTIME_DIR} -type s -exec chmod g+w '{}' ';'
        einfo "Socket file: $(find ${PIPEWIRE_RUNTIME_DIR} -type s)"
}
Top
acidrums4
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 148
Joined: Thu Feb 05, 2009 11:22 pm
Location: Al otro lado del monitor

Re: System wide pipewire with openrc

  • Quote

Post by acidrums4 » Thu Nov 17, 2022 2:31 pm

mazes80 wrote: Add all user who can use sound to pipewire group

Code: Select all

usermod -a -G user1
usermod -a -G user2
usermod -a -G mpd
Not sure if it's worth noting that when issuing these commands, the pipewire group should precede the usernames, something like

Code: Select all

usermod -a -G pipewire mpd
That will add mpd user to the pipewire group.

However, this was the only thing that let me use mpd as its own user with pipewire. Thank you so much!
Top
L29Ah
n00b
n00b
Posts: 17
Joined: Mon Oct 18, 2010 6:41 pm

  • Quote

Post by L29Ah » Sat Aug 26, 2023 3:15 pm

Any plans on adding this to the media-video/pipewire ebuild (perhaps behind an USE flag)?
Top
Ralphred
l33t
l33t
Posts: 822
Joined: Tue Dec 31, 2013 11:52 am

Re: System wide pipewire with openrc

  • Quote

Post by Ralphred » Sat Aug 26, 2023 5:29 pm

mazes80 wrote:Known issues: qjackctl will refuse to run for multiple users at the same time as the socket name seems hardcoded
qjackctl does that with a system wide jackd too, I wouldn't consider it an exclusive pipewire issue. Are you exporting JACK_PROMISCUOUS_SERVER?
Top
mazes80
n00b
n00b
User avatar
Posts: 13
Joined: Thu Feb 24, 2011 8:01 am
Location: toulouse - france

Re: System wide pipewire with openrc

  • Quote

Post by mazes80 » Mon Sep 04, 2023 10:26 am

Ralphred wrote:
mazes80 wrote:Known issues: qjackctl will refuse to run for multiple users at the same time as the socket name seems hardcoded
qjackctl does that with a system wide jackd too, I wouldn't consider it an exclusive pipewire issue. Are you exporting JACK_PROMISCUOUS_SERVER?
qjackctl and qpwgraph created one socket named: /tmp/software@hostname, if you tried to launch it in another session an error was thrown as socket already existed.
I submitted one PR that changed the socket name to /tmp/user:software@hostname, so every user can launch 1 instance of those softwares.
Top
mwhitlock
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 89
Joined: Mon Aug 07, 2006 10:52 am
Location: New Hampshire, USA
Contact:
Contact mwhitlock
Website

  • Quote

Post by mwhitlock » Mon Dec 30, 2024 12:51 am

I didn't need media-sound/jack-audio-connection-kit. It was sufficient to install media-video/pipewire, media-video/wireplumber, and acct-user/pipewire.

I cleaned up the init scripts to remove some extraneous cruft, to move the runtime dir beneath /run, and to allow the user:group to be overridden…

/etc/init.d/pipewire

Code: Select all

#!/sbin/openrc-run

: ${PIPEWIRE_RUNTIME_DIR:=/run/pipewire}
export PIPEWIRE_RUNTIME_DIR

name="PipeWire daemon"
description="Facilitates sharing of multimedia content between devices and applications"
command="/usr/bin/pipewire"
command_background="true"
command_user="${PIPEWIRE_USER:-pipewire}:${PIPEWIRE_GROUP:-pipewire}"
directory="${PIPEWIRE_RUNTIME_DIR}"
pidfile="${PIPEWIRE_RUNTIME_DIR}/${RC_SVCNAME}.pid"
umask="0002"

start_pre() {
	checkpath -d -m0750 -o "${command_user}" -- "${PIPEWIRE_RUNTIME_DIR}"
}
/etc/init.d/wireplumber

Code: Select all

#!/sbin/openrc-run

: ${PIPEWIRE_RUNTIME_DIR:=/run/pipewire}
export PIPEWIRE_RUNTIME_DIR

: ${XDG_STATE_HOME:=${PIPEWIRE_RUNTIME_DIR}/state}
export XDG_STATE_HOME

name="WirePlumber session manager"
description="Session and policy manager for PipeWire"
command="/usr/bin/wireplumber"
command_background="true"
command_user="${PIPEWIRE_USER:-pipewire}:${PIPEWIRE_GROUP:-pipewire}"
directory="${PIPEWIRE_RUNTIME_DIR}"
pidfile="${PIPEWIRE_RUNTIME_DIR}/${RC_SVCNAME}.pid"

depend() {
	need pipewire
	use dev-settle
	after alsasound modules
}
You probably won't need this, but on my Raspberry Pi 1, I also needed to increase the default clock quantum to avoid sporadic audio glitches:

/etc/pipewire/pipewire.conf.d/local.conf

Code: Select all

context.properties = {
	default.clock.quantum = 2048
}
Note: I did not need to set PIPEWIRE_RUNTIME_DIR in my user profile, as MPV's pipewire audio output module apparently finds the system-wide PipeWire socket just fine without being told explicitly where to look for it. Presumably the same would be true for any client using the PipeWire client library, but YMMV.
Top
L29Ah
n00b
n00b
Posts: 17
Joined: Mon Oct 18, 2010 6:41 pm

  • Quote

Post by L29Ah » Mon Dec 30, 2024 12:54 am

mwhitlock wrote:Note: I did not need to set PIPEWIRE_RUNTIME_DIR in my user profile, as MPV's pipewire audio output module apparently finds the system-wide PipeWire socket just fine without being told explicitly where to look for it. Presumably the same would be true for any client using the PipeWire client library, but YMMV.
Thanks for your work. Do i get it right you didn't need any adjustments for the default configuration of PipeWire itself?
Do ALSA and PulseAudio frontends of PipeWire work for the users in your setup?
Top
mwhitlock
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 89
Joined: Mon Aug 07, 2006 10:52 am
Location: New Hampshire, USA
Contact:
Contact mwhitlock
Website

  • Quote

Post by mwhitlock » Mon Dec 30, 2024 1:36 am

L29Ah wrote:Do i get it right you didn't need any adjustments for the default configuration of PipeWire itself?
The only thing I changed about PipeWire's configuration was to increase the default clock quantum. Everything else is just as Portage installed it. I did add the pipewire and wireplumber services to my default runlevel, and I added my user to the pipewire group.
L29Ah wrote:Do ALSA and PulseAudio frontends of PipeWire work for the users in your setup?
I don't know. I am running this on a headless Raspberry Pi in my home theater rack, which is why I couldn't use PipeWire in the usual way — I don't start any desktop session, and there is no D-Bus (system or session) and no elogind. I can say that it works great for running MPV from the command line in SSH, just had to set ao=pipewire.

Code: Select all

[ao] Trying audio driver 'pipewire'
[ao/pipewire] requested format: 44100 Hz, stereo channels, s16p
[ao/pipewire] Headers version: 1.2.6
[ao/pipewire] Library version: 1.2.6
[ao/pipewire] Core user: pipewire
[ao/pipewire] Core host: hifipi
[ao/pipewire] Core version: 1.2.6
[ao/pipewire] Core name: pipewire-0
[ao/pipewire] using soft-buffer of 132300 samples.
AO: [pipewire] 44100Hz stereo 2ch s16p
[cplayer] AO: Description: PipeWire audio output
The only real reason I'm trying out PipeWire at all is that my stupid AV preprocessor fades in the audio after even the briefest moment of digital silence in the HDMI audio stream, and that causes the beginning of every music track to fade in and even causes some drop-outs in the middle of some tracks that contain digital silence. There's supposed to be a way to make PipeWire constantly output an inaudible noise to trick such stupid receivers into staying locked on the PCM clock. I haven't gotten that far yet, though.
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Mon Jan 27, 2025 9:26 pm

I've been using pipewire for a while, and although I was mostly happy with it, I did miss my system-wide sound.
Gotta say, good job figuring out how to fix it. Thanks!

Moving from a working single-user pipewire to system-wide took adding init scripts for pipewire and wireplumber and removing gentoo-pipewire-launcher from xdg's autostart.
That's it, no other configuration changes, no sourcing variables into user session etc.
Just set pipewire runtime dir and umask for sockets to be created under /run/pipewire and with with g+rw permissions (I used umask="07"). I'm not sure how do applications know where to look for sockets, but they do find them just fine.
I don't use pulseaudio, so I skipped setting up the proxy completely.

Results:
* my audio works (using either ALSA or JACK)
* mpd launched as mpd:pipewire works (ALSA output with all optional parameters skipped)
* applications launched as a restricted user with pipewire group work (I'm pretty sure firefox uses alsa, mpv connected using jack), though I had to remove it from audio group to prevent direct access to hardware which conflicted with pipewire
* easyeffects work
* applications using portaudio work (they don't have descriptive names in patchbay, but the sound works)
* Bonus: bluetooth speaker works. There is no need to remove related configs.

Code: Select all

media-video/pipewire-1.2.7-r1::gentoo was built with the following:
USE="X bluetooth dbus elogind extra ffmpeg jack-sdk lv2 modemmanager readline sound-server ssl v4l zeroconf -doc -echo-cancel -flatpak -gsettings -gstreamer -ieee1394 -jack-client -liblc3 -man -pipewire-alsa -roc (-selinux) (-system-service) -systemd -test"
Make Pipewire a system service
Top
pietinger
Administrator
Administrator
Posts: 6620
Joined: Tue Oct 17, 2006 5:11 pm
Location: Bavaria

  • Quote

Post by pietinger » Tue Jan 28, 2025 1:15 pm

Moved from Multimedia to Documentation, Tips & Tricks.
https://wiki.gentoo.org/wiki/User:Pietinger --> https://wiki.gentoo.org/wiki/User:Pieti ... _at_Gentoo
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Wed Jun 25, 2025 3:01 pm

Update time!
I revisited this topic in an attempt to fix wireplumber's goldfish memory problem (it just wouldn't store any session information), and came up with an improved version. This post should be enough for anyone interested to try it. Enjoy!

Apparently, wireplumber requires a valid HOME for its persistence.
Also, somewhere in the meantime bluetooth speaker stopped working with my previous configuration. I hardly ever use it, so I don't know when or why it broke, but I've got a workaround for that too. Perhaps someone could figure out an actual solution. My guess is it has something to do with dbus, but I'm not going to investigate further for now.
As a side note, I cleaned up a little bit, since some things included in earlier scripts turned out to be redundant.

============================================================================================
The base setup:
emerge acct-user/pipewire acct-group/pipewire media-video/pipewire media-video/wireplumber
Make sure your user is a member of pipewire group

create init script /etc/init.d/pipewire

Code: Select all

#!/sbin/openrc-run

PIPEWIRE_RUNTIME_DIR="/run/pipewire"
name="pipewire daemon"
description=""
command=/usr/bin/pipewire
command_args="${pipewire_args}"
command_background=yes
command_user="pipewire:pipewire"
pidfile="${PIPEWIRE_RUNTIME_DIR}/${RC_SVCNAME}.pid"
umask="0007"

export PIPEWIRE_RUNTIME_DIR

depend() {
	# Even though wireplumber controls volume levels, something must unmute your devices first.
	# AFAIR "use" should be enough to start the service as a dependency, but somehow it is not.
	need alsasound
}

start_pre() {
	mkdir -p   "${PIPEWIRE_RUNTIME_DIR}"
	chown -R pipewire:pipewire "${PIPEWIRE_RUNTIME_DIR}"
}

Create init script /etc/init.d/wireplumber

Code: Select all

#!/sbin/openrc-run

PIPEWIRE_RUNTIME_DIR="/run/pipewire"
name="wireplumber daemon"
description=""
command=/usr/bin/wireplumber
command_args="${wireplumber_args}"
command_background="true"
command_user="${PIPEWIRE_USER:-pipewire}:${PIPEWIRE_GROUP:-pipewire}"
directory="${PIPEWIRE_RUNTIME_DIR}"

pidfile="${PIPEWIRE_RUNTIME_DIR}/${RC_SVCNAME}.pid"

depend() {
   need pipewire
}

Options:
1) Persistence + bluetooth workaround for a single-user system
echo PIPEWIRE_USER=<your username> > /etc/conf.d/wireplumber

2) Persistence on a multiuser system, without bluetooth
copy acct-user/pipewire/pipewire-1-r2.ebuild to your local overlay
change ACCT_USER_HOME from /dev/null to /var/lib/pipewire
re-emerge acct-user/pipewire, using the one from local overlay

3) Persistence + bluetooth on a multiuser system
Instead of starting wireplumber as a service, just launch it from within your session after you login.
Make Pipewire a system service
Top
Post Reply

12 posts • Page 1 of 1

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic