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

From: Hilton Chain <[email-masked]>
Date: Tue, 11 Mar 2025 22:39:59 +0800

On Tue, 11 Mar 2025 05:16:36 +0800,
Ludovic Courtès wrote:
>
> Hi!
>
> Hilton Chain <[email-masked]> skribis:
>
> > On a second thought ‘display’ may not be a good name, I'm going to use
> > ‘graphical-session’, sounds familiar? ;)
>
> Good idea.  :-)
>
> > I have realized that for a Wayland session, setting only ‘WAYLAND_DISPLAY’ in
> > Shepherd is not sufficient to make all applications work.
>
> The goal of ‘x11-display’ now is only to (1) ensure X11 is running, and
> (2) determine the correct value of ‘DISPLAY’ so other services can use
> it.
>
> I would say that other environment variables like the Freedesktop ones
> (XDG_*) are beyond the scope of such a service.  WDYT?
>
> > 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
> >
> >
> > These environment variables will be collected in ‘GUIX_GRAPHICAL_SESSION’:
>
> That seems a bit too complex to me.

I finally realized...!  ‘x11-display’ has a fundamental issue: It actually
relies on pre-existing graphical session!

1. Shepherd loads service definitons
  - 'service' dependending on ‘x11-display’ calls ‘(getenv "DISPLAY")’ in its
    definiton -> it depends on existing DISPLAY.
  - Shepherd actually fails at this stage if there's no pre-existing DISPLAY.
2. Shepherd starts ‘x11-display’
  - ‘x11-display’ finds socket and sets DISPLAY.
3. Shepherd starts 'service'
  - 'service' is already loaded in (1.), DISPLAY set in (2.) won't affect it.

Bad news, but simplifies the whole thing a lot :)

We can just remove socket finding part from ‘x11-display’ and use ‘getenv’
instead.  Then For a ‘graphical-session’ provision, Shepherd should be started
by... a graphical session.  Previously for ‘x11-display’ I think Shepherd was
supposed to be started by a display manager, but I'm not sure if WAYLAND_DISPLAY
changes when using a display manager.

home-shepherd-service-type doesn't set default environment variables so
Shepherd's starting environment is inherited.  Then no need to worry about
importing environment variables if we want to keep this behavior.

So a graphical session setup is what I have mentioned before: Disable
auto-starting of Shepherd, and start it in your desktop environment.

I'm using this snippet btw:
--8<---------------cut here---------------start------------->8---
pgrep --uid $USER shepherd > /dev/null || shepherd
--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.
>
> That’s not really intended, but it’s a Guix issue, not a Shepherd issue
> (the Shepherd has no notion of “auto starting”; it just starts whatever
> you ask it to start in your config file).
>
> Perhaps the ‘auto-start?’ property should automatically propagate along
> edges?

Either services marked not to auto-start starting or those marked as auto-start
not starting? :P  I'm not sure which side to choose.

For the specific case this is unnecessary now, as there's no need to wait to
import environment variables.