diff mbox series

[bug#56050] home: services: environment-variables: Fix XDG base directories.

Message ID c8f5f8b21bc299011bd598e9bbdd3d19999d1071.1655528190.git.philip@philipmcgrath.com
State New
Headers show
Series [bug#56050] home: services: environment-variables: Fix XDG base directories. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Philip McGrath June 18, 2022, 5:25 a.m. UTC
When the environment initialization script is run, XDG_DATA_DIRS and/or
XDG_CONFIG_DIRS may be empty or unset, in which case we must use their
respective defaults from the specification, rather than ending the value
with a trailing ":". For further discussion, see
<https://lists.gnu.org/archive/html/help-guix/2022-05/msg00147.html>.

* gnu/home/services.scm
(environment-variables->setup-environment-script): Use conditional
parameter expansion for XDG_DATA_DIRS and XDG_CONFIG_DIRS.
---

MANPATH and INFOPATH don't have this problem because they have
well-defined behavior for a trailing ":".

XCURSOR_PATH, on the other hand, does seem to have a similar problem. In
my KDE Plasma Wayland session, at least, omiting the default caused the
cursor to disappear when hovering over the border of a window. I could
fix this on my Debian-based distribution by putting:

    export XCURSOR_PATH="${XCURSOR_PATH:-/usr/share/icons:/usr/share/pixmaps}"

in a file under "/etc/profile.d", but I'm not sure if that default is
truly portable even among FHS-based distros. For example, it sounds like
Gentoo uses "/usr/share/cursors/xorg-x11". So I haven't tried to address
XCURSOR_PATH for now.

  -Philip

 gnu/home/services.scm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


base-commit: 3154b582567539d8d607344fbd03a3d8456f66cb

Comments

Ludovic Courtès June 22, 2022, 8:38 p.m. UTC | #1
Philip McGrath <philip@philipmcgrath.com> skribis:

> When the environment initialization script is run, XDG_DATA_DIRS and/or
> XDG_CONFIG_DIRS may be empty or unset, in which case we must use their
> respective defaults from the specification, rather than ending the value
> with a trailing ":". For further discussion, see
> <https://lists.gnu.org/archive/html/help-guix/2022-05/msg00147.html>.
>
> * gnu/home/services.scm
> (environment-variables->setup-environment-script): Use conditional
> parameter expansion for XDG_DATA_DIRS and XDG_CONFIG_DIRS.

[...]

> +++ b/gnu/home/services.scm
> @@ -208,7 +208,7 @@ (define (environment-variables->setup-environment-script vars)
>  
>  case $XDG_DATA_DIRS in
>    *$HOME_ENVIRONMENT/profile/share*) ;;
> -  *) export XDG_DATA_DIRS=$HOME_ENVIRONMENT/profile/share:$XDG_DATA_DIRS ;;
> +  *) export XDG_DATA_DIRS=$HOME_ENVIRONMENT/profile/share:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/} ;;

What about doing it this way:

  export "XDG_DATA_DIRS=$HOME_ENVIRONMENT/profile/share${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"

That would avoid adding /usr, which makes little sense for Guix and
could lead to bad surprises on foreign distros, such as loading
incompatible data from the host distro.

WDYT?

>  case $XDG_CONFIG_DIRS in
>    *$HOME_ENVIRONMENT/profile/etc/xdg*) ;;
> -  *) export XDG_CONFIG_DIRS=$HOME_ENVIRONMENT/profile/etc/xdg:$XDG_CONFIG_DIRS ;;
> +  *) export XDG_CONFIG_DIRS=$HOME_ENVIRONMENT/profile/etc/xdg:${XDG_CONFIG_DIRS:-/etc/xdg} ;;

Same question here, though /etc/xdg is a bit less problematic as it
could exist on Guix System too.

Thanks,
Ludo’.
Philip McGrath June 23, 2022, 9:33 p.m. UTC | #2
On Wednesday, June 22, 2022 4:38:11 PM EDT Ludovic Courtès wrote:
> Philip McGrath <philip@philipmcgrath.com> skribis:
> > When the environment initialization script is run, XDG_DATA_DIRS and/or
> > XDG_CONFIG_DIRS may be empty or unset, in which case we must use their
> > respective defaults from the specification, rather than ending the value
> > with a trailing ":". For further discussion, see
> > <https://lists.gnu.org/archive/html/help-guix/2022-05/msg00147.html>.
> > 
> > * gnu/home/services.scm
> > (environment-variables->setup-environment-script): Use conditional
> > parameter expansion for XDG_DATA_DIRS and XDG_CONFIG_DIRS.
> 
> [...]
> 
> > +++ b/gnu/home/services.scm
> > @@ -208,7 +208,7 @@ (define
> > (environment-variables->setup-environment-script vars)> 
> >  case $XDG_DATA_DIRS in
> >  
> >    *$HOME_ENVIRONMENT/profile/share*) ;;
> > 
> > -  *) export XDG_DATA_DIRS=$HOME_ENVIRONMENT/profile/share:$XDG_DATA_DIRS
> > ;; +  *) export
> > XDG_DATA_DIRS=$HOME_ENVIRONMENT/profile/share:${XDG_DATA_DIRS:-/usr/local
> > /share/:/usr/share/} ;;
> What about doing it this way:
> 
>   export
> "XDG_DATA_DIRS=$HOME_ENVIRONMENT/profile/share${XDG_DATA_DIRS:+:}$XDG_DATA_
> DIRS"
> 
> That would avoid adding /usr, which makes little sense for Guix and
> could lead to bad surprises on foreign distros, such as loading
> incompatible data from the host distro.
> 
> WDYT?
> 
> >  case $XDG_CONFIG_DIRS in
> >  
> >    *$HOME_ENVIRONMENT/profile/etc/xdg*) ;;
> > 
> > -  *) export
> > XDG_CONFIG_DIRS=$HOME_ENVIRONMENT/profile/etc/xdg:$XDG_CONFIG_DIRS ;; + 
> > *) export
> > XDG_CONFIG_DIRS=$HOME_ENVIRONMENT/profile/etc/xdg:${XDG_CONFIG_DIRS:-/etc
> > /xdg} ;;
> Same question here, though /etc/xdg is a bit less problematic as it
> could exist on Guix System too.
> 

Unfortunately this doesn't work: on a foreign distro (concretely, for me, Kubuntu 22.04) when XDG_CONFIG_DIRS isn't set globally, this would expand equivalent to just:

    XDG_CONFIG_DIRS=$HOME_ENVIRONMENT/profile/etc/xdg

Arguably, that's slightly better than ending with a trailing ":", since the semantics of an empty element in or at the end of the path list doesn't seem to be defined by the specification. However, it leaves me with the same problem: SDDM can't find the configuration it needs to start my KDE Plasma session successfully.

I do see how /usr would not make a lot of sense for Guix System. Since those paths are written into the spec for empty or unset variables, it seems like Guix System probably should arrange for all of the XDG variables to be set to something non-empty very early, maybe in /etc/profile itself.

I based this patch on the file that gets installed as /etc/profile.d/guix.sh (I haven't found its source yet). Maybe we could leave this code alone if we change that file, instead? Then, both on Guix System and on foreign distros, some system-wide code would be responsible for initializing these search paths, and we could assume in contexts like this that they are explicitly set and not empty.

One catch is that, right now, this is what was installed for me into /etc/profile.d/guix.sh:

```
# _GUIX_PROFILE: `guix pull` profile
_GUIX_PROFILE="$HOME/.config/guix/current"
if [ -L $_GUIX_PROFILE ]; then
  export PATH="$_GUIX_PROFILE/bin${PATH:+:}$PATH"
  # Export INFOPATH so that the updated info pages can be found
  # and read by both /usr/bin/info and/or $GUIX_PROFILE/bin/info
  # When INFOPATH is unset, add a trailing colon so that Emacs
  # searches 'Info-default-directory-list'.
  export INFOPATH="$_GUIX_PROFILE/share/info:$INFOPATH"
fi

# GUIX_PROFILE: User's default profile
GUIX_PROFILE="$HOME/.guix-profile"
[ -L $GUIX_PROFILE ] || return
GUIX_LOCPATH="$GUIX_PROFILE/lib/locale"
export GUIX_PROFILE GUIX_LOCPATH

[ -f "$GUIX_PROFILE/etc/profile" ] && . "$GUIX_PROFILE/etc/profile"

# set XDG_DATA_DIRS to include Guix installations
export XDG_DATA_DIRS="$GUIX_PROFILE/share:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}"
```

but $HOME/.guix-profile doesn't exist for me (only $HOME/.guix-home), so this script exits without setting GUIX_LOCPATH or XDG_DATA_DIRS. Maybe something about that should change?

-Philip
Ludovic Courtès June 25, 2022, 9:39 p.m. UTC | #3
Hi Philip,

Philip McGrath <philip@philipmcgrath.com> skribis:

> I based this patch on the file that gets installed as /etc/profile.d/guix.sh (I haven't found its source yet). Maybe we could leave this code alone if we change that file, instead? Then, both on Guix System and on foreign distros, some system-wide code would be responsible for initializing these search paths, and we could assume in contexts like this that they are explicitly set and not empty.

Yes, changing /etc/profile.d/guix.sh sounds better: it allows us to
provide a solution specifically for foreign distros.

This file is created by ‘etc/guix-install.sh’, the installation script
given at <https://guix.gnu.org/manual/en/html_node/Binary-Installation.html>.

> One catch is that, right now, this is what was installed for me into /etc/profile.d/guix.sh:

[...]

> but $HOME/.guix-profile doesn't exist for me (only $HOME/.guix-home), so this script exits without setting GUIX_LOCPATH or XDG_DATA_DIRS. Maybe something about that should change?

Yes, that too!  We should change it so that it checks
~/.guix-home/profile and ~/.guix-profile (in that order) and picks the
right one.

Would you like to give it a try?

Thanks,
Ludo’.
diff mbox series

Patch

diff --git a/gnu/home/services.scm b/gnu/home/services.scm
index 5ee3357792..ba14d8a119 100644
--- a/gnu/home/services.scm
+++ b/gnu/home/services.scm
@@ -208,7 +208,7 @@  (define (environment-variables->setup-environment-script vars)
 
 case $XDG_DATA_DIRS in
   *$HOME_ENVIRONMENT/profile/share*) ;;
-  *) export XDG_DATA_DIRS=$HOME_ENVIRONMENT/profile/share:$XDG_DATA_DIRS ;;
+  *) export XDG_DATA_DIRS=$HOME_ENVIRONMENT/profile/share:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/} ;;
 esac
 case $MANPATH in
   *$HOME_ENVIRONMENT/profile/share/man*) ;;
@@ -220,7 +220,7 @@  (define (environment-variables->setup-environment-script vars)
 esac
 case $XDG_CONFIG_DIRS in
   *$HOME_ENVIRONMENT/profile/etc/xdg*) ;;
-  *) export XDG_CONFIG_DIRS=$HOME_ENVIRONMENT/profile/etc/xdg:$XDG_CONFIG_DIRS ;;
+  *) export XDG_CONFIG_DIRS=$HOME_ENVIRONMENT/profile/etc/xdg:${XDG_CONFIG_DIRS:-/etc/xdg} ;;
 esac
 case $XCURSOR_PATH in
   *$HOME_ENVIRONMENT/profile/share/icons*) ;;