Subject: Re: [bug#76619] [PATCH] gnu: home: services: Add 'wayland-display' service.

From: Hilton Chain <[email-masked]>
Date: Mon, 10 Mar 2025 19:20:32 +0800

On Fri, 07 Mar 2025 23:48:24 +0800,
Hilton Chain wrote:
>
> On Wed, 05 Mar 2025 23:16:18 +0800,
> Ludovic Courtès wrote:
> >
> > Hi Hilton,
> >
> > Hilton Chain <[email-masked]> skribis:
> >
> > > Since some services may depend on either DISPLAY or WAYLAND_DISPLAY, and these
> > > two services (x11-display, wayland-display) are similar, I think we can merge
> > > them into one and deprecate home-x11-service-type by this new service.
> > >
> > > e.g.
> > >
> > > service: home-display-service-type
> > > configuration: x11? (boolean: #f) wayland? (boolean: #f) time-to-wait (integer: 10)
> > > default-value #f
> > > provision: 'x11-display when x11? is #t
> > >            'wayland-display when walyand? is #t
> > >            'display when either x11? or wayland? is #t
> > > return value: "DISPLAY: unset; WAYLAND_DISPLAY: wayland-1"
> > >
> > > Then one service can choose to depend on 'display or specifically 'x11-display /
> > > 'wayland-display.
> >
> > That sounds like a good idea to me.  It goes beyond the scope of the
> > initial patch in this thread though.
> >
> > Sisiutl, Hilton: who wants to work on it?
>
> Sure, I can do this.  I'll begin in a few days.

On a second thought ‘display’ may not be a good name, I'm going to use
‘graphical-session’, sounds familiar? ;)

I have realized that for a Wayland session, setting only ‘WAYLAND_DISPLAY’ in
Shepherd is not sufficient to make all applications work.

Currently to have a fully-functional setup, you'll need to disable auto starting
of ‘home-shepherd-service-type’ and start Shepherd via Wayland compositor to
have all needed environment variables passed to Shepherd.  This patch doesn't
make a difference in this regard.

To address this, I have made the service to accpet passing environment variables
directly:
--8<---------------cut here---------------start------------->8---
herd start graphical-session \
    DISPLAY=$DISPLAY \
    WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
    XDG_SESSION_TYPE=$XDG_SESSION_TYPE \
    XDG_CURRENT_DESKTOP=$XDG_CURRENT_DESKTOP \
    NIRI_SOCKET=$NIRI_SOCKET
--8<---------------cut here---------------end--------------->8---

These environment variables will be collected in ‘GUIX_GRAPHICAL_SESSION’:
--8<---------------cut here---------------start------------->8---
GUIX_GRAPHICAL_SESSION => "DISPLAY WALYAND_DISPLAY XDG_SESSION_TYPE ..."
--8<---------------cut here---------------end--------------->8---

And used by users of ‘graphical-session’:
--8<---------------cut here---------------start------------->8---
#:environment-variables
(let ((update-environment-variable
       (lambda (name base)
         (match (getenv name)
           (#f base)
           (value (cons (string-append name "=" value)
                        (remove (cut string-prefix?
                                     (string-append name "=")
                                     <>)
                                base)))))))
  (fold update-environment-variable
        (default-environment-variables)
        (or (and=> (getenv "GUIX_GRAPHICAL_SESSION")
                   string-tokenize)
            '("DISPLAY" "WAYLAND_DISPLAY"))))
--8<---------------cut here---------------end--------------->8---

However I found that Shepherd starts ‘graphical-session’ even if its
auto-starting is disabled, when there're services depending on it.

Is this intended?  I expect to have these services waiting ‘graphical-session’
to start instead of starting it right away.