GNU bug report logs - #76060
[PATCH] gnu: home: services: Add 'wayland-display' service.

Previous Next

Package: guix-patches;

Reported by: Sisiutl <sisiutl <at> egregore.fun>

Date: Tue, 4 Feb 2025 21:45:02 UTC

Severity: normal

Tags: patch

Merged with 76057, 76058, 76619, 76659, 76667

To reply to this bug, email your comments to 76060 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#76060; Package guix-patches. (Tue, 04 Feb 2025 21:45:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Sisiutl <sisiutl <at> egregore.fun>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Tue, 04 Feb 2025 21:45:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Sisiutl <sisiutl <at> egregore.fun>
To: guix-patches <at> gnu.org
Cc: Sisiutl <sisiutl <at> egregore.fun>
Subject: [PATCH] gnu: home: services: Add 'wayland-display' service.
Date: Mon,  3 Feb 2025 13:45:13 +0100
* gnu/home/services/desktop.scm (wayland-shepherd-service): New procedure.
(home-wayland-service-type): New variable.

Change-Id: Ide1ca748551a280efe8286b4ac1e46787b108443
---
 gnu/home/services/desktop.scm | 68 +++++++++++++++++++++++++++++++++--
 1 file changed, 66 insertions(+), 2 deletions(-)

diff --git a/gnu/home/services/desktop.scm b/gnu/home/services/desktop.scm
index fc96ce9295..34321409f7 100644
--- a/gnu/home/services/desktop.scm
+++ b/gnu/home/services/desktop.scm
@@ -48,7 +48,7 @@ (define-module (gnu home services desktop)
 
             home-startx-command-service-type))
 
-
+
 ;;;
 ;;; Waiting for X11.
 ;;;
@@ -121,7 +121,71 @@ (define home-x11-service-type
 during that time, the @code{x11-display} service is marked as failing to
 start.")))
 
-
+
+;;;
+;;; Waiting for Wayland.
+;;;
+
+(define (wayland-shepherd-service config)
+  (list (shepherd-service
+         (provision '(wayland-display))
+         (modules '((ice-9 ftw)
+                    (ice-9 regex)
+                    (ice-9 match)
+                    (srfi srfi-1)
+                    (shepherd support)))
+         (respawn? #t)
+         (respawn-limit (home-wayland-configuration-tries config))
+         (respawn-delay 1)
+         (start
+          #~(lambda* (#:optional (env-wayland-display (getenv "WAYLAND_DISPLAY")))
+
+              (define wayland-socket-regex "wayland-[0-9]+$")
+
+              (define (socket? directory regex)
+                (find (match-lambda
+                        ((or "." "..") #f)
+                        (name
+                         (let ((name (in-vicinity directory
+                                                  name)))
+                           (and (string-match regex name)
+                                (access? name O_RDWR)))))
+                      ;; Wayland names its sockets `wayland-n`. With
+                      ;; `reverse`, we pick up on the last Wayland instance
+                      ;; created (essentially what we always want to do).
+                      (or (reverse (scandir directory)) '())))
+
+              (define wayland-display
+                (or env-wayland-display
+                    (socket? %user-runtime-dir "wayland-[0-9]+$")))
+
+              (when wayland-display
+                (format #t "Wayland display found at ~s.~%" wayland-display)
+                ;; Note: 'make-forkexec-constructor' calls take their
+                ;; default #:environment-variables value before this service
+                ;; is started and are thus unaffected by the 'setenv' call
+                ;; below.  Users of this service have to explicitly query
+                ;; its value.
+                (setenv "WAYLAND_DISPLAY" wayland-display))
+              wayland-display))
+         (stop #~(lambda (_)
+                   (unsetenv "WAYLAND_DISPLAY")
+                   #f)))))
+
+(define-public home-wayland-service-type
+  (service-type
+   (name 'home-wayland-display)
+   (extensions (list (service-extension home-shepherd-service-type
+                                        wayland-shepherd-service)))
+   (default-value 10)
+   (description
+    "Create a @code{wayland-display} Shepherd service that waits for a Wayland
+compositor to be up and running, up to a configurable delay, and sets the
+@code{WAYLAND_DISPLAY} environment variable of @command{shepherd} itself
+accordingly.  If no accessible Wayland server shows up during that time, the
+@code{wayland-display} service is marked as failing to start.")))
+
+
 ;;;
 ;;; Redshift.
 ;;;
-- 
2.48.1





Information forwarded to guix-patches <at> gnu.org:
bug#76060; Package guix-patches. (Wed, 05 Feb 2025 21:49:01 GMT) Full text and rfc822 format available.

Message #8 received at 76060 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Sisiutl <sisiutl <at> egregore.fun>
Cc: 76060 <at> debbugs.gnu.org, Janneke Nieuwenhuizen <janneke <at> gnu.org>,
 Tanguy Le Carrour <tanguy <at> bioneland.org>, Andrew Tropin <andrew <at> trop.in>
Subject: Re: [bug#76060] [PATCH] gnu: home: services: Add 'wayland-display'
 service.
Date: Wed, 05 Feb 2025 22:48:07 +0100
Hello,

(Cc’ing members of the Home team.)

Sisiutl <sisiutl <at> egregore.fun> skribis:

> * gnu/home/services/desktop.scm (wayland-shepherd-service): New procedure.
> (home-wayland-service-type): New variable.
>
> Change-Id: Ide1ca748551a280efe8286b4ac1e46787b108443

Nice improvement.

> -
> +
>  ;;;
>  ;;; Waiting for X11.

These ^L characters are page breaks, which are useful when navigating
through the file; please preserve them.

> +(define (wayland-shepherd-service config)

[...]

> +         (respawn? #t)
> +         (respawn-limit (home-wayland-configuration-tries config))
> +         (respawn-delay 1)

I believe ‘home-wayland-configuration-tries’ does not exist.

But I think you can remove these three lines because respawning only
applies to services that start a daemon, which is not the case here.

> +              (define (socket? directory regex)
> +                (find (match-lambda
> +                        ((or "." "..") #f)
> +                        (name
> +                         (let ((name (in-vicinity directory
> +                                                  name)))
> +                           (and (string-match regex name)
> +                                (access? name O_RDWR)))))
> +                      ;; Wayland names its sockets `wayland-n`. With
> +                      ;; `reverse`, we pick up on the last Wayland instance
> +                      ;; created (essentially what we always want to do).
> +                      (or (reverse (scandir directory)) '())))

I think ‘find-socket’ would be a better name than ‘socket?’.

Nitpick: prefer 'straight quotes' or ‘curly quotes’ in comments.

> +(define-public home-wayland-service-type

Please use plain ‘define’ and add to the export list at the top.

> +  (service-type
> +   (name 'home-wayland-display)
> +   (extensions (list (service-extension home-shepherd-service-type
> +                                        wayland-shepherd-service)))
> +   (default-value 10)

I believe this value is unused.  Maybe set it to #f for clarity.

One last thing: could you add a note in ‘doc/guix.texi’ about this
service, right after ‘home-x11-service-type’?

Thanks in advance!

Ludo’.




Merged 76057 76058 76060. Request was from Ludovic Courtès <ludo <at> gnu.org> to control <at> debbugs.gnu.org. (Wed, 05 Feb 2025 21:49:02 GMT) Full text and rfc822 format available.

Severity set to 'wishlist' from 'normal' Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Sun, 16 Feb 2025 06:59:02 GMT) Full text and rfc822 format available.

Severity set to 'normal' from 'wishlist' Request was from Hilton Chain <hako <at> ultrarare.space> to control <at> debbugs.gnu.org. (Sun, 02 Mar 2025 04:38:02 GMT) Full text and rfc822 format available.

Merged 76057 76058 76060 76619 76659 76667. Request was from Hilton Chain <hako <at> ultrarare.space> to control <at> debbugs.gnu.org. (Sun, 02 Mar 2025 04:38:02 GMT) Full text and rfc822 format available.

This bug report was last modified 105 days ago.

Previous Next


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