[PATCH] gnu: home: Add support for home-pipewire-service

  • Done
  • quality assurance status badge
Details
8 participants
  • Andrew Tropin
  • Brian Cully
  • Oleg Pykhalov
  • Hilton Chain
  • Jakob Honal
  • Ludovic Courtès
  • Tanguy LE CARROUR
  • taosabella
Owner
unassigned
Submitted by
Brian Cully
Severity
normal
B
B
Brian Cully wrote on 3 Jun 2023 01:04
(address . guix-patches@gnu.org)(name . Brian Cully)(address . bjc@spork.org)
13252a733171e18f4d39d0185ddf3e8e3c06bc15.1685747062.git.bjc@spork.org
This adds a set of home shepherd services which will start the required
services for a functional pipewire setup.

* gnu/home/services/sound.scm (home-pipewire-shepherd-service),
(home-pipewire-pulse-shepherd-service), (home-wireplumber-shepherd-service),
(home-pipewire-shepherd-services), (generate-doc): new procedures.
(home-pipewire-service-type): new service type.
(home-pipewire-configuration): new struct.
* doc/guix.texi (Sound Home Services): document it.
---
doc/guix.texi | 34 +++++++++++++++++
gnu/home/services/sound.scm | 74 ++++++++++++++++++++++++++++++++++++-
2 files changed, 107 insertions(+), 1 deletion(-)

Toggle diff (157 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index 7f8d8d66e9..0b19c9301f 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -116,6 +116,7 @@
Copyright @copyright{} 2023 Karl Hallsby@*
Copyright @copyright{} 2023 Nathaniel Nicandro@*
Copyright @copyright{} 2023 Tanguy Le Carrour@*
+Copyright @copyright{} 2023 Brian Cully@*
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -43563,6 +43564,39 @@ Sound Home Services
This is the multicast address used by default by the two services above.
@end defvar
+@cindex PipeWire, home service
+
+@uref{https://pipewire.org, PipeWire} provides a low-latency,
+graph-based audio and video processing service. In addition to its
+native protocol, it can also be used as a replacement for both JACK and
+PulseAudio.
+
+@defvar home-pipewire-service-type
+This provides the service definition for @command{pipewire}, which will
+run on login. Its value is a @code{home-pipewire-configuration} object.
+
+To start the service, add it to the @code{service} field of your
+@code{home-environment}, such as:
+
+@lisp
+(service home-pipewire-service-type)
+@end lisp
+
+@deftp {Data Type} home-pipewire-configuration
+Available @code{home-pipewire-configuration} fields are:
+
+@table @asis
+@item @code{pipewire} (default: @code{pipewire}) (type: file-like)
+The PipeWire package to use.
+
+@item @code{wireplumber} (default: @code{wireplumber}) (type: file-like)
+The WirePlumber package to use.
+
+@item @code{enable-pulseaudio?} (default: @code{#t}) (type: boolean)
+Enable PulseAudio replacement.
+@end table
+@end deftp
+
@node Mail Home Services
@subsection Mail Home Services
diff --git a/gnu/home/services/sound.scm b/gnu/home/services/sound.scm
index 22c1a99250..94d8bc7482 100644
--- a/gnu/home/services/sound.scm
+++ b/gnu/home/services/sound.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2023 Brian Cully <bjc@spork.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -19,13 +20,77 @@
(define-module (gnu home services sound)
#:use-module (gnu home services)
#:use-module (gnu home services shepherd)
+ #:use-module (gnu packages linux)
+ #:use-module (gnu services configuration)
#:use-module (guix records)
#:use-module (guix gexp)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-26)
#:use-module (ice-9 match)
#:export (home-pulseaudio-rtp-sink-service-type
home-pulseaudio-rtp-source-service-type
- %pulseaudio-rtp-multicast-address))
+ %pulseaudio-rtp-multicast-address
+
+ home-pipewire-configuration
+ home-pipewire-service-type))
+
+
+;;;
+;;; PipeWire support.
+;;;
+(define-configuration/no-serialization home-pipewire-configuration
+ (pipewire (file-like pipewire) "The PipeWire package to use.")
+ (wireplumber (file-like wireplumber) "The WirePlumber package to use.")
+ (enable-pulseaudio? (boolean #t) "Enable PulseAudio replacement."))
+
+(define (home-pipewire-shepherd-service config)
+ (shepherd-service
+ (documentation "PipeWire screen and audio sharing.")
+ (provision '(pipewire))
+ (requirement '(dbus))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire"))))))
+
+(define (home-pipewire-pulseaudio-shepherd-service config)
+ (shepherd-service
+ (documentation "Drop-in PulseAudio replacement service for PipeWire.")
+ (provision '(pipewire-pulseaudio))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire-pulse"))))))
+
+(define (home-wireplumber-shepherd-service config)
+ (shepherd-service
+ (documentation "WirePlumber session management for PipeWire.")
+ (provision '(wireplumber))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-wireplumber config)
+ "/bin/wireplumber"))))))
+
+(define (home-pipewire-shepherd-services config)
+ (define shepherd-services
+ (filter
+ identity
+ (list home-pipewire-shepherd-service home-wireplumber-shepherd-service
+ (and (home-pipewire-configuration-enable-pulseaudio? config)
+ home-pipewire-pulseaudio-shepherd-service))))
+ (map (cut <> config) shepherd-services))
+
+(define home-pipewire-service-type
+ (service-type
+ (name 'pipewire)
+ (extensions
+ (list (service-extension home-shepherd-service-type
+ home-pipewire-shepherd-services)))
+ (description
+ "Start essential PipeWire services.")
+ (default-value (home-pipewire-configuration))))
;;;
@@ -149,3 +214,10 @@ (define home-pulseaudio-rtp-source-service-type
"Define a PulseAudio source to receive audio broadcasted over RTP by
another PulseAudio instance.")
(default-value %pulseaudio-rtp-multicast-address)))
+
+
+;;;
+;;; Generate documentation.
+;;;
+(define (generate-doc)
+ (configuration->documentation 'home-pipewire-configuration))

base-commit: c11b92a8aae6fe7fad0da8257ec28f5009c37b35
--
2.40.1
L
L
Ludovic Courtès wrote on 9 Jun 2023 22:22
(name . Brian Cully)(address . bjc@spork.org)(address . 63863@debbugs.gnu.org)
87o7lov11n.fsf@gnu.org
Hi,

Brian Cully <bjc@spork.org> skribis:

Toggle quote (10 lines)
> This adds a set of home shepherd services which will start the required
> services for a functional pipewire setup.
>
> * gnu/home/services/sound.scm (home-pipewire-shepherd-service),
> (home-pipewire-pulse-shepherd-service), (home-wireplumber-shepherd-service),
> (home-pipewire-shepherd-services), (generate-doc): new procedures.
> (home-pipewire-service-type): new service type.
> (home-pipewire-configuration): new struct.
> * doc/guix.texi (Sound Home Services): document it.

[...]

Toggle quote (7 lines)
> +@cindex PipeWire, home service
> +
> +@uref{https://pipewire.org, PipeWire} provides a low-latency,
> +graph-based audio and video processing service. In addition to its
> +native protocol, it can also be used as a replacement for both JACK and
> +PulseAudio.

Could you explain why a Home service is necessary (I’d expect it to be
started on-demand via D-Bus or similar, like PulseAudio)?

Also, please leave two spaces after end-of-sentence periods (this eases
navigation in Emacs).

Toggle quote (7 lines)
> +@table @asis
> +@item @code{pipewire} (default: @code{pipewire}) (type: file-like)
> +The PipeWire package to use.
> +
> +@item @code{wireplumber} (default: @code{wireplumber}) (type: file-like)
> +The WirePlumber package to use.

Could you add a few words saying what each of these packages does,
especially the second one.

Toggle quote (3 lines)
> +@item @code{enable-pulseaudio?} (default: @code{#t}) (type: boolean)
> +Enable PulseAudio replacement.

Maybe add: “When true, PulseAudio applications will talk to PipeWire,
which will handle them as if they were ``native'' PipeWire
applications.” (I’m making it up, but you get the idea.)

Toggle quote (4 lines)
> +;;; PipeWire support.
> +;;;
> +(define-configuration/no-serialization home-pipewire-configuration

Please leave an empty line after the comment.

Toggle quote (10 lines)
> +(define (home-pipewire-shepherd-service config)
> + (shepherd-service
> + (documentation "PipeWire screen and audio sharing.")
> + (provision '(pipewire))
> + (requirement '(dbus))
> + (start #~(make-forkexec-constructor
> + (list #$(file-append
> + (home-pipewire-configuration-pipewire config)
> + "/bin/pipewire"))))))

Please add the ‘stop’ method or the process will never be stopped. :-)

Toggle quote (5 lines)
> + (start #~(make-forkexec-constructor
> + (list #$(file-append
> + (home-pipewire-configuration-pipewire config)
> + "/bin/pipewire-pulse"))))))

Same here…

Toggle quote (5 lines)
> + (start #~(make-forkexec-constructor
> + (list #$(file-append
> + (home-pipewire-configuration-wireplumber config)
> + "/bin/wireplumber"))))))

… and here.


Toggle quote (9 lines)
> +(define (home-pipewire-shepherd-services config)
> + (define shepherd-services
> + (filter
> + identity
> + (list home-pipewire-shepherd-service home-wireplumber-shepherd-service
> + (and (home-pipewire-configuration-enable-pulseaudio? config)
> + home-pipewire-pulseaudio-shepherd-service))))
> + (map (cut <> config) shepherd-services))

Rather:

(cons* (home-pipewire-shepherd-service config)
(home-wireplumber-shepherd-service config)
(if …
(list (home-pipewire-pulseaudio-shepherd-service config))
'()))

Toggle quote (3 lines)
> + (description
> + "Start essential PipeWire services.")

Can you add a couple of sentences? That’s useful when running ‘guix
home search’ or similar.

Toggle quote (8 lines)
> +
> +
> +;;;
> +;;; Generate documentation.
> +;;;
> +(define (generate-doc)
> + (configuration->documentation 'home-pipewire-configuration))

This is unused, please remove it.

Could you send a v2?

Thanks!

Ludo’.
A
A
Andrew Tropin wrote on 12 Jun 2023 07:50
Re: [bug#63863] [PATCH] gnu: home: Add support for home-pipewire-service
87mt15mdp4.fsf@trop.in
On 2023-06-02 19:04, Brian Cully via Guix-patches via wrote:

Toggle quote (109 lines)
> This adds a set of home shepherd services which will start the required
> services for a functional pipewire setup.
>
> * gnu/home/services/sound.scm (home-pipewire-shepherd-service),
> (home-pipewire-pulse-shepherd-service), (home-wireplumber-shepherd-service),
> (home-pipewire-shepherd-services), (generate-doc): new procedures.
> (home-pipewire-service-type): new service type.
> (home-pipewire-configuration): new struct.
> * doc/guix.texi (Sound Home Services): document it.
> ---
> doc/guix.texi | 34 +++++++++++++++++
> gnu/home/services/sound.scm | 74 ++++++++++++++++++++++++++++++++++++-
> 2 files changed, 107 insertions(+), 1 deletion(-)
>
> diff --git a/doc/guix.texi b/doc/guix.texi
> index 7f8d8d66e9..0b19c9301f 100644
> --- a/doc/guix.texi
> +++ b/doc/guix.texi
> @@ -116,6 +116,7 @@
> Copyright @copyright{} 2023 Karl Hallsby@*
> Copyright @copyright{} 2023 Nathaniel Nicandro@*
> Copyright @copyright{} 2023 Tanguy Le Carrour@*
> +Copyright @copyright{} 2023 Brian Cully@*
>
> Permission is granted to copy, distribute and/or modify this document
> under the terms of the GNU Free Documentation License, Version 1.3 or
> @@ -43563,6 +43564,39 @@ Sound Home Services
> This is the multicast address used by default by the two services above.
> @end defvar
>
> +@cindex PipeWire, home service
> +
> +@uref{https://pipewire.org, PipeWire} provides a low-latency,
> +graph-based audio and video processing service. In addition to its
> +native protocol, it can also be used as a replacement for both JACK and
> +PulseAudio.
> +
> +@defvar home-pipewire-service-type
> +This provides the service definition for @command{pipewire}, which will
> +run on login. Its value is a @code{home-pipewire-configuration} object.
> +
> +To start the service, add it to the @code{service} field of your
> +@code{home-environment}, such as:
> +
> +@lisp
> +(service home-pipewire-service-type)
> +@end lisp
> +
> +@deftp {Data Type} home-pipewire-configuration
> +Available @code{home-pipewire-configuration} fields are:
> +
> +@table @asis
> +@item @code{pipewire} (default: @code{pipewire}) (type: file-like)
> +The PipeWire package to use.
> +
> +@item @code{wireplumber} (default: @code{wireplumber}) (type: file-like)
> +The WirePlumber package to use.
> +
> +@item @code{enable-pulseaudio?} (default: @code{#t}) (type: boolean)
> +Enable PulseAudio replacement.
> +@end table
> +@end deftp
> +
> @node Mail Home Services
> @subsection Mail Home Services
>
> diff --git a/gnu/home/services/sound.scm b/gnu/home/services/sound.scm
> index 22c1a99250..94d8bc7482 100644
> --- a/gnu/home/services/sound.scm
> +++ b/gnu/home/services/sound.scm
> @@ -1,5 +1,6 @@
> ;;; GNU Guix --- Functional package management for GNU
> ;;; Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
> +;;; Copyright © 2023 Brian Cully <bjc@spork.org>
> ;;;
> ;;; This file is part of GNU Guix.
> ;;;
> @@ -19,13 +20,77 @@
> (define-module (gnu home services sound)
> #:use-module (gnu home services)
> #:use-module (gnu home services shepherd)
> + #:use-module (gnu packages linux)
> + #:use-module (gnu services configuration)
> #:use-module (guix records)
> #:use-module (guix gexp)
> #:use-module (srfi srfi-1)
> + #:use-module (srfi srfi-26)
> #:use-module (ice-9 match)
> #:export (home-pulseaudio-rtp-sink-service-type
> home-pulseaudio-rtp-source-service-type
> - %pulseaudio-rtp-multicast-address))
> + %pulseaudio-rtp-multicast-address
> +
> + home-pipewire-configuration
> + home-pipewire-service-type))
> +
> +
> +;;;
> +;;; PipeWire support.
> +;;;
> +(define-configuration/no-serialization home-pipewire-configuration
> + (pipewire (file-like pipewire) "The PipeWire package to use.")
> + (wireplumber (file-like wireplumber) "The WirePlumber package to use.")
> + (enable-pulseaudio? (boolean #t) "Enable PulseAudio replacement."))
> +
> +(define (home-pipewire-shepherd-service config)
> + (shepherd-service
> + (documentation "PipeWire screen and audio sharing.")

The description seems a little bit missleading, while PipeWire can do
screensharing, it's not only or even primary role.

Toggle quote (62 lines)
> + (provision '(pipewire))
> + (requirement '(dbus))
> + (start #~(make-forkexec-constructor
> + (list #$(file-append
> + (home-pipewire-configuration-pipewire config)
> + "/bin/pipewire"))))))
> +
> +(define (home-pipewire-pulseaudio-shepherd-service config)
> + (shepherd-service
> + (documentation "Drop-in PulseAudio replacement service for PipeWire.")
> + (provision '(pipewire-pulseaudio))
> + (requirement '(pipewire))
> + (start #~(make-forkexec-constructor
> + (list #$(file-append
> + (home-pipewire-configuration-pipewire config)
> + "/bin/pipewire-pulse"))))))
> +
> +(define (home-wireplumber-shepherd-service config)
> + (shepherd-service
> + (documentation "WirePlumber session management for PipeWire.")
> + (provision '(wireplumber))
> + (requirement '(pipewire))
> + (start #~(make-forkexec-constructor
> + (list #$(file-append
> + (home-pipewire-configuration-wireplumber config)
> + "/bin/wireplumber"))))))
> +
> +(define (home-pipewire-shepherd-services config)
> + (define shepherd-services
> + (filter
> + identity
> + (list home-pipewire-shepherd-service home-wireplumber-shepherd-service
> + (and (home-pipewire-configuration-enable-pulseaudio? config)
> + home-pipewire-pulseaudio-shepherd-service))))
> + (map (cut <> config) shepherd-services))
> +
> +(define home-pipewire-service-type
> + (service-type
> + (name 'pipewire)
> + (extensions
> + (list (service-extension home-shepherd-service-type
> + home-pipewire-shepherd-services)))
> + (description
> + "Start essential PipeWire services.")
> + (default-value (home-pipewire-configuration))))
>
>
> ;;;
> @@ -149,3 +214,10 @@ (define home-pulseaudio-rtp-source-service-type
> "Define a PulseAudio source to receive audio broadcasted over RTP by
> another PulseAudio instance.")
> (default-value %pulseaudio-rtp-multicast-address)))
> +
> +
> +;;;
> +;;; Generate documentation.
> +;;;
> +(define (generate-doc)
> + (configuration->documentation 'home-pipewire-configuration))
>
> base-commit: c11b92a8aae6fe7fad0da8257ec28f5009c37b35

Hi Brian,

Thank you for the patch! You may also want to add pipewire backend for
alsa:

--
Best regards,
Andrew Tropin
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmSGsicACgkQIgjSCVjB
3rClnxAAjAYXIoPx3Eorh6icMEkTOfYTJUQ7eyIgjfzt0hUw6K4tNE6v3A3XqgZh
pmvXV/r4LSibZloZkYDZF15/vwaTwqiGQwuRVP38XtLD58BzKWRSBieIwkO0kQZg
4bXpftBgFMC/6+4YR+9R7koMRAZt8hNQyY3AcrAj+6wOjCxdi/unXq5fhAXR7VKS
sceeCzKIwzgeWwKbDZ3wp1ncVbgQ+IjNOSjXSyBfrTtYTAAPVxgx4S8BeRWznPPt
ldBaMswvTduXeNFxgAHAUBcsQTEV8SFdtnsX66az6woyrf29/i/7636ZGyYe9ZaS
bmbCMNlCfSsGutjvrbGfRdC+u59pYHMZ592+jEu21UAAI1Gff/dS4Pc7dfGxoZtG
FKMYPOoB+hyGK/Eeo7uNCtoRCVvElhX2ql/6erpPhqruB8zT0xeHNIAJf1KSHxzr
a3u96DroKtsTgmB7iEC5L51j/ojGmNohz98DB05CjPyEICGa/MAzUU0Qm25uRnD8
6H0SI1MKPYpq3q85XqXUSrvz54PyT86QycgsdgAeP4NPAskn+7JkpRUSknVBc4gn
icYxCogyn9rFVeFsD3Dgr7xnZ9D+DN3TTKPtZYPysFF7cYgVXGNvb8dbPvfeknpI
GS8tek+m/dt0TnrjANjMjJ3s7l/2vgLlbfOHVfSIy138kMa/KxE=
=cRyd
-----END PGP SIGNATURE-----

B
B
Brian Cully wrote on 12 Jun 2023 17:56
(name . Andrew Tropin)(address . andrew@trop.in)(address . 63863@debbugs.gnu.org)
875y7spsgv.fsf@psyduck.jhoto.kublai.com
Andrew Tropin <andrew@trop.in> writes:
Toggle quote (8 lines)
>> +(define (home-pipewire-shepherd-service config)
>> + (shepherd-service
>> + (documentation "PipeWire screen and audio sharing.")
>
> The description seems a little bit missleading, while PipeWire
> can do
> screensharing, it's not only or even primary role.

I'm not sure I understand the objection. Would you rather I
mention its audio capabilities before screen sharing? Or would
something like "PipeWire media processing" seem to suit it better
for you?

Truth be told, I find succinctly describing PipeWire for this
context to be pretty difficult. It does a lot, and it's all pretty
abstract. PipeWire is just plumbing for services people actually
care about, and I don't think "PipeWire make media worky" is going
to fly ?.

Toggle quote (5 lines)
> Thank you for the patch! You may also want to add pipewire
> backend for
> alsa:
> https://git.sr.ht/~abcdw/rde/tree/525f8c7f25783c6b8fa55f21c8e62237bc0d4a04/src/rde/features/linux.scm#L100

Thanks for the pointer. I'll try to dig through the documentation
to see what I can do. I find the Linux sound ecosystem to be
pretty confusing. For instance: I thought ALSA was the backend
that PipeWire used on Linux already, so I don't understand how
ALSA can also use PipeWire as a backend.

My use for this patch was Wayland-motivated, and everything
outside of basic functionality (screen sharing and playing audio
from Firefox and MPD) wasn't something I spent much time on —
since I really don't know much about it — in the hopes that we
could provide a minimum level of service for people and add better
support as people needed it as time went on.

-bjc
A
A
Andrew Tropin wrote on 13 Jun 2023 06:39
(name . Brian Cully)(address . bjc@spork.org)(address . 63863@debbugs.gnu.org)
87pm602cy3.fsf@trop.in
On 2023-06-12 11:56, Brian Cully wrote:

Toggle quote (12 lines)
> Andrew Tropin <andrew@trop.in> writes:
>>> +(define (home-pipewire-shepherd-service config)
>>> + (shepherd-service
>>> + (documentation "PipeWire screen and audio sharing.")
>>
>> The description seems a little bit missleading, while PipeWire
>> can do
>> screensharing, it's not only or even primary role.
>
> I'm not sure I understand the objection. Would you rather I
> mention its audio capabilities before screen sharing?

Nope.

Toggle quote (3 lines)
> Or would something like "PipeWire media processing" seem to suit it
> better for you?

Yep.

Toggle quote (7 lines)
> Truth be told, I find succinctly describing PipeWire for this
> context to be pretty difficult. It does a lot, and it's all pretty
> abstract. PipeWire is just plumbing for services people actually
> care about, and I don't think "PipeWire make media worky" is going
> to fly ?.
>

"PipeWire make media worky" would work great! :D jk

Real-time multimedia capturing, processing and playback or low-latency,
graph-based audio and video processing engine or something like that.

Toggle quote (18 lines)
>> Thank you for the patch! You may also want to add pipewire
>> backend for
>> alsa:
>> https://git.sr.ht/~abcdw/rde/tree/525f8c7f25783c6b8fa55f21c8e62237bc0d4a04/src/rde/features/linux.scm#L100
>
> Thanks for the pointer. I'll try to dig through the documentation
> to see what I can do. I find the Linux sound ecosystem to be
> pretty confusing. For instance: I thought ALSA was the backend
> that PipeWire used on Linux already, so I don't understand how
> ALSA can also use PipeWire as a backend.
>
> My use for this patch was Wayland-motivated, and everything
> outside of basic functionality (screen sharing and playing audio
> from Firefox and MPD) wasn't something I spent much time on —
> since I really don't know much about it — in the hopes that we
> could provide a minimum level of service for people and add better
> support as people needed it as time went on.

Yep, we have similiar use cases in rde and configuration mentioned
earlier serves them quite well. According to Alsa: I don't have deep
knowledge in this area too, but according to my knowledge pipewire can
be loaded as a shared library and injected into alsa user-facing API to
process requests, so maybe a backend for ALSA-based applications or
middleend for ALSA will be more apropriate name for the pipewire role
here :)

Anyway, without the config above alsamixer doesn't work on my system,
probably with some configuration it's possible to make it work, but
bypassing pipewire, however I think it would be nice to go full
pipewire.

--
Best regards,
Andrew Tropin
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmSH8vQACgkQIgjSCVjB
3rDEhg/+MqNlQalpc8o1sMAhq39h3dx5c/WJv4QwHXMNdCtpJM/yNa+WF9zAtDUL
79w45+zLV4M2ouwA8+1/0mzj0TIeo/PMF4+q20UagGx7AqgwxFzSfuNgh2ZMMWWy
RpMI+SaVoqW8xIZBxtVEVQ6liVr3Gseq/m+bdDCAJfbaVGD7mQe131cWpvuYoupf
cctLBZYGdAMcg4Z2FFQteukoXSOZIwpHOuAAmPIPxUDtGYf02qBsg3EGbQ/SrZ98
i+ofEE58zKfT5I1r/1oQ8dG1s4KmVnWpkcZdrAieYCx2ybUS+mfNXjjVJf269hrj
4i1NnQ9e7p+UawgmLN2+6JWKu9IUwZDSVOQEGRmw2MxxrU/VqMdCLEU32WyTMgnj
9kwm73ojdA96Xu8mC1ttKB3CUKbe0ni5gY2rFdNlEZTYW85xpbUO85EOBXGY23vq
lhamRphabC29+pVNd/E6KrPnvs6kTQjUJP+zHj7wCldqR0y435PSy3Z5qBTfZSbW
clDr0iuGT/dDoLuKgY5gbjdpbEAb7Tbp3iTnA563Pp8lqxE0w15pb8pOsm3OyzQG
IS7xw64FTcnl/ltkxEA9nxD4z9eQZjgSq5DXjFX0jMJ6MHh2+ZT0IRGCkz15sgzE
B1zQ3JDjK5P9Gp+7xXzqwyq99MqbDAa0BVTJCnWMhjzt1m1GuIg=
=gLar
-----END PGP SIGNATURE-----

B
B
Brian Cully wrote on 13 Jun 2023 14:20
(name . Andrew Tropin)(address . andrew@trop.in)(address . 63863@debbugs.gnu.org)
87wn07o40w.fsf@psyduck.jhoto.kublai.com
Andrew Tropin <andrew@trop.in> writes:
Toggle quote (6 lines)
>> Or would something like "PipeWire media processing" seem to
>> suit it
>> better for you?
>
> Yep.

Works for me.

Toggle quote (7 lines)
> Anyway, without the config above alsamixer doesn't work on my
> system,
> probably with some configuration it's possible to make it work,
> but
> bypassing pipewire, however I think it would be nice to go full
> pipewire.

I've just tried using ‘alsamixer’ from the ‘alsa-utils’ package
this morning, and it works for me without any additional
configuration. It shows both ‘Card’ and ‘Chip’ to be ‘PulseAudio’,
and volume control works. Although, that is with PulseAudio
emulation enabled. Should the ALSA configuration always be added?
Or just if it's enabled in configuration (possibly defaulting #t)?

-bjc
A
A
Andrew Tropin wrote on 14 Jun 2023 11:08
(name . Brian Cully)(address . bjc@spork.org)(address . 63863@debbugs.gnu.org)
875y7qif6z.fsf@trop.in
On 2023-06-13 08:20, Brian Cully wrote:

Toggle quote (22 lines)
> Andrew Tropin <andrew@trop.in> writes:
>>> Or would something like "PipeWire media processing" seem to
>>> suit it
>>> better for you?
>>
>> Yep.
>
> Works for me.
>
>> Anyway, without the config above alsamixer doesn't work on my
>> system,
>> probably with some configuration it's possible to make it work,
>> but
>> bypassing pipewire, however I think it would be nice to go full
>> pipewire.
>
> I've just tried using ‘alsamixer’ from the ‘alsa-utils’ package
> this morning, and it works for me without any additional
> configuration. It shows both ‘Card’ and ‘Chip’ to be ‘PulseAudio’,
> and volume control works. Although, that is with PulseAudio
> emulation enabled.

With config mentioned earlier it shows PipeWire in Card and Chip.

Toggle quote (3 lines)
> Should the ALSA configuration always be added? Or just if it's
> enabled in configuration (possibly defaulting #t)?

Yep, I think it should be always added by default.

Also, it make sense to disable autospawn of pulseaudio to prevent
accidential interference.

Like this:

--
Best regards,
Andrew Tropin
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmSJg5QACgkQIgjSCVjB
3rBL5Q//b88E4u4RT1v9D2FMzmTgit9ZdSP5kEueTvy30CGHtDYbqO3g5yXOxJNE
V+zEYjkMiXHQFEnbaNzRprwKd5H3WUI7S1UKWgrlUKrWIJdGO/TbvEFIrglyJWZT
s8OO79TXmfBHDn2TRPXwtCtbwgXCfTapebUciunGTsApumYo9/13e6Lig2YoNOyb
9ZhKD3HiMjI+pbq/lbWz80WPPVdzVvtfKma6dZDC+jGpBRFCWSyhe37VVpR61wxX
qGpkuf9DAsJEg2NBybIzpK104WqAmn9k4acJWbUTBj8X4qfCmoRK7im91Z6R/KSe
aIojQOuXWJxnOi/LMHdqjkjRXRkjc7obGmq4xPqutiCX1GRfQi7G8CSLehw4/drm
V0dtPXZPySugvoRYH7xl0nVIaGYo2gHlkzYwzzxC63vPF2b11G0Z/CnbIgAo600U
W2iEYOh7W1ww5+qXWCxPqTI3LGI12ZHMGsyQVChhvjmvHW8OvbkhXPWjMXt5o5of
zSBffaFU4TZy4Vvp5vwqnhGkRDdBi/2YHCMzu+/cfwRPXuzgfR5w+hJWbvpY6JI9
ZuFoMcflNeus3s4x0fDh0ilifI0xUZc8klIPyHliNhe5gM6SBNgMUcmgd+Mhz12R
DodxX/K+e/Glh6tjE7i2b/vCZREP2BVcReJ/J1YsjtBPP77MOyg=
=9DrV
-----END PGP SIGNATURE-----

B
B
Brian Cully wrote on 15 Jun 2023 15:16
[PATCH v2] gnu: home: Add support for home-pipewire-service
(address . 63863@debbugs.gnu.org)(name . Brian Cully)(address . bjc@spork.org)
92a7e4009704b62b5ceddfa3fdd5bd12fb6ef91c.1686834990.git.bjc@spork.org
This adds a set of home shepherd services which will start the required
services for a functional pipewire setup.

* gnu/home/services/sound.scm (home-pipewire-shepherd-service),
(home-pipewire-pulse-shepherd-service), (home-wireplumber-shepherd-service),
(home-pipewire-shepherd-services)
(home-pipewire-asoundrc), (home-pipewire-xdg-configuration): new procedures.
(home-pipewire-service-type): new service type.
(home-pipewire-configuration): new struct.
(home-pipewire-disable-pulseaudio-auto-start): new variable.
* doc/guix.texi (Sound Home Services): document it.
---
doc/guix.texi | 47 +++++++++++++++
gnu/home/services/sound.scm | 115 +++++++++++++++++++++++++++++++++++-
2 files changed, 161 insertions(+), 1 deletion(-)

Toggle diff (207 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index 9232c82b4b..ee50d7a324 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -116,6 +116,7 @@
Copyright @copyright{} 2023 Karl Hallsby@*
Copyright @copyright{} 2023 Nathaniel Nicandro@*
Copyright @copyright{} 2023 Tanguy Le Carrour@*
+Copyright @copyright{} 2023 Brian Cully@*
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -43635,6 +43636,52 @@ Sound Home Services
This is the multicast address used by default by the two services above.
@end defvar
+@cindex PipeWire, home service
+
+@uref{https://pipewire.org, PipeWire} provides a low-latency,
+graph-based audio and video processing service. In addition to its
+native protocol, it can also be used as a replacement for both JACK and
+PulseAudio.
+
+While PipeWire provides the media processing and API, it does not,
+directly, know about devices such as sound cards, nor how you might want
+to connect applications, hardware, and media processing
+filters. Instead, PipeWire relies on a @dfn{session manager} to specify
+all these relationships. While you may use any session manager you wish,
+for most people the
+@url{https://pipewire.pages.freedesktop.org/wireplumber/, WirePlumber}
+session manager, a reference implementation provided by the PipeWire
+project itself, suffices, and that is the one
+@code{home-pipewire-service-type} uses.
+
+@defvar home-pipewire-service-type
+This provides the service definition for @command{pipewire}, which will
+run on login. Its value is a @code{home-pipewire-configuration} object.
+
+To start the service, add it to the @code{service} field of your
+@code{home-environment}, such as:
+
+@lisp
+(service home-pipewire-service-type)
+@end lisp
+@end defvar
+
+@deftp {Data Type} home-pipewire-configuration
+Available @code{home-pipewire-configuration} fields are:
+
+@table @asis
+@item @code{pipewire} (default: @code{pipewire}) (type: file-like)
+The PipeWire package to use.
+
+@item @code{wireplumber} (default: @code{wireplumber}) (type: file-like)
+The WirePlumber package to use.
+
+@item @code{enable-pulseaudio?} (default: @code{#t}) (type: boolean)
+When true, enable PipeWire's PulseAudio emulation support, allowing
+PulseAudio clients to use PipeWire transparently.
+@end table
+@end deftp
+
@node Mail Home Services
@subsection Mail Home Services
diff --git a/gnu/home/services/sound.scm b/gnu/home/services/sound.scm
index 22c1a99250..5463255e8c 100644
--- a/gnu/home/services/sound.scm
+++ b/gnu/home/services/sound.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2023 Brian Cully <bjc@spork.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -19,13 +20,125 @@
(define-module (gnu home services sound)
#:use-module (gnu home services)
#:use-module (gnu home services shepherd)
+ #:use-module (gnu home services xdg)
+ #:use-module (gnu packages linux)
+ #:use-module (gnu services configuration)
#:use-module (guix records)
#:use-module (guix gexp)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:export (home-pulseaudio-rtp-sink-service-type
home-pulseaudio-rtp-source-service-type
- %pulseaudio-rtp-multicast-address))
+ %pulseaudio-rtp-multicast-address
+
+ home-pipewire-configuration
+ home-pipewire-service-type))
+
+
+;;;
+;;; PipeWire support.
+;;;
+
+(define-configuration/no-serialization home-pipewire-configuration
+ (pipewire
+ (file-like pipewire)
+ "The PipeWire package to use.")
+ (wireplumber
+ (file-like wireplumber)
+ "The WirePlumber package to use.")
+ (enable-pulseaudio?
+ (boolean #t)
+ "When true, enable PipeWire's PulseAudio emulation support, allowing
+PulseAudio clients to use PipeWire transparently."))
+
+(define (home-pipewire-shepherd-service config)
+ (shepherd-service
+ (documentation "PipeWire media processing.")
+ (provision '(pipewire))
+ (requirement '(dbus))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-pulseaudio-shepherd-service config)
+ (shepherd-service
+ (documentation "Drop-in PulseAudio replacement service for PipeWire.")
+ (provision '(pipewire-pulseaudio))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire-pulse"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-wireplumber-shepherd-service config)
+ (shepherd-service
+ (documentation "WirePlumber session management for PipeWire.")
+ (provision '(wireplumber))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-wireplumber config)
+ "/bin/wireplumber"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-shepherd-services config)
+ (cons* (home-pipewire-shepherd-service config)
+ (home-wireplumber-shepherd-service config)
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ (list (home-pipewire-pulseaudio-shepherd-service config))
+ '())))
+
+(define (home-pipewire-asoundrc config)
+ (mixed-text-file
+ "asoundrc"
+ #~(string-append
+ "<"
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/share/alsa/alsa.conf.d/50-pipewire.conf")
+ ">\n"
+ "<"
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/share/alsa/alsa.conf.d/99-pipewire-default.conf")
+ ">\n"
+ "pcm_type.pipewire {\n"
+ " lib \""
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/lib/alsa-lib/libasound_module_pcm_pipewire.so")
+ "\"\n}\n"
+ "ctl_type.pipewire {\n"
+ " lib \""
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/lib/alsa-lib/libasound_module_ctl_pipewire.so")
+ "\"\n}\n")))
+
+(define home-pipewire-disable-pulseaudio-auto-start
+ (plain-file "client.conf" "autospawn = no"))
+
+(define (home-pipewire-xdg-configuration config)
+ (cons* `("alsa/asoundrc" ,(home-pipewire-asoundrc config))
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ `(("pulse/client.conf"
+ ,home-pipewire-disable-pulseaudio-auto-start))
+ '())))
+
+(define home-pipewire-service-type
+ (service-type
+ (name 'pipewire)
+ (extensions
+ (list (service-extension home-shepherd-service-type
+ home-pipewire-shepherd-services)
+ (service-extension home-xdg-configuration-files-service-type
+ home-pipewire-xdg-configuration)))
+ (description
+ "Start essential PipeWire services.")
+ (default-value (home-pipewire-configuration))))
;;;

base-commit: f74df2ab879fc5457982bbc85b7455a90e82317d
--
2.40.1
B
B
Brian Cully wrote on 15 Jun 2023 15:19
(name . Brian Cully)(address . bjc@spork.org)(address . 63863@debbugs.gnu.org)
87bkhgeu50.fsf@psyduck.jhoto.kublai.com
This address most of the issues, I hope.

* I've added a config for ALSA.
* I'm disabling autospawn for PulseAudio when ‘enable-pulseaudio?’
is #t
* I've added a paragraph to the documentation explaining
WireGuard.
* The missing Shepherd ‘stop’ fields are no longer missing.
* I've changed the wording for the Shepherd ‘pipewire’ service
documentation.
* The documentation generation function has been removed.
* I've reworded the ‘enable-pulseaudio?’ configuration field of
‘home-pipewire-configuration’.

-bjc
B
B
Brian Cully wrote on 15 Jun 2023 15:26
[PATCH v3] gnu: home: Add support for home-pipewire-service
(address . 63863@debbugs.gnu.org)(name . Brian Cully)(address . bjc@spork.org)
1f25804bdd4994e607f701a4bad4085cb180bc39.1686835617.git.bjc@spork.org
This adds a set of home shepherd services which will start the required
services for a functional pipewire setup.

* gnu/home/services/sound.scm (home-pipewire-shepherd-service),
(home-pipewire-pulse-shepherd-service), (home-wireplumber-shepherd-service),
(home-pipewire-shepherd-services)
(home-pipewire-asoundrc), (home-pipewire-xdg-configuration): new procedures.
(home-pipewire-service-type): new service type.
(home-pipewire-configuration): new struct.
(home-pipewire-disable-pulseaudio-auto-start): new variable.
* doc/guix.texi (Sound Home Services): document it.
---
doc/guix.texi | 46 +++++++++++++++
gnu/home/services/sound.scm | 115 +++++++++++++++++++++++++++++++++++-
2 files changed, 160 insertions(+), 1 deletion(-)

Toggle diff (206 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index 9232c82b4b..c5e7066a4c 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -116,6 +116,7 @@
Copyright @copyright{} 2023 Karl Hallsby@*
Copyright @copyright{} 2023 Nathaniel Nicandro@*
Copyright @copyright{} 2023 Tanguy Le Carrour@*
+Copyright @copyright{} 2023 Brian Cully@*
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -43635,6 +43636,51 @@ Sound Home Services
This is the multicast address used by default by the two services above.
@end defvar
+@cindex PipeWire, home service
+
+@uref{https://pipewire.org, PipeWire} provides a low-latency,
+graph-based audio and video processing service. In addition to its
+native protocol, it can also be used as a replacement for both JACK and
+PulseAudio.
+
+While PipeWire provides the media processing and API, it does not,
+directly, know about devices such as sound cards, nor how you might want
+to connect applications, hardware, and media processing filters.
+Instead, PipeWire relies on a @dfn{session manager} to specify all these
+relationships. While you may use any session manager you wish, for most
+people the @url{https://pipewire.pages.freedesktop.org/wireplumber/,
+WirePlumber} session manager, a reference implementation provided by the
+PipeWire project itself, suffices, and that is the one
+@code{home-pipewire-service-type} uses.
+
+@defvar home-pipewire-service-type
+This provides the service definition for @command{pipewire}, which will
+run on login. Its value is a @code{home-pipewire-configuration} object.
+
+To start the service, add it to the @code{service} field of your
+@code{home-environment}, such as:
+
+@lisp
+(service home-pipewire-service-type)
+@end lisp
+@end defvar
+
+@deftp {Data Type} home-pipewire-configuration
+Available @code{home-pipewire-configuration} fields are:
+
+@table @asis
+@item @code{pipewire} (default: @code{pipewire}) (type: file-like)
+The PipeWire package to use.
+
+@item @code{wireplumber} (default: @code{wireplumber}) (type: file-like)
+The WirePlumber package to use.
+
+@item @code{enable-pulseaudio?} (default: @code{#t}) (type: boolean)
+When true, enable PipeWire's PulseAudio emulation support, allowing
+PulseAudio clients to use PipeWire transparently.
+@end table
+@end deftp
+
@node Mail Home Services
@subsection Mail Home Services
diff --git a/gnu/home/services/sound.scm b/gnu/home/services/sound.scm
index 22c1a99250..5463255e8c 100644
--- a/gnu/home/services/sound.scm
+++ b/gnu/home/services/sound.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2023 Brian Cully <bjc@spork.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -19,13 +20,125 @@
(define-module (gnu home services sound)
#:use-module (gnu home services)
#:use-module (gnu home services shepherd)
+ #:use-module (gnu home services xdg)
+ #:use-module (gnu packages linux)
+ #:use-module (gnu services configuration)
#:use-module (guix records)
#:use-module (guix gexp)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:export (home-pulseaudio-rtp-sink-service-type
home-pulseaudio-rtp-source-service-type
- %pulseaudio-rtp-multicast-address))
+ %pulseaudio-rtp-multicast-address
+
+ home-pipewire-configuration
+ home-pipewire-service-type))
+
+
+;;;
+;;; PipeWire support.
+;;;
+
+(define-configuration/no-serialization home-pipewire-configuration
+ (pipewire
+ (file-like pipewire)
+ "The PipeWire package to use.")
+ (wireplumber
+ (file-like wireplumber)
+ "The WirePlumber package to use.")
+ (enable-pulseaudio?
+ (boolean #t)
+ "When true, enable PipeWire's PulseAudio emulation support, allowing
+PulseAudio clients to use PipeWire transparently."))
+
+(define (home-pipewire-shepherd-service config)
+ (shepherd-service
+ (documentation "PipeWire media processing.")
+ (provision '(pipewire))
+ (requirement '(dbus))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-pulseaudio-shepherd-service config)
+ (shepherd-service
+ (documentation "Drop-in PulseAudio replacement service for PipeWire.")
+ (provision '(pipewire-pulseaudio))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire-pulse"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-wireplumber-shepherd-service config)
+ (shepherd-service
+ (documentation "WirePlumber session management for PipeWire.")
+ (provision '(wireplumber))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-wireplumber config)
+ "/bin/wireplumber"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-shepherd-services config)
+ (cons* (home-pipewire-shepherd-service config)
+ (home-wireplumber-shepherd-service config)
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ (list (home-pipewire-pulseaudio-shepherd-service config))
+ '())))
+
+(define (home-pipewire-asoundrc config)
+ (mixed-text-file
+ "asoundrc"
+ #~(string-append
+ "<"
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/share/alsa/alsa.conf.d/50-pipewire.conf")
+ ">\n"
+ "<"
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/share/alsa/alsa.conf.d/99-pipewire-default.conf")
+ ">\n"
+ "pcm_type.pipewire {\n"
+ " lib \""
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/lib/alsa-lib/libasound_module_pcm_pipewire.so")
+ "\"\n}\n"
+ "ctl_type.pipewire {\n"
+ " lib \""
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/lib/alsa-lib/libasound_module_ctl_pipewire.so")
+ "\"\n}\n")))
+
+(define home-pipewire-disable-pulseaudio-auto-start
+ (plain-file "client.conf" "autospawn = no"))
+
+(define (home-pipewire-xdg-configuration config)
+ (cons* `("alsa/asoundrc" ,(home-pipewire-asoundrc config))
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ `(("pulse/client.conf"
+ ,home-pipewire-disable-pulseaudio-auto-start))
+ '())))
+
+(define home-pipewire-service-type
+ (service-type
+ (name 'pipewire)
+ (extensions
+ (list (service-extension home-shepherd-service-type
+ home-pipewire-shepherd-services)
+ (service-extension home-xdg-configuration-files-service-type
+ home-pipewire-xdg-configuration)))
+ (description
+ "Start essential PipeWire services.")
+ (default-value (home-pipewire-configuration))))
;;;

base-commit: f74df2ab879fc5457982bbc85b7455a90e82317d
--
2.40.1
B
B
Brian Cully wrote on 15 Jun 2023 15:27
(name . Brian Cully)(address . bjc@spork.org)(address . 63863@debbugs.gnu.org)
877cs4etyh.fsf@psyduck.jhoto.kublai.com
The only changes in this version are two spaces after a period.

-bjc
B
B
Brian Cully wrote on 20 Jun 2023 14:41
[PATCH v4 0/1] gnu: home: Add support for home-pipewire-service
(address . 63863@debbugs.gnu.org)(name . Brian Cully)(address . bjc@spork.org)
cover.1687264416.git.bjc@spork.org
This patch iteration adds some more documentation. Specifically:

1) Explain why we need the Shepherd to start services,
2) document the Shepherd services started,
3) flesh out the JACK and PulseAudio emulation bits, and,
4) use @subsubheading to separate the PulseAudio RTP stuff from the
PipeWire stuff.

Regarding point 3, I looked at existing home-service documentation,
and used the style found in the shells section of the manual, rather
than trying to group everything under the @defvar for the
service-type, as is done in other parts (such as desktop services).

I did this because the sections in the sound services are more
verbose, so I felt it read better with @subsubheading where more
disparate topics could be synthesized into a more cohesive narrative
structure, leaving @defvar to explain the variables themselves. Also,
it meant I wouldn't have to make any major changes to the existing
PulseAudio RTP section, which I didn't write, and have only lightly
used.

Brian Cully (1):
gnu: home: Add support for home-pipewire-service

doc/guix.texi | 73 +++++++++++++++++++++++
gnu/home/services/sound.scm | 115 +++++++++++++++++++++++++++++++++++-
2 files changed, 187 insertions(+), 1 deletion(-)


base-commit: bb09f3ac002a4f34177d42fd3ea0332f4b7fe7a6
--
2.40.1
B
B
Brian Cully wrote on 20 Jun 2023 14:41
[PATCH v4 1/1] gnu: home: Add support for home-pipewire-service
(address . 63863@debbugs.gnu.org)(name . Brian Cully)(address . bjc@spork.org)
797ea363e1d7b7f467d0f201b8f8716593eb1bc4.1687264416.git.bjc@spork.org
This adds a set of home shepherd services which will start the required
services for a functional pipewire setup.

* gnu/home/services/sound.scm (home-pipewire-shepherd-service),
(home-pipewire-pulse-shepherd-service), (home-wireplumber-shepherd-service),
(home-pipewire-shepherd-services)
(home-pipewire-asoundrc), (home-pipewire-xdg-configuration): new procedures.
(home-pipewire-service-type): new service type.
(home-pipewire-configuration): new struct.
(home-pipewire-disable-pulseaudio-auto-start): new variable.
* doc/guix.texi (Sound Home Services): document it.
---
doc/guix.texi | 73 +++++++++++++++++++++++
gnu/home/services/sound.scm | 115 +++++++++++++++++++++++++++++++++++-
2 files changed, 187 insertions(+), 1 deletion(-)

Toggle diff (238 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index c961f706ec..97c3c85d79 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -116,6 +116,7 @@
Copyright @copyright{} 2023 Karl Hallsby@*
Copyright @copyright{} 2023 Nathaniel Nicandro@*
Copyright @copyright{} 2023 Tanguy Le Carrour@*
+Copyright @copyright{} 2023 Brian Cully@*
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -43678,6 +43679,7 @@ Sound Home Services
@cindex PulseAudio, home service
@cindex RTP, for PulseAudio
+@subsubheading PulseAudio RTP Streaming Services
The following services dynamically reconfigure the
@uref{https://pulseaudio.org,PulseAudio sound server}: they let you
@@ -43765,6 +43767,77 @@ Sound Home Services
This is the multicast address used by default by the two services above.
@end defvar
+@cindex PipeWire, home service
+@subsubheading PipeWire Home Service
+
+@uref{https://pipewire.org, PipeWire} provides a low-latency,
+graph-based audio and video processing service. In addition to its
+native protocol, it can also be used as a replacement for both JACK and
+PulseAudio.
+
+While PipeWire provides the media processing and API, it does not,
+directly, know about devices such as sound cards, nor how you might want
+to connect applications, hardware, and media processing filters.
+Instead, PipeWire relies on a @dfn{session manager} to specify all these
+relationships. While you may use any session manager you wish, for most
+people the @url{https://pipewire.pages.freedesktop.org/wireplumber/,
+WirePlumber} session manager, a reference implementation provided by the
+PipeWire project itself, suffices, and that is the one
+@code{home-pipewire-service-type} uses.
+
+PipeWire can be used as a replacement for PulseAudio by setting
+@code{enable-pulseaudio?} to @code{#t} in
+@code{home-pipewire-configuration}, so that existing PulseAudio clients
+may use it without any further configuration.
+
+In addition, JACK clients may connect to PipeWire by using the
+@command{pw-jack} program, which comes with PipeWire. Simply prefix the
+command with @command{pw-jack} when you run it, and audio data should go
+through PipeWire:
+
+@example
+pw-jack mpv -ao=jack sound-file.wav
+@end example
+
+For more information on PulseAudio emulation, see
+@uref{https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/Config-PulseAudio},
+for JACK, see
+@uref{https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/Config-JACK}.
+
+As PipeWire does not use @code{dbus} to start its services on demand
+(as PulseAudio does), @code{home-pipewire-service-type} uses Shepherd
+to start services when logged in, provisioning the @code{pipewire},
+@code{wireplumber}, and, if configured, @code{pipewire-pulseaudio}
+services. @xref{Shepherd Home Service}.
+
+@defvar home-pipewire-service-type
+This provides the service definition for @command{pipewire}, which will
+run on login. Its value is a @code{home-pipewire-configuration} object.
+
+To start the service, add it to the @code{service} field of your
+@code{home-environment}, such as:
+
+@lisp
+(service home-pipewire-service-type)
+@end lisp
+@end defvar
+
+@deftp {Data Type} home-pipewire-configuration
+Available @code{home-pipewire-configuration} fields are:
+
+@table @asis
+@item @code{pipewire} (default: @code{pipewire}) (type: file-like)
+The PipeWire package to use.
+
+@item @code{wireplumber} (default: @code{wireplumber}) (type: file-like)
+The WirePlumber package to use.
+
+@item @code{enable-pulseaudio?} (default: @code{#t}) (type: boolean)
+When true, enable PipeWire's PulseAudio emulation support, allowing
+PulseAudio clients to use PipeWire transparently.
+@end table
+@end deftp
+
@node Mail Home Services
@subsection Mail Home Services
diff --git a/gnu/home/services/sound.scm b/gnu/home/services/sound.scm
index 22c1a99250..5463255e8c 100644
--- a/gnu/home/services/sound.scm
+++ b/gnu/home/services/sound.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2023 Brian Cully <bjc@spork.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -19,13 +20,125 @@
(define-module (gnu home services sound)
#:use-module (gnu home services)
#:use-module (gnu home services shepherd)
+ #:use-module (gnu home services xdg)
+ #:use-module (gnu packages linux)
+ #:use-module (gnu services configuration)
#:use-module (guix records)
#:use-module (guix gexp)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:export (home-pulseaudio-rtp-sink-service-type
home-pulseaudio-rtp-source-service-type
- %pulseaudio-rtp-multicast-address))
+ %pulseaudio-rtp-multicast-address
+
+ home-pipewire-configuration
+ home-pipewire-service-type))
+
+
+;;;
+;;; PipeWire support.
+;;;
+
+(define-configuration/no-serialization home-pipewire-configuration
+ (pipewire
+ (file-like pipewire)
+ "The PipeWire package to use.")
+ (wireplumber
+ (file-like wireplumber)
+ "The WirePlumber package to use.")
+ (enable-pulseaudio?
+ (boolean #t)
+ "When true, enable PipeWire's PulseAudio emulation support, allowing
+PulseAudio clients to use PipeWire transparently."))
+
+(define (home-pipewire-shepherd-service config)
+ (shepherd-service
+ (documentation "PipeWire media processing.")
+ (provision '(pipewire))
+ (requirement '(dbus))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-pulseaudio-shepherd-service config)
+ (shepherd-service
+ (documentation "Drop-in PulseAudio replacement service for PipeWire.")
+ (provision '(pipewire-pulseaudio))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire-pulse"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-wireplumber-shepherd-service config)
+ (shepherd-service
+ (documentation "WirePlumber session management for PipeWire.")
+ (provision '(wireplumber))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-wireplumber config)
+ "/bin/wireplumber"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-shepherd-services config)
+ (cons* (home-pipewire-shepherd-service config)
+ (home-wireplumber-shepherd-service config)
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ (list (home-pipewire-pulseaudio-shepherd-service config))
+ '())))
+
+(define (home-pipewire-asoundrc config)
+ (mixed-text-file
+ "asoundrc"
+ #~(string-append
+ "<"
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/share/alsa/alsa.conf.d/50-pipewire.conf")
+ ">\n"
+ "<"
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/share/alsa/alsa.conf.d/99-pipewire-default.conf")
+ ">\n"
+ "pcm_type.pipewire {\n"
+ " lib \""
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/lib/alsa-lib/libasound_module_pcm_pipewire.so")
+ "\"\n}\n"
+ "ctl_type.pipewire {\n"
+ " lib \""
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/lib/alsa-lib/libasound_module_ctl_pipewire.so")
+ "\"\n}\n")))
+
+(define home-pipewire-disable-pulseaudio-auto-start
+ (plain-file "client.conf" "autospawn = no"))
+
+(define (home-pipewire-xdg-configuration config)
+ (cons* `("alsa/asoundrc" ,(home-pipewire-asoundrc config))
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ `(("pulse/client.conf"
+ ,home-pipewire-disable-pulseaudio-auto-start))
+ '())))
+
+(define home-pipewire-service-type
+ (service-type
+ (name 'pipewire)
+ (extensions
+ (list (service-extension home-shepherd-service-type
+ home-pipewire-shepherd-services)
+ (service-extension home-xdg-configuration-files-service-type
+ home-pipewire-xdg-configuration)))
+ (description
+ "Start essential PipeWire services.")
+ (default-value (home-pipewire-configuration))))
;;;
--
2.40.1
B
B
Brian Cully wrote on 2 Jul 2023 14:39
[PATCH v5 0/1] gnu: home: Add support for home-pipewire-service
(address . 63863@debbugs.gnu.org)(name . Brian Cully)(address . bjc@spork.org)
cover.1688301546.git.bjc@spork.org
Two sentences were missing a double space after a period. Otherwise
this is unchanged from v4.

Are there any remaining issues to be addressed, or can this finally be
merged?

Brian Cully (1):
gnu: home: Add support for home-pipewire-service

doc/guix.texi | 73 +++++++++++++++++++++++
gnu/home/services/sound.scm | 115 +++++++++++++++++++++++++++++++++++-
2 files changed, 187 insertions(+), 1 deletion(-)


base-commit: a919a16898e7219fdd26bdfe33a9959e7156d59d
--
2.40.1
B
B
Brian Cully wrote on 2 Jul 2023 14:39
[PATCH v5 1/1] gnu: home: Add support for home-pipewire-service
(address . 63863@debbugs.gnu.org)(name . Brian Cully)(address . bjc@spork.org)
1023a7ef7f4612d8f7c08c2a4f9a39591263c284.1688301546.git.bjc@spork.org
This adds a set of home shepherd services which will start the required
services for a functional pipewire setup.

* gnu/home/services/sound.scm (home-pipewire-shepherd-service),
(home-pipewire-pulse-shepherd-service), (home-wireplumber-shepherd-service),
(home-pipewire-shepherd-services)
(home-pipewire-asoundrc), (home-pipewire-xdg-configuration): new procedures.
(home-pipewire-service-type): new service type.
(home-pipewire-configuration): new struct.
(home-pipewire-disable-pulseaudio-auto-start): new variable.
* doc/guix.texi (Sound Home Services): document it.
---
doc/guix.texi | 73 +++++++++++++++++++++++
gnu/home/services/sound.scm | 115 +++++++++++++++++++++++++++++++++++-
2 files changed, 187 insertions(+), 1 deletion(-)

Toggle diff (238 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index 853396f776..7a6b7ebc3a 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -116,6 +116,7 @@
Copyright @copyright{} 2023 Karl Hallsby@*
Copyright @copyright{} 2023 Nathaniel Nicandro@*
Copyright @copyright{} 2023 Tanguy Le Carrour@*
+Copyright @copyright{} 2023 Brian Cully@*
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -43742,6 +43743,7 @@ Sound Home Services
@cindex PulseAudio, home service
@cindex RTP, for PulseAudio
+@subsubheading PulseAudio RTP Streaming Services
The following services dynamically reconfigure the
@uref{https://pulseaudio.org,PulseAudio sound server}: they let you
@@ -43829,6 +43831,77 @@ Sound Home Services
This is the multicast address used by default by the two services above.
@end defvar
+@cindex PipeWire, home service
+@subsubheading PipeWire Home Service
+
+@uref{https://pipewire.org, PipeWire} provides a low-latency,
+graph-based audio and video processing service. In addition to its
+native protocol, it can also be used as a replacement for both JACK and
+PulseAudio.
+
+While PipeWire provides the media processing and API, it does not,
+directly, know about devices such as sound cards, nor how you might want
+to connect applications, hardware, and media processing filters.
+Instead, PipeWire relies on a @dfn{session manager} to specify all these
+relationships. While you may use any session manager you wish, for most
+people the @url{https://pipewire.pages.freedesktop.org/wireplumber/,
+WirePlumber} session manager, a reference implementation provided by the
+PipeWire project itself, suffices, and that is the one
+@code{home-pipewire-service-type} uses.
+
+PipeWire can be used as a replacement for PulseAudio by setting
+@code{enable-pulseaudio?} to @code{#t} in
+@code{home-pipewire-configuration}, so that existing PulseAudio clients
+may use it without any further configuration.
+
+In addition, JACK clients may connect to PipeWire by using the
+@command{pw-jack} program, which comes with PipeWire. Simply prefix the
+command with @command{pw-jack} when you run it, and audio data should go
+through PipeWire:
+
+@example
+pw-jack mpv -ao=jack sound-file.wav
+@end example
+
+For more information on PulseAudio emulation, see
+@uref{https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/Config-PulseAudio},
+for JACK, see
+@uref{https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/Config-JACK}.
+
+As PipeWire does not use @code{dbus} to start its services on demand
+(as PulseAudio does), @code{home-pipewire-service-type} uses Shepherd
+to start services when logged in, provisioning the @code{pipewire},
+@code{wireplumber}, and, if configured, @code{pipewire-pulseaudio}
+services. @xref{Shepherd Home Service}.
+
+@defvar home-pipewire-service-type
+This provides the service definition for @command{pipewire}, which will
+run on login. Its value is a @code{home-pipewire-configuration} object.
+
+To start the service, add it to the @code{service} field of your
+@code{home-environment}, such as:
+
+@lisp
+(service home-pipewire-service-type)
+@end lisp
+@end defvar
+
+@deftp {Data Type} home-pipewire-configuration
+Available @code{home-pipewire-configuration} fields are:
+
+@table @asis
+@item @code{pipewire} (default: @code{pipewire}) (type: file-like)
+The PipeWire package to use.
+
+@item @code{wireplumber} (default: @code{wireplumber}) (type: file-like)
+The WirePlumber package to use.
+
+@item @code{enable-pulseaudio?} (default: @code{#t}) (type: boolean)
+When true, enable PipeWire's PulseAudio emulation support, allowing
+PulseAudio clients to use PipeWire transparently.
+@end table
+@end deftp
+
@node Mail Home Services
@subsection Mail Home Services
diff --git a/gnu/home/services/sound.scm b/gnu/home/services/sound.scm
index 22c1a99250..5463255e8c 100644
--- a/gnu/home/services/sound.scm
+++ b/gnu/home/services/sound.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2023 Brian Cully <bjc@spork.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -19,13 +20,125 @@
(define-module (gnu home services sound)
#:use-module (gnu home services)
#:use-module (gnu home services shepherd)
+ #:use-module (gnu home services xdg)
+ #:use-module (gnu packages linux)
+ #:use-module (gnu services configuration)
#:use-module (guix records)
#:use-module (guix gexp)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:export (home-pulseaudio-rtp-sink-service-type
home-pulseaudio-rtp-source-service-type
- %pulseaudio-rtp-multicast-address))
+ %pulseaudio-rtp-multicast-address
+
+ home-pipewire-configuration
+ home-pipewire-service-type))
+
+
+;;;
+;;; PipeWire support.
+;;;
+
+(define-configuration/no-serialization home-pipewire-configuration
+ (pipewire
+ (file-like pipewire)
+ "The PipeWire package to use.")
+ (wireplumber
+ (file-like wireplumber)
+ "The WirePlumber package to use.")
+ (enable-pulseaudio?
+ (boolean #t)
+ "When true, enable PipeWire's PulseAudio emulation support, allowing
+PulseAudio clients to use PipeWire transparently."))
+
+(define (home-pipewire-shepherd-service config)
+ (shepherd-service
+ (documentation "PipeWire media processing.")
+ (provision '(pipewire))
+ (requirement '(dbus))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-pulseaudio-shepherd-service config)
+ (shepherd-service
+ (documentation "Drop-in PulseAudio replacement service for PipeWire.")
+ (provision '(pipewire-pulseaudio))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire-pulse"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-wireplumber-shepherd-service config)
+ (shepherd-service
+ (documentation "WirePlumber session management for PipeWire.")
+ (provision '(wireplumber))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-wireplumber config)
+ "/bin/wireplumber"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-shepherd-services config)
+ (cons* (home-pipewire-shepherd-service config)
+ (home-wireplumber-shepherd-service config)
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ (list (home-pipewire-pulseaudio-shepherd-service config))
+ '())))
+
+(define (home-pipewire-asoundrc config)
+ (mixed-text-file
+ "asoundrc"
+ #~(string-append
+ "<"
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/share/alsa/alsa.conf.d/50-pipewire.conf")
+ ">\n"
+ "<"
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/share/alsa/alsa.conf.d/99-pipewire-default.conf")
+ ">\n"
+ "pcm_type.pipewire {\n"
+ " lib \""
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/lib/alsa-lib/libasound_module_pcm_pipewire.so")
+ "\"\n}\n"
+ "ctl_type.pipewire {\n"
+ " lib \""
+ #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/lib/alsa-lib/libasound_module_ctl_pipewire.so")
+ "\"\n}\n")))
+
+(define home-pipewire-disable-pulseaudio-auto-start
+ (plain-file "client.conf" "autospawn = no"))
+
+(define (home-pipewire-xdg-configuration config)
+ (cons* `("alsa/asoundrc" ,(home-pipewire-asoundrc config))
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ `(("pulse/client.conf"
+ ,home-pipewire-disable-pulseaudio-auto-start))
+ '())))
+
+(define home-pipewire-service-type
+ (service-type
+ (name 'pipewire)
+ (extensions
+ (list (service-extension home-shepherd-service-type
+ home-pipewire-shepherd-services)
+ (service-extension home-xdg-configuration-files-service-type
+ home-pipewire-xdg-configuration)))
+ (description
+ "Start essential PipeWire services.")
+ (default-value (home-pipewire-configuration))))
;;;
--
2.40.1
T
T
Tanguy LE CARROUR wrote on 23 Aug 2023 10:25
(name . Brian Cully)(address . bjc@spork.org)(address . 63863@debbugs.gnu.org)
169277912935.12471.14366434028428015342@localhost
Hi Brian,

I came across you patch by chance and, as I had been waiting for a
PipeWire home service for a long time, I couldn't resist trying it out!

I copied it to my channel, added it to my home configuration,
reconfigured and… go this message:

```
guix home: error: service 'pipewire' requires 'dbus', which is not provided by any service
```

I was a little confused, because in the documentation, you wrote
"As PipeWire does not use @code{dbus} to start its services on demand".

I added it anyway, reconfigured and after rebooting (I currently have a
problem with shepherd not being properly reloaded! ?) I can see
the new services as being "stopped" in `herd status` output.
Are they stopped on purpose? Who is supposed to start them?
Sorry, I'm not sure I understand how it's supposed to work.
I've tried joining a JitsiMeet conference. The video seems to be
working, but my mic‘ is marked as "broken".

I've had to roll back my home configuration for the time being,
but if there are more things I can try to make it work and help your
patch being merged, I would be more than happy to try them!

Anyway, thanks for you work on this patch! Can't wait for it to be
merged.

--
Tanguy
B
(name . Tanguy LE CARROUR)(address . tanguy@bioneland.org)(address . 63863@debbugs.gnu.org)
87sf89bntk.fsf@spork.org
Tanguy LE CARROUR <tanguy@bioneland.org> writes:

Toggle quote (3 lines)
> I came across you patch by chance and, as I had been waiting for a
> PipeWire home service for a long time, I couldn't resist trying it out!

Thanks for helping test it!

Toggle quote (10 lines)
> I copied it to my channel, added it to my home configuration,
> reconfigured and… go this message:
>
> ```
> guix home: error: service 'pipewire' requires 'dbus', which is not provided by any service
> ```
>
> I was a little confused, because in the documentation, you wrote
> "As PipeWire does not use @code{dbus} to start its services on demand".

Pipewire does not use dbus to start its services on demand, but it does
use it for communication between the pipewire daemon itself and the
session manager (typically wireplumber).

I guess this is confusing. I'll see if I can explain this
better. Although part of me wants to drop the dbus verbiage from the
documentation entirely, since it only exists right now to explain things
to people who might be migrating from Pulseaudio and used to not needing
a Shepherd service. I don't want to write a deep explainer on how DBus
is used. It's not the place for that, nor do I even know that much about
it.

Toggle quote (5 lines)
> I added it anyway, reconfigured and after rebooting (I currently have a
> problem with shepherd not being properly reloaded! ?) I can see
> the new services as being "stopped" in `herd status` output.
> Are they stopped on purpose? Who is supposed to start them?

The services should all start automatically, but they do all depend on
a user-session level dbus daemon running. I see you're using dbus, but
are you using it from ‘home-dbus-service-type’?

Toggle quote (4 lines)
> Sorry, I'm not sure I understand how it's supposed to work.
> I've tried joining a JitsiMeet conference. The video seems to be
> working, but my mic‘ is marked as "broken".

If video sharing under Wayland is working, then I'd say that means
Pipewire+Wireguard are working. The mic doesn't work, but can you hear
audio through your speakers or headphones? Are your audio devices
visible? Are you using Pulseaudio emulation (which I recommend you do)?

Toggle quote (3 lines)
> Anyway, thanks for you work on this patch! Can't wait for it to be
> merged.

/me pokes Ludo ?

-bjc
T
T
Tanguy LE CARROUR wrote on 25 Aug 2023 08:44
(name . brian)(address . bjc@spork.org)(address . 63863@debbugs.gnu.org)
169294584661.1605.10650518560015904738@bioneland.org
Hi Brian,


Quoting brian (2023-08-23 20:44:55)
Toggle quote (23 lines)
> Tanguy LE CARROUR <tanguy@bioneland.org> writes:
> > I copied it to my channel, added it to my home configuration,
> > reconfigured and… go this message:
> >
> > ```
> > guix home: error: service 'pipewire' requires 'dbus', which is not provided by any service
> > ```
> >
> > I was a little confused, because in the documentation, you wrote
> > "As PipeWire does not use @code{dbus} to start its services on demand".
>
> Pipewire does not use dbus to start its services on demand, but it does
> use it for communication between the pipewire daemon itself and the
> session manager (typically wireplumber).
>
> I guess this is confusing. I'll see if I can explain this
> better. Although part of me wants to drop the dbus verbiage from the
> documentation entirely, since it only exists right now to explain things
> to people who might be migrating from Pulseaudio and used to not needing
> a Shepherd service. I don't want to write a deep explainer on how DBus
> is used. It's not the place for that, nor do I even know that much about
> it.

It's a bit confusing, indeed! … but I'm easily confused! ?
What would be great would a mechanism to "pull/manage" service dependencies.


Toggle quote (9 lines)
> > I added it anyway, reconfigured and after rebooting (I currently have a
> > problem with shepherd not being properly reloaded! ?) I can see
> > the new services as being "stopped" in `herd status` output.
> > Are they stopped on purpose? Who is supposed to start them?
>
> The services should all start automatically, but they do all depend on
> a user-session level dbus daemon running. I see you're using dbus, but
> are you using it from ‘home-dbus-service-type’?

Yes, I added it in my home configuration.


Toggle quote (9 lines)
> > Sorry, I'm not sure I understand how it's supposed to work.
> > I've tried joining a JitsiMeet conference. The video seems to be
> > working, but my mic‘ is marked as "broken".
>
> If video sharing under Wayland is working, then I'd say that means
> Pipewire+Wireguard are working. The mic doesn't work, but can you hear
> audio through your speakers or headphones? Are your audio devices
> visible? Are you using Pulseaudio emulation (which I recommend you do)?

I'll give it another try at the week-end! ?


Toggle quote (5 lines)
> > Anyway, thanks for you work on this patch! Can't wait for it to be
> > merged.
>
> /me pokes Ludo ?

Poke poke ?


--
Tanguy
T
T
taosabella wrote on 11 Oct 2023 13:34
Re: [bug#63863] [PATCH v5 1/1] gnu: home: Add support for home-pipewire-service
(address . 63863@debbugs.gnu.org)
0bd2f596e130cd8522e74fc6839596a0@riseup.net
I've tested this patch and it works perfectly, with all Shepherd
services starting after activation and a reboot. Ludovic, are there any
other blockers to getting this into Guix proper?
J
J
Jakob Honal wrote on 5 Nov 2023 16:09
(no subject)
(address . 63863@debbugs.gnu.org)
trinity-2ed51d6c-1ba1-4030-9291-0045924f852e-1699196988425@3c-app-gmx-bs51
Attachment: file
H
H
Hilton Chain wrote on 12 Nov 2023 15:14
Re: [bug#63863] [PATCH v5 1/1] gnu: home: Add support for home-pipewire-service
(name . Brian Cully)(address . bjc@spork.org)(address . 63863@debbugs.gnu.org)
87y1f383er.wl-hako@ultrarare.space
Hi Brian,

Tested the patch in my setup, it works well :)

(Some comments are in and after the quote.)

On Sun, 02 Jul 2023 20:39:41 +0800,
Brian Cully via Guix-patches via wrote:
Toggle quote (230 lines)
>
> This adds a set of home shepherd services which will start the required
> services for a functional pipewire setup.
>
> * gnu/home/services/sound.scm (home-pipewire-shepherd-service),
> (home-pipewire-pulse-shepherd-service), (home-wireplumber-shepherd-service),
> (home-pipewire-shepherd-services)
> (home-pipewire-asoundrc), (home-pipewire-xdg-configuration): new procedures.
> (home-pipewire-service-type): new service type.
> (home-pipewire-configuration): new struct.
> (home-pipewire-disable-pulseaudio-auto-start): new variable.
> * doc/guix.texi (Sound Home Services): document it.
> ---
> doc/guix.texi | 73 +++++++++++++++++++++++
> gnu/home/services/sound.scm | 115 +++++++++++++++++++++++++++++++++++-
> 2 files changed, 187 insertions(+), 1 deletion(-)
>
> diff --git a/doc/guix.texi b/doc/guix.texi
> index 853396f776..7a6b7ebc3a 100644
> --- a/doc/guix.texi
> +++ b/doc/guix.texi
> @@ -116,6 +116,7 @@
> Copyright @copyright{} 2023 Karl Hallsby@*
> Copyright @copyright{} 2023 Nathaniel Nicandro@*
> Copyright @copyright{} 2023 Tanguy Le Carrour@*
> +Copyright @copyright{} 2023 Brian Cully@*
>
> Permission is granted to copy, distribute and/or modify this document
> under the terms of the GNU Free Documentation License, Version 1.3 or
> @@ -43742,6 +43743,7 @@ Sound Home Services
>
> @cindex PulseAudio, home service
> @cindex RTP, for PulseAudio
> +@subsubheading PulseAudio RTP Streaming Services
>
> The following services dynamically reconfigure the
> @uref{https://pulseaudio.org,PulseAudio sound server}: they let you
> @@ -43829,6 +43831,77 @@ Sound Home Services
> This is the multicast address used by default by the two services above.
> @end defvar
>
> +@cindex PipeWire, home service
> +@subsubheading PipeWire Home Service
> +
> +@uref{https://pipewire.org, PipeWire} provides a low-latency,
> +graph-based audio and video processing service. In addition to its
> +native protocol, it can also be used as a replacement for both JACK and
> +PulseAudio.
> +
> +While PipeWire provides the media processing and API, it does not,
> +directly, know about devices such as sound cards, nor how you might want
> +to connect applications, hardware, and media processing filters.
> +Instead, PipeWire relies on a @dfn{session manager} to specify all these
> +relationships. While you may use any session manager you wish, for most
> +people the @url{https://pipewire.pages.freedesktop.org/wireplumber/,
> +WirePlumber} session manager, a reference implementation provided by the
> +PipeWire project itself, suffices, and that is the one
> +@code{home-pipewire-service-type} uses.
> +
> +PipeWire can be used as a replacement for PulseAudio by setting
> +@code{enable-pulseaudio?} to @code{#t} in
> +@code{home-pipewire-configuration}, so that existing PulseAudio clients
> +may use it without any further configuration.
> +
> +In addition, JACK clients may connect to PipeWire by using the
> +@command{pw-jack} program, which comes with PipeWire. Simply prefix the
> +command with @command{pw-jack} when you run it, and audio data should go
> +through PipeWire:
> +
> +@example
> +pw-jack mpv -ao=jack sound-file.wav
> +@end example
> +
> +For more information on PulseAudio emulation, see
> +@uref{https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/Config-PulseAudio},
> +for JACK, see
> +@uref{https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/Config-JACK}.
> +
> +As PipeWire does not use @code{dbus} to start its services on demand
> +(as PulseAudio does), @code{home-pipewire-service-type} uses Shepherd
> +to start services when logged in, provisioning the @code{pipewire},
> +@code{wireplumber}, and, if configured, @code{pipewire-pulseaudio}
> +services. @xref{Shepherd Home Service}.
> +
> +@defvar home-pipewire-service-type
> +This provides the service definition for @command{pipewire}, which will
> +run on login. Its value is a @code{home-pipewire-configuration} object.
> +
> +To start the service, add it to the @code{service} field of your
> +@code{home-environment}, such as:
> +
> +@lisp
> +(service home-pipewire-service-type)
> +@end lisp
> +@end defvar
> +
> +@deftp {Data Type} home-pipewire-configuration
> +Available @code{home-pipewire-configuration} fields are:
> +
> +@table @asis
> +@item @code{pipewire} (default: @code{pipewire}) (type: file-like)
> +The PipeWire package to use.
> +
> +@item @code{wireplumber} (default: @code{wireplumber}) (type: file-like)
> +The WirePlumber package to use.
> +
> +@item @code{enable-pulseaudio?} (default: @code{#t}) (type: boolean)
> +When true, enable PipeWire's PulseAudio emulation support, allowing
> +PulseAudio clients to use PipeWire transparently.
> +@end table
> +@end deftp
> +
> @node Mail Home Services
> @subsection Mail Home Services
>
> diff --git a/gnu/home/services/sound.scm b/gnu/home/services/sound.scm
> index 22c1a99250..5463255e8c 100644
> --- a/gnu/home/services/sound.scm
> +++ b/gnu/home/services/sound.scm
> @@ -1,5 +1,6 @@
> ;;; GNU Guix --- Functional package management for GNU
> ;;; Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
> +;;; Copyright © 2023 Brian Cully <bjc@spork.org>
> ;;;
> ;;; This file is part of GNU Guix.
> ;;;
> @@ -19,13 +20,125 @@
> (define-module (gnu home services sound)
> #:use-module (gnu home services)
> #:use-module (gnu home services shepherd)
> + #:use-module (gnu home services xdg)
> + #:use-module (gnu packages linux)
> + #:use-module (gnu services configuration)
> #:use-module (guix records)
> #:use-module (guix gexp)
> #:use-module (srfi srfi-1)
> #:use-module (ice-9 match)
> #:export (home-pulseaudio-rtp-sink-service-type
> home-pulseaudio-rtp-source-service-type
> - %pulseaudio-rtp-multicast-address))
> + %pulseaudio-rtp-multicast-address
> +
> + home-pipewire-configuration
> + home-pipewire-service-type))
> +
> +
> +;;;
> +;;; PipeWire support.
> +;;;
> +
> +(define-configuration/no-serialization home-pipewire-configuration
> + (pipewire
> + (file-like pipewire)
> + "The PipeWire package to use.")
> + (wireplumber
> + (file-like wireplumber)
> + "The WirePlumber package to use.")
> + (enable-pulseaudio?
> + (boolean #t)
> + "When true, enable PipeWire's PulseAudio emulation support, allowing
> +PulseAudio clients to use PipeWire transparently."))
> +
> +(define (home-pipewire-shepherd-service config)
> + (shepherd-service
> + (documentation "PipeWire media processing.")
> + (provision '(pipewire))
> + (requirement '(dbus))
> + (start #~(make-forkexec-constructor
> + (list #$(file-append
> + (home-pipewire-configuration-pipewire config)
> + "/bin/pipewire"))))
> + (stop #~(make-kill-destructor))))
> +
> +(define (home-pipewire-pulseaudio-shepherd-service config)
> + (shepherd-service
> + (documentation "Drop-in PulseAudio replacement service for PipeWire.")
> + (provision '(pipewire-pulseaudio))
> + (requirement '(pipewire))
> + (start #~(make-forkexec-constructor
> + (list #$(file-append
> + (home-pipewire-configuration-pipewire config)
> + "/bin/pipewire-pulse"))))
> + (stop #~(make-kill-destructor))))
> +
> +(define (home-wireplumber-shepherd-service config)
> + (shepherd-service
> + (documentation "WirePlumber session management for PipeWire.")
> + (provision '(wireplumber))
> + (requirement '(pipewire))
> + (start #~(make-forkexec-constructor
> + (list #$(file-append
> + (home-pipewire-configuration-wireplumber config)
> + "/bin/wireplumber"))))
> + (stop #~(make-kill-destructor))))
> +
> +(define (home-pipewire-shepherd-services config)
> + (cons* (home-pipewire-shepherd-service config)
> + (home-wireplumber-shepherd-service config)
> + (if (home-pipewire-configuration-enable-pulseaudio? config)
> + (list (home-pipewire-pulseaudio-shepherd-service config))
> + '())))
> +
> +(define (home-pipewire-asoundrc config)
> + (mixed-text-file
> + "asoundrc"
> + #~(string-append
> + "<"
> + #$(file-append
> + (home-pipewire-configuration-pipewire config)
> + "/share/alsa/alsa.conf.d/50-pipewire.conf")
> + ">\n"
> + "<"
> + #$(file-append
> + (home-pipewire-configuration-pipewire config)
> + "/share/alsa/alsa.conf.d/99-pipewire-default.conf")
> + ">\n"
> + "pcm_type.pipewire {\n"
> + " lib \""
> + #$(file-append
> + (home-pipewire-configuration-pipewire config)
> + "/lib/alsa-lib/libasound_module_pcm_pipewire.so")
> + "\"\n}\n"
> + "ctl_type.pipewire {\n"
> + " lib \""
> + #$(file-append
> + (home-pipewire-configuration-pipewire config)
> + "/lib/alsa-lib/libasound_module_ctl_pipewire.so")
> + "\"\n}\n")))


I'd prefer the following:
Toggle snippet (15 lines)
(define (home-pipewire-asoundrc config)
(match-record config <home-pipewire-configuration>
(pipewire)
(mixed-text-file
"asoundrc"
"<" pipewire "/share/alsa/alsa.conf.d/50-pipewire.conf>\n"
"<" pipewire "/share/alsa/alsa.conf.d/99-pipewire-default.conf>\n"
"pcm_type.pipewire {\n"
" lib \"" pipewire "/lib/alsa-lib/libasound_module_pcm_pipewire.so\"\n"
"}\n"
"ctl_type.pipewire {\n"
" lib \"" pipewire "/lib/alsa-lib/libasound_module_ctl_pipewire.so\"\n"
"}\n")))

or:
Toggle snippet (19 lines)
(define (home-pipewire-asoundrc config)
(match-record config <home-pipewire-configuration>
(pipewire)
(mixed-text-file
"asoundrc"
#~(begin
(use-modules (ice-9 format))
(format #f "~
<~a/share/alsa/alsa.conf.d/50-pipewire.conf>
<~@*~a/share/alsa/alsa.conf.d/99-pipewire-default.conf>
pcm_type.pipewire {
lib \"~@*~a/lib/alsa-lib/libasound_module_pcm_pipewire.so\"
}
ctl_type.pipewire {
lib \"~@*~a/lib/alsa-lib/libasound_module_ctl_pipewire.so\"
}~%" #$pipewire)))))


Toggle quote (29 lines)
> +
> +(define home-pipewire-disable-pulseaudio-auto-start
> + (plain-file "client.conf" "autospawn = no"))
> +
> +(define (home-pipewire-xdg-configuration config)
> + (cons* `("alsa/asoundrc" ,(home-pipewire-asoundrc config))
> + (if (home-pipewire-configuration-enable-pulseaudio? config)
> + `(("pulse/client.conf"
> + ,home-pipewire-disable-pulseaudio-auto-start))
> + '())))
> +
> +(define home-pipewire-service-type
> + (service-type
> + (name 'pipewire)
> + (extensions
> + (list (service-extension home-shepherd-service-type
> + home-pipewire-shepherd-services)
> + (service-extension home-xdg-configuration-files-service-type
> + home-pipewire-xdg-configuration)))
> + (description
> + "Start essential PipeWire services.")
> + (default-value (home-pipewire-configuration))))
>
>
> ;;;
> --
> 2.40.1


One thing to note: the wireplumber package is built with elogind integration, so
it fails to start when elogind is not present:
Toggle snippet (3 lines)
[wireplumber] failed to start systemd logind monitor: -2 (No such file or directory)

I think we can add a wireplumber variant built with "-Delogind=disabled" and
maybe mention it in the documentation.

Thanks
B
B
Brian Cully wrote on 16 Dec 2023 16:17
(name . Hilton Chain)(address . hako@ultrarare.space)(address . 63863@debbugs.gnu.org)
9E63989C-2927-45B5-B1BF-5C5E8FF1D5C1@spork.org
Hilton Chain <hako@ultrarare.space> writes:

Toggle quote (36 lines)
> I'd prefer the following:
>
> (define (home-pipewire-asoundrc config)
> (match-record config <home-pipewire-configuration>
> (pipewire)
> (mixed-text-file
> "asoundrc"
> "<" pipewire "/share/alsa/alsa.conf.d/50-pipewire.conf>\n"
> "<" pipewire "/share/alsa/alsa.conf.d/99-pipewire-default.conf>\n"
> "pcm_type.pipewire {\n"
> " lib \"" pipewire "/lib/alsa-lib/libasound_module_pcm_pipewire.so\"\n"
> "}\n"
> "ctl_type.pipewire {\n"
> " lib \"" pipewire "/lib/alsa-lib/libasound_module_ctl_pipewire.so\"\n"
> "}\n")))
>
>
> or:
>
> (define (home-pipewire-asoundrc config)
> (match-record config <home-pipewire-configuration>
> (pipewire)
> (mixed-text-file
> "asoundrc"
> #~(begin
> (use-modules (ice-9 format))
> (format #f "~
> <~a/share/alsa/alsa.conf.d/50-pipewire.conf>
> <~@*~a/share/alsa/alsa.conf.d/99-pipewire-default.conf>
> pcm_type.pipewire {
> lib \"~@*~a/lib/alsa-lib/libasound_module_pcm_pipewire.so\"
> }
> ctl_type.pipewire {
> lib \"~@*~a/lib/alsa-lib/libasound_module_ctl_pipewire.so\"
> }~%" #$pipewire)))))

I prefer the former to the latter; I often find ‘format’ strings to be pretty confusing, and the documentation doesn't tend to help much. I know I'm not alone in this, and since this is fairly simple, I'll use the straight concatenation, which has the additional benefit of preserving indentation.

Toggle quote (8 lines)
> One thing to note: the wireplumber package is built with elogind integration, so
> it fails to start when elogind is not present:
>
> [wireplumber] failed to start systemd logind monitor: -2 (No such file or directory)
>
> I think we can add a wireplumber variant built with "-Delogind=disabled" and
> maybe mention it in the documentation.

Sounds reasonable. I don't know how long wireplumber has been able to be built without systemd stuff, just that I tried running it with seatd/greetd and it failed. Have you got it working without elogind?

I'm not sure when I'll be able to have a look at it, so I'd rather the current patch go in, and we can add elogind-less variants afterwards.

--
-bjc
B
B
Brian Cully wrote on 16 Dec 2023 16:23
[PATCH v6] gnu: home: Add support for home-pipewire-service
(address . 63863@debbugs.gnu.org)(name . Brian Cully)(address . bjc@spork.org)
bbb613b6d406c2a25534d25be224f6b9e4a64629.1702740217.git.bjc@spork.org
This adds a set of home shepherd services which will start the required
services for a functional pipewire setup.

* gnu/home/services/sound.scm (home-pipewire-shepherd-service),
(home-pipewire-pulse-shepherd-service), (home-wireplumber-shepherd-service),
(home-pipewire-shepherd-services)
(home-pipewire-asoundrc), (home-pipewire-xdg-configuration): new procedures.
(home-pipewire-service-type): new service type.
(home-pipewire-configuration): new struct.
(home-pipewire-disable-pulseaudio-auto-start): new variable.
* doc/guix.texi (Sound Home Services): document it.

Change-Id: I99e0ae860de91d459c3c554ec5503bf35f785a2a
---
doc/guix.texi | 72 +++++++++++++++++++++++++
gnu/home/services/sound.scm | 102 +++++++++++++++++++++++++++++++++++-
2 files changed, 173 insertions(+), 1 deletion(-)

Toggle diff (219 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index e61a893af9..90888a514f 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -45050,6 +45050,7 @@ Sound Home Services
@cindex PulseAudio, home service
@cindex RTP, for PulseAudio
+@subsubheading PulseAudio RTP Streaming Services
The following services dynamically reconfigure the
@uref{https://pulseaudio.org,PulseAudio sound server}: they let you
@@ -45137,6 +45138,77 @@ Sound Home Services
This is the multicast address used by default by the two services above.
@end defvar
+@cindex PipeWire, home service
+@subsubheading PipeWire Home Service
+
+@uref{https://pipewire.org, PipeWire} provides a low-latency,
+graph-based audio and video processing service. In addition to its
+native protocol, it can also be used as a replacement for both JACK and
+PulseAudio.
+
+While PipeWire provides the media processing and API, it does not,
+directly, know about devices such as sound cards, nor how you might want
+to connect applications, hardware, and media processing filters.
+Instead, PipeWire relies on a @dfn{session manager} to specify all these
+relationships. While you may use any session manager you wish, for most
+people the @url{https://pipewire.pages.freedesktop.org/wireplumber/,
+WirePlumber} session manager, a reference implementation provided by the
+PipeWire project itself, suffices, and that is the one
+@code{home-pipewire-service-type} uses.
+
+PipeWire can be used as a replacement for PulseAudio by setting
+@code{enable-pulseaudio?} to @code{#t} in
+@code{home-pipewire-configuration}, so that existing PulseAudio clients
+may use it without any further configuration.
+
+In addition, JACK clients may connect to PipeWire by using the
+@command{pw-jack} program, which comes with PipeWire. Simply prefix the
+command with @command{pw-jack} when you run it, and audio data should go
+through PipeWire:
+
+@example
+pw-jack mpv -ao=jack sound-file.wav
+@end example
+
+For more information on PulseAudio emulation, see
+@uref{https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/Config-PulseAudio},
+for JACK, see
+@uref{https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/Config-JACK}.
+
+As PipeWire does not use @code{dbus} to start its services on demand
+(as PulseAudio does), @code{home-pipewire-service-type} uses Shepherd
+to start services when logged in, provisioning the @code{pipewire},
+@code{wireplumber}, and, if configured, @code{pipewire-pulseaudio}
+services. @xref{Shepherd Home Service}.
+
+@defvar home-pipewire-service-type
+This provides the service definition for @command{pipewire}, which will
+run on login. Its value is a @code{home-pipewire-configuration} object.
+
+To start the service, add it to the @code{service} field of your
+@code{home-environment}, such as:
+
+@lisp
+(service home-pipewire-service-type)
+@end lisp
+@end defvar
+
+@deftp {Data Type} home-pipewire-configuration
+Available @code{home-pipewire-configuration} fields are:
+
+@table @asis
+@item @code{pipewire} (default: @code{pipewire}) (type: file-like)
+The PipeWire package to use.
+
+@item @code{wireplumber} (default: @code{wireplumber}) (type: file-like)
+The WirePlumber package to use.
+
+@item @code{enable-pulseaudio?} (default: @code{#t}) (type: boolean)
+When true, enable PipeWire's PulseAudio emulation support, allowing
+PulseAudio clients to use PipeWire transparently.
+@end table
+@end deftp
+
@node Mail Home Services
@subsection Mail Home Services
diff --git a/gnu/home/services/sound.scm b/gnu/home/services/sound.scm
index 22c1a99250..313a57305b 100644
--- a/gnu/home/services/sound.scm
+++ b/gnu/home/services/sound.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2023 Brian Cully <bjc@spork.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -19,13 +20,112 @@
(define-module (gnu home services sound)
#:use-module (gnu home services)
#:use-module (gnu home services shepherd)
+ #:use-module (gnu home services xdg)
+ #:use-module (gnu packages linux)
+ #:use-module (gnu services configuration)
#:use-module (guix records)
#:use-module (guix gexp)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:export (home-pulseaudio-rtp-sink-service-type
home-pulseaudio-rtp-source-service-type
- %pulseaudio-rtp-multicast-address))
+ %pulseaudio-rtp-multicast-address
+
+ home-pipewire-configuration
+ home-pipewire-service-type))
+
+
+;;;
+;;; PipeWire support.
+;;;
+
+(define-configuration/no-serialization home-pipewire-configuration
+ (pipewire
+ (file-like pipewire)
+ "The PipeWire package to use.")
+ (wireplumber
+ (file-like wireplumber)
+ "The WirePlumber package to use.")
+ (enable-pulseaudio?
+ (boolean #t)
+ "When true, enable PipeWire's PulseAudio emulation support, allowing
+PulseAudio clients to use PipeWire transparently."))
+
+(define (home-pipewire-shepherd-service config)
+ (shepherd-service
+ (documentation "PipeWire media processing.")
+ (provision '(pipewire))
+ (requirement '(dbus))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-pulseaudio-shepherd-service config)
+ (shepherd-service
+ (documentation "Drop-in PulseAudio replacement service for PipeWire.")
+ (provision '(pipewire-pulseaudio))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire-pulse"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-wireplumber-shepherd-service config)
+ (shepherd-service
+ (documentation "WirePlumber session management for PipeWire.")
+ (provision '(wireplumber))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-wireplumber config)
+ "/bin/wireplumber"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-shepherd-services config)
+ (cons* (home-pipewire-shepherd-service config)
+ (home-wireplumber-shepherd-service config)
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ (list (home-pipewire-pulseaudio-shepherd-service config))
+ '())))
+
+(define (home-pipewire-asoundrc config)
+ (match-record config <home-pipewire-configuration>
+ (pipewire)
+ (mixed-text-file
+ "asoundrc"
+ "<" pipewire "/share/alsa/alsa.conf.d/50-pipewire.conf>\n"
+ "<" pipewire "/share/alsa/alsa.conf.d/99-pipewire-default.conf>\n"
+ "pcm_type.pipewire {\n"
+ " lib \"" pipewire "/lib/alsa-lib/libasound_module_pcm_pipewire.so\"\n"
+ "}\n"
+ "ctl_type.pipewire {\n"
+ " lib \"" pipewire "/lib/alsa-lib/libasound_module_ctl_pipewire.so\"\n"
+ "}\n")))
+
+(define home-pipewire-disable-pulseaudio-auto-start
+ (plain-file "client.conf" "autospawn = no"))
+
+(define (home-pipewire-xdg-configuration config)
+ (cons* `("alsa/asoundrc" ,(home-pipewire-asoundrc config))
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ `(("pulse/client.conf"
+ ,home-pipewire-disable-pulseaudio-auto-start))
+ '())))
+
+(define home-pipewire-service-type
+ (service-type
+ (name 'pipewire)
+ (extensions
+ (list (service-extension home-shepherd-service-type
+ home-pipewire-shepherd-services)
+ (service-extension home-xdg-configuration-files-service-type
+ home-pipewire-xdg-configuration)))
+ (description
+ "Start essential PipeWire services.")
+ (default-value (home-pipewire-configuration))))
;;;

base-commit: d5298c5e334e56a9aabddcb62d312e63135864f6
--
2.41.0
O
O
Oleg Pykhalov wrote on 20 Dec 2023 09:46
(name . Brian Cully)(address . bjc@spork.org)
871qbh8dni.fsf@gmail.com
Hi Brian,

Brian Cully <bjc@spork.org> writes:

Toggle quote (6 lines)
> This adds a set of home shepherd services which will start the required
> services for a functional pipewire setup.
>
> * gnu/home/services/sound.scm (home-pipewire-shepherd-service),
> (home-pipewire-pulse-shepherd-service), (home-wireplumber-shepherd-service),

The ‘home-pipewire-pulse-shepherd-service’ procedure is missing. Do you
have a code for this procedure or should it be removed from the commit
message? The PipeWire service seems to work without it.

Toggle quote (15 lines)
> (home-pipewire-shepherd-services)
> (home-pipewire-asoundrc), (home-pipewire-xdg-configuration): new procedures.
> (home-pipewire-service-type): new service type.
> (home-pipewire-configuration): new struct.
> (home-pipewire-disable-pulseaudio-auto-start): new variable.
> * doc/guix.texi (Sound Home Services): document it.
>
> Change-Id: I99e0ae860de91d459c3c554ec5503bf35f785a2a
> ---
> doc/guix.texi | 72 +++++++++++++++++++++++++
> gnu/home/services/sound.scm | 102 +++++++++++++++++++++++++++++++++++-
> 2 files changed, 173 insertions(+), 1 deletion(-)
> ...
> base-commit: d5298c5e334e56a9aabddcb62d312e63135864f6

This is the third implementation of a PipeWire related home services
which I've found on the Internet. In the end all of them are the same
except variable naming. Also I've looked how NixOS and Gentoo GNU/Linux
distributions use PipeWire. Running it is a home service is the
recommended way by the upstream (user's systemd units are recommended by
the upstream to be correct) [1].



The patch is tested with the following Guix home configuration:
Toggle snippet (4 lines)
(service home-dbus-service-type)
(service home-pipewire-service-type)

The sound from speakers and microphone work.

Also I've packaged obs-pipewire-audio-capture package which works with
current PipeWire implementation.


I think we could merge the patch after getting
‘home-pipewire-pulse-shepherd-service’ or removing it from the commit
message, e.g.:
Toggle snippet (15 lines)
gnu: home: Add home-pipewire service.

This adds a set of home Shepherd services which will start the required
services for a functional PipeWire setup

* gnu/home/services/sound.scm
(home-pipewire-shepherd-service, home-wireplumber-shepherd-service,
home-pipewire-shepherd-services, home-pipewire-asoundrc,
home-pipewire-xdg-configuration): New procedures.
(home-pipewire-service-type): New service type.
(home-pipewire-configuration): New struct.
(home-pipewire-disable-pulseaudio-auto-start): New variable.
* doc/guix.texi (Sound Home Services): Document it.

Brian, could you add the code for ‘home-pipewire-pulse-shepherd-service’
if it is required, please?


Thanks,
Oleg.
-----BEGIN PGP SIGNATURE-----

iQJIBAEBCgAyFiEEcjhxI46s62NFSFhXFn+OpQAa+pwFAmWCqeEUHGdvLndpZ3Vz
dEBnbWFpbC5jb20ACgkQFn+OpQAa+pxFrw/+JoLSu0ORCQBxWo89bLESCgiDmcvR
giTnNgxnjBfuur7nfTinReKCSkkrfUhoFLabGMz9Rr/0guyzTHsB+nIoGab2S8ZU
KGD3uru+AgcNmJwABKJZ2S5ULvtjZ79eAKmujpPUMc8HQK16vUPxAnGAahPC0/T1
v3oH+FyuDhGa3Re+IcWDAg6hw+qBCfEBJL6LZaeWmwPEaXbHnpHl7f+sxdUe/yMa
WIoKPN3VVTerNbdpIECKuTHYFDAkGjz1tYa2dEEYgJTi+KyM0HIG2ZEz2Lkw9Ah7
Zda7i8WeaIriYYfWO89ys9yxeoBqk9ZWrAJiWoW42/Rt4nQpghcn4dqd7OaUSmjJ
ec4bnekFIlZtq6pnyZD03we7B50PB4R4jWVBIgrHEhskUs5PumwbUI9FYZjArDQJ
3rzLAVxPxqxJn4Pv744eO+WMmVW39/ixfvYv2+HAD0sf4LelS6QlJOrxzpc3Tuhc
1GTHbEn4BgsE3XfANyICA1hcK8wT917Osaa2d2SSM5Xk19aGJWT+cWzEDMskaaeu
tZqOl7Q/Z6vLOgADNbrLflJxTtWVS7ESJvxXVbqptdSSbHTs6uc/0e5drgXEMpI7
IPMCBj5Gv6YQITkQcOCqnvXNnYTbVHXVIa8p/sHOrS/XjZg/liWsjvkJMgoSZpIu
4sc4ugBRnwd9m1Q=
=YXi8
-----END PGP SIGNATURE-----

Closed
O
O
Oleg Pykhalov wrote on 20 Dec 2023 09:51
control message for bug #63863
(address . control@debbugs.gnu.org)
4ddae0af29c2331e032430d9c9df708f@gmail.com
reopen 63863
tags 63863 - fixed patch
quit
O
O
Oleg Pykhalov wrote on 20 Dec 2023 09:55
(address . control@debbugs.gnu.org)
5b2d6ca138a1f4329f66a49271bb0f92@gmail.com
tags 63863 + patch
quit
B
B
Brian Cully wrote on 22 Dec 2023 16:22
[PATCH v7] gnu: home: Add support for home-pipewire-service
(address . 63863@debbugs.gnu.org)(name . Brian Cully)(address . bjc@spork.org)
b959bdfb63f1ada6e6db8848a78cc1162f9d0505.1703258521.git.bjc@spork.org
This adds a set of home shepherd services which will start the required
services for a functional pipewire setup.

* gnu/home/services/sound.scm (home-pipewire-shepherd-service),
(home-pipewire-pulseaudio-shepherd-service), (home-wireplumber-shepherd-service),
(home-pipewire-shepherd-services)
(home-pipewire-asoundrc), (home-pipewire-xdg-configuration): new procedures.
(home-pipewire-service-type): new service type.
(home-pipewire-configuration): new struct.
(home-pipewire-disable-pulseaudio-auto-start): new variable.
* doc/guix.texi (Sound Home Services): document it.

Change-Id: I99e0ae860de91d459c3c554ec5503bf35f785a2a
---
doc/guix.texi | 72 +++++++++++++++++++++++++
gnu/home/services/sound.scm | 102 +++++++++++++++++++++++++++++++++++-
2 files changed, 173 insertions(+), 1 deletion(-)

Toggle diff (219 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index e61a893af9..90888a514f 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -45050,6 +45050,7 @@ Sound Home Services
@cindex PulseAudio, home service
@cindex RTP, for PulseAudio
+@subsubheading PulseAudio RTP Streaming Services
The following services dynamically reconfigure the
@uref{https://pulseaudio.org,PulseAudio sound server}: they let you
@@ -45137,6 +45138,77 @@ Sound Home Services
This is the multicast address used by default by the two services above.
@end defvar
+@cindex PipeWire, home service
+@subsubheading PipeWire Home Service
+
+@uref{https://pipewire.org, PipeWire} provides a low-latency,
+graph-based audio and video processing service. In addition to its
+native protocol, it can also be used as a replacement for both JACK and
+PulseAudio.
+
+While PipeWire provides the media processing and API, it does not,
+directly, know about devices such as sound cards, nor how you might want
+to connect applications, hardware, and media processing filters.
+Instead, PipeWire relies on a @dfn{session manager} to specify all these
+relationships. While you may use any session manager you wish, for most
+people the @url{https://pipewire.pages.freedesktop.org/wireplumber/,
+WirePlumber} session manager, a reference implementation provided by the
+PipeWire project itself, suffices, and that is the one
+@code{home-pipewire-service-type} uses.
+
+PipeWire can be used as a replacement for PulseAudio by setting
+@code{enable-pulseaudio?} to @code{#t} in
+@code{home-pipewire-configuration}, so that existing PulseAudio clients
+may use it without any further configuration.
+
+In addition, JACK clients may connect to PipeWire by using the
+@command{pw-jack} program, which comes with PipeWire. Simply prefix the
+command with @command{pw-jack} when you run it, and audio data should go
+through PipeWire:
+
+@example
+pw-jack mpv -ao=jack sound-file.wav
+@end example
+
+For more information on PulseAudio emulation, see
+@uref{https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/Config-PulseAudio},
+for JACK, see
+@uref{https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/Config-JACK}.
+
+As PipeWire does not use @code{dbus} to start its services on demand
+(as PulseAudio does), @code{home-pipewire-service-type} uses Shepherd
+to start services when logged in, provisioning the @code{pipewire},
+@code{wireplumber}, and, if configured, @code{pipewire-pulseaudio}
+services. @xref{Shepherd Home Service}.
+
+@defvar home-pipewire-service-type
+This provides the service definition for @command{pipewire}, which will
+run on login. Its value is a @code{home-pipewire-configuration} object.
+
+To start the service, add it to the @code{service} field of your
+@code{home-environment}, such as:
+
+@lisp
+(service home-pipewire-service-type)
+@end lisp
+@end defvar
+
+@deftp {Data Type} home-pipewire-configuration
+Available @code{home-pipewire-configuration} fields are:
+
+@table @asis
+@item @code{pipewire} (default: @code{pipewire}) (type: file-like)
+The PipeWire package to use.
+
+@item @code{wireplumber} (default: @code{wireplumber}) (type: file-like)
+The WirePlumber package to use.
+
+@item @code{enable-pulseaudio?} (default: @code{#t}) (type: boolean)
+When true, enable PipeWire's PulseAudio emulation support, allowing
+PulseAudio clients to use PipeWire transparently.
+@end table
+@end deftp
+
@node Mail Home Services
@subsection Mail Home Services
diff --git a/gnu/home/services/sound.scm b/gnu/home/services/sound.scm
index 22c1a99250..313a57305b 100644
--- a/gnu/home/services/sound.scm
+++ b/gnu/home/services/sound.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2023 Brian Cully <bjc@spork.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -19,13 +20,112 @@
(define-module (gnu home services sound)
#:use-module (gnu home services)
#:use-module (gnu home services shepherd)
+ #:use-module (gnu home services xdg)
+ #:use-module (gnu packages linux)
+ #:use-module (gnu services configuration)
#:use-module (guix records)
#:use-module (guix gexp)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:export (home-pulseaudio-rtp-sink-service-type
home-pulseaudio-rtp-source-service-type
- %pulseaudio-rtp-multicast-address))
+ %pulseaudio-rtp-multicast-address
+
+ home-pipewire-configuration
+ home-pipewire-service-type))
+
+
+;;;
+;;; PipeWire support.
+;;;
+
+(define-configuration/no-serialization home-pipewire-configuration
+ (pipewire
+ (file-like pipewire)
+ "The PipeWire package to use.")
+ (wireplumber
+ (file-like wireplumber)
+ "The WirePlumber package to use.")
+ (enable-pulseaudio?
+ (boolean #t)
+ "When true, enable PipeWire's PulseAudio emulation support, allowing
+PulseAudio clients to use PipeWire transparently."))
+
+(define (home-pipewire-shepherd-service config)
+ (shepherd-service
+ (documentation "PipeWire media processing.")
+ (provision '(pipewire))
+ (requirement '(dbus))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-pulseaudio-shepherd-service config)
+ (shepherd-service
+ (documentation "Drop-in PulseAudio replacement service for PipeWire.")
+ (provision '(pipewire-pulseaudio))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire-pulse"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-wireplumber-shepherd-service config)
+ (shepherd-service
+ (documentation "WirePlumber session management for PipeWire.")
+ (provision '(wireplumber))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-wireplumber config)
+ "/bin/wireplumber"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-shepherd-services config)
+ (cons* (home-pipewire-shepherd-service config)
+ (home-wireplumber-shepherd-service config)
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ (list (home-pipewire-pulseaudio-shepherd-service config))
+ '())))
+
+(define (home-pipewire-asoundrc config)
+ (match-record config <home-pipewire-configuration>
+ (pipewire)
+ (mixed-text-file
+ "asoundrc"
+ "<" pipewire "/share/alsa/alsa.conf.d/50-pipewire.conf>\n"
+ "<" pipewire "/share/alsa/alsa.conf.d/99-pipewire-default.conf>\n"
+ "pcm_type.pipewire {\n"
+ " lib \"" pipewire "/lib/alsa-lib/libasound_module_pcm_pipewire.so\"\n"
+ "}\n"
+ "ctl_type.pipewire {\n"
+ " lib \"" pipewire "/lib/alsa-lib/libasound_module_ctl_pipewire.so\"\n"
+ "}\n")))
+
+(define home-pipewire-disable-pulseaudio-auto-start
+ (plain-file "client.conf" "autospawn = no"))
+
+(define (home-pipewire-xdg-configuration config)
+ (cons* `("alsa/asoundrc" ,(home-pipewire-asoundrc config))
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ `(("pulse/client.conf"
+ ,home-pipewire-disable-pulseaudio-auto-start))
+ '())))
+
+(define home-pipewire-service-type
+ (service-type
+ (name 'pipewire)
+ (extensions
+ (list (service-extension home-shepherd-service-type
+ home-pipewire-shepherd-services)
+ (service-extension home-xdg-configuration-files-service-type
+ home-pipewire-xdg-configuration)))
+ (description
+ "Start essential PipeWire services.")
+ (default-value (home-pipewire-configuration))))
;;;

base-commit: d5298c5e334e56a9aabddcb62d312e63135864f6
--
2.41.0
B
B
Brian Cully wrote on 22 Dec 2023 16:22
Re: bug#63863: closed (Re: [bug#63863] [PATCH v6] gnu: home: Add support for home-pipewire-service)
(address . 63863@debbugs.gnu.org)
8734vumfak.fsf@spork.org
help-debbugs@gnu.org (GNU bug Tracking System) writes:

Toggle quote (7 lines)
> Your bug report
>
> #63863: [PATCH] gnu: home: Add support for home-pipewire-service
>
> which was filed against the guix-patches package, has been
> closed.

Was this intentional?

Toggle quote (6 lines)
> The ‘home-pipewire-pulse-shepherd-service’ procedure is
> missing. Do you
> have a code for this procedure or should it be removed from the
> commit
> message? The PipeWire service seems to work without it.

I'd renamed it to ‘home-pulseaudio-shepherd-service’ and forgot to
update the commit message; v7 will have it fixed.

-bjc
O
O
Oleg Pykhalov wrote on 26 Dec 2023 13:57
Re: [bug#63863] closed (Re: [bug#63863] [PATCH v6] gnu: home: Add support for home-pipewire-service)
(name . Brian Cully)(address . bjc@spork.org)(address . 63863-done@debbugs.gnu.org)
87bkad3yui.fsf@gmail.com
Brian Cully <bjc@spork.org> writes:

Toggle quote (10 lines)
> help-debbugs@gnu.org (GNU bug Tracking System) writes:
>
>> Your bug report
>>
>> #63863: [PATCH] gnu: home: Add support for home-pipewire-service
>>
>> which was filed against the guix-patches package, has been closed.
>
> Was this intentional?

It was accidental, apologies. I reopened the issue right after closing.

Toggle quote (7 lines)
>> The ‘home-pipewire-pulse-shepherd-service’ procedure is missing. Do you
>> have a code for this procedure or should it be removed from the commit
>> message? The PipeWire service seems to work without it.
>
> I'd renamed it to ‘home-pulseaudio-shepherd-service’ and forgot to update the
> commit message; v7 will have it fixed.

Pushed to master as afdbf7f271529573397474fdb8f1c9d00dceba37, following
the Guix convention style with a neatly formatted commit message.


Thanks,
Oleg.
-----BEGIN PGP SIGNATURE-----

iQJIBAEBCgAyFiEEcjhxI46s62NFSFhXFn+OpQAa+pwFAmWKzdUUHGdvLndpZ3Vz
dEBnbWFpbC5jb20ACgkQFn+OpQAa+pxB9w/+IxZc5eao/QAAiRq482keuBBNUPzu
u/wLnGUlEoJvx4uz+DBSlUcLl99uKRla8i7gKBcgL3e5pbmQjdTE1ouzPqZszyJ8
wjvvMvxwC2OkRXUviB2rZXFqGouPi68HzdvnxrBBavNif8tRdMCE8MGxSU3/xjIZ
wnRc3VsHeaPxGIqQbPgFTRWjtqDOMzEjZm3/VzAvCFlskfy0K/SSfaMnseu9TKf7
MS7esot5s9DyMerrqFJi3Zqi5kcmaCa4ok4fAXGavnY5Fk50PFundKahAsN3LRVi
jCfyQ4VnmWJl7Ojq+cvQtT5gf5qSnOCvOZthBEFUMZUQlzl6lvAv40Q6qA1qRNGf
a41pI1WVCp4nMpioAO4OvSIRn/xzOp7WLmDxgpiIxEgIrIE92U4QiH5DY7dgkX2Y
0Kik0VOTeZzjoLVd5JMPnArXk5RDLJsDK+YhSu+GM91HwBErFZy5kw+1OQ65OXA6
JJGmWdVf56xFnDxDckhlHN/7QYGfUUmbcBcoRCZtQT5lm2hS8yzNdAhyPuKqPoxB
YLkRZf/2AMTJw6wAMRwnUNT/lvt/xvNHFbb7fxvbqlMOmfyPDXT5V2rBrZsLvT0c
H0krfA+ci3YiPSSH9tW84nFOs15R6/gQfBRRMhimwVbSUyN6L62zGV30SHtoWQlt
EPdx//U9cWk+z7U=
=4VWq
-----END PGP SIGNATURE-----

Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 63863@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 63863
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch