GNU bug report logs - #63863
[PATCH] gnu: home: Add support for home-pipewire-service

Previous Next

Package: guix-patches;

Reported by: Brian Cully <bjc <at> spork.org>

Date: Fri, 2 Jun 2023 23:06:02 UTC

Severity: normal

Tags: patch

Done: Oleg Pykhalov <go.wigust <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Oleg Pykhalov <go.wigust <at> gmail.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#63863: closed ([PATCH] gnu: home: Add support for
 home-pipewire-service)
Date: Wed, 20 Dec 2023 08:47:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Wed, 20 Dec 2023 11:46:25 +0300
with message-id <871qbh8dni.fsf <at> gmail.com>
and subject line Re: [bug#63863] [PATCH v6] gnu: home: Add support for home-pipewire-service
has caused the debbugs.gnu.org bug report #63863,
regarding [PATCH] gnu: home: Add support for home-pipewire-service
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
63863: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63863
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Brian Cully <bjc <at> spork.org>
To: guix-patches <at> gnu.org
Cc: Brian Cully <bjc <at> spork.org>
Subject: [PATCH] gnu: home: Add support for home-pipewire-service
Date: Fri,  2 Jun 2023 19:04:27 -0400
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 <at> gnu.org>
+;;; Copyright © 2023 Brian Cully <bjc <at> 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



[Message part 3 (message/rfc822, inline)]
From: Oleg Pykhalov <go.wigust <at> gmail.com>
To: Brian Cully <bjc <at> spork.org>
Cc: Ludovic Courtès <ludo <at> gnu.org>, 63863-done <at> debbugs.gnu.org,
 Tanguy LE CARROUR <tanguy <at> bioneland.org>, Andrew Tropin <andrew <at> trop.in>
Subject: Re: [bug#63863] [PATCH v6] gnu: home: Add support for
 home-pipewire-service
Date: Wed, 20 Dec 2023 11:46:25 +0300
[Message part 4 (text/plain, inline)]
Hi Brian,

Brian Cully <bjc <at> spork.org> writes:

> 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.

> (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].

[1]: https://github.com/PipeWire/pipewire/blob/bd87902da6a2badae096e4679eedfe9da2e75d79/NEWS#L5573


The patch is tested with the following Guix home configuration:
--8<---------------cut here---------------start------------->8---
    (service home-dbus-service-type)
    (service home-pipewire-service-type)
--8<---------------cut here---------------end--------------->8---

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.:
--8<---------------cut here---------------start------------->8---
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.
--8<---------------cut here---------------end--------------->8---

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


Thanks,
Oleg.
[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 1 year and 147 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.