[PATCH] home: services: environment-variables: Fix XDG base directories.

  • Open
  • quality assurance status badge
Details
4 participants
  • Andrew Tropin
  • Ludovic Courtès
  • Maxim Cournoyer
  • Philip McGrath
Owner
unassigned
Submitted by
Philip McGrath
Severity
normal
P
P
Philip McGrath wrote on 18 Jun 2022 07:25
(address . guix-patches@gnu.org)
c8f5f8b21bc299011bd598e9bbdd3d19999d1071.1655528190.git.philip@philipmcgrath.com
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

* 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(-)

Toggle diff (26 lines)
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*) ;;

base-commit: 3154b582567539d8d607344fbd03a3d8456f66cb
--
2.32.0
L
L
Ludovic Courtès wrote on 22 Jun 2022 22:38
(name . Philip McGrath)(address . philip@philipmcgrath.com)(address . 56050@debbugs.gnu.org)
871qvg303w.fsf@gnu.org
Philip McGrath <philip@philipmcgrath.com> skribis:

Toggle quote (10 lines)
> 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.

[...]

Toggle quote (8 lines)
> +++ 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?

Toggle quote (5 lines)
> 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’.
P
P
Philip McGrath wrote on 23 Jun 2022 23:33
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 56050@debbugs.gnu.org)
10145966.nUPlyArG6x@avalon
On Wednesday, June 22, 2022 4:38:11 PM EDT Ludovic Courtès wrote:
Toggle quote (49 lines)
> 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
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEE9GWrrNY3rqwUFVXPygNjjfo/HHoFAmK03BwACgkQygNjjfo/
HHpzdQ/+LLJJdwhXvKCVZEacdIOCoOsyOPerGZkKTCEKSzauB84iBt/rBtA7TJIO
0xTp8PDNF2x/wE/UzLpd4RShwrummsxkSeVVo1fys7Kjf30/1fn2cHMjqGn2oORK
XGkN7eX+pIjQntjUP5hrf7Xi47uyp/F4zCFTFT1SceJ+FUghGtDRI8K61a+ktguD
Qf5Q4R0sE8heuX3+l5CPGoNt2Zq0O0LQ6OJqGM9tsjlGqG3FJrrLbAqiR0cqsweA
ea54z1bgJeZzwBKjNpztCy+JamuueVoAw7IwF3wge2DIkO5II41G9usHM0rBIMFK
t3rlS4JELRkNfBykZVvG6krAAfXKweQrI6AgeKP8puXRGzkXPdfQ8H9SL1IL0Dat
IbZmgxydav2oHVeW9a9Q0ryph2zeZBwe5XicbjBRQKPMHO4NnIa/Cl7Tch9kaw8i
cwAVjE/7vbqj9xiCavoZpMkLbAS7VtgoddxBJgk7+SZD49L4JmnOwqBSv1Uss6nk
ADw+GgAjEB8nghHfBqwe0n5TC3glSET3rJ8iID7TAJKwj+1LQK7epLNaBtaaQSvy
K3ZJM+Su7W3Dtnmce5HitGy8lanD8I068zLaCPmr3//7eJCNYXkPoQ5/MZ4w5iv9
QUOyMfeKQiGK8UtFe20lv58ztrLNjDOrhE1TvS2oGVM+BfAxWWY=
=w65O
-----END PGP SIGNATURE-----


L
L
Ludovic Courtès wrote on 25 Jun 2022 23:39
(name . Philip McGrath)(address . philip@philipmcgrath.com)(address . 56050@debbugs.gnu.org)
878rpktobq.fsf_-_@gnu.org
Hi Philip,

Philip McGrath <philip@philipmcgrath.com> skribis:

Toggle quote (2 lines)
> 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

Toggle quote (2 lines)
> One catch is that, right now, this is what was installed for me into /etc/profile.d/guix.sh:

[...]

Toggle quote (2 lines)
> 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’.
P
P
Philip McGrath wrote on 4 Jul 2022 04:35
[PATCH v2 0/2] etc/guix-install.sh: Initialize XDG base directories.
(address . 56050@debbugs.gnu.org)
cover.1656899134.git.philip@philipmcgrath.com
Hi,

Here is a v2! I've changed the ‘/etc/profile.d/guix.sh’ generated by
‘etc/guix-install.sh’ to initialize all of the XDG base directory
variables---some seem less likely to cause problems, but it should be harmless
to make them all explicit---and to check for ‘~/.guix-home/profile’ before
‘~/.guix-profile’ when looking for the default profile.

I still haven't done anything here about `XCURSOR_PATH`, but I've looked into
the situation more, and there is a Chromium bug [1] that confirms what I
previously thought: the default search path [2] can be overridden by
configuring libXcursor with `--with-cursorpath=`, and Gentoo, at least, does
so [3]. (So far, Gentoo is the only distro I've found that does so.) It seems
like the only way to find out the system's default path is, with
`XCURSOR_PATH` unset, to `dlopen` libXcursor and call `XcursorLibraryPath`.

A further complication is that the default path:

~/.local/share/icons:~/.icons:/usr/share/icons:/usr/share/pixmaps

contains both user-specific and system-wide locations, seemingly with no
reliable way to interject between them.

I think it would not be so bad to ignore this issue, and that's what I propose
doing for now: unlike the problems with the XDG variables, which for me
produced a black screen instead of a desktop environment, the only symptom of
the missing `XCURSOR_PATH` for me was that my cursor disapeared when hovering
over the edges of windows, rather than transforming into a bidirectional
resize cursor.

It might also be reasonable to initialize `XCURSOR_PATH` to
"/usr/share/icons:/usr/share/pixmaps". Even Gentoo's default value for
`XCURSOR_PATH` seems to include those directories.

But I wonder if it really makes sense for
`environment-variables->setup-environment-script` from `(gnu home services)`
to always set `XCURSOR_PATH`. I, for one, don't have any cursors in
`$HOME_ENVIRONMENT/profile/share/icons` (though I do have other kinds of icons
in that path). If we just left `XCURSOR_PATH` alone, we could at least limit
the problem to people who actually want to manage cursors with `guix home`.

In any case, `XCURSOR_PATH` need not block these patches.

-Philip


Philip McGrath (2):
etc/guix-install.sh: Initialize XDG base directories.
etc/guix-install.sh: Check for profile from 'guix home'.

etc/guix-install.sh | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)


base-commit: 4a2f487740fc4a000480226fd25ff2452efa9012
--
2.32.0
P
P
Philip McGrath wrote on 4 Jul 2022 04:35
[PATCH v2 1/2] etc/guix-install.sh: Initialize XDG base directories.
(address . 56050@debbugs.gnu.org)
605a74b1f064e2b057f6c9d57692dda5bccf8edf.1656899134.git.philip@philipmcgrath.com
The default values from the XDG base directory specification make little
sense for Guix System, and some scripts in Guix assume that they are not
"empty or unset": for example, see https://issues.guix.gnu.org/56050.
On foreign distros, however, omitting the default values is likely to
break software from the distro, perhaps even preventing the desktop
environment from starting. To smooth over the difference, use the
system-wide configuration to ensure the environment variables are always
explicitly set on foreign distros.

* etc/guix-install.sh (sys_create_init_profile): Explicitly initialize
XDG base directory variables.
---
etc/guix-install.sh | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

Toggle diff (32 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index cd1a1c34c1..62a33a55c4 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -504,6 +504,16 @@ sys_create_init_profile()
# This will not take effect until the next shell or desktop session!
[ -d "/etc/profile.d" ] || mkdir /etc/profile.d # Just in case
cat <<"EOF" > /etc/profile.d/guix.sh
+# Explicitly initialize XDG base directory variables to ease compatibility
+# with Guix System: see <https://issues.guix.gnu.org/56050#3>.
+export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
+export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
+export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
+export XDG_DATA_DIRS="${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}"
+export XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/etc/xdg}"
+export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
+# no default for XDG_RUNTIME_DIR (depends on foreign distro for semantics)
+
# _GUIX_PROFILE: `guix pull` profile
_GUIX_PROFILE="$HOME/.config/guix/current"
export PATH="$_GUIX_PROFILE/bin${PATH:+:}$PATH"
@@ -522,7 +532,7 @@ export 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/}"
+export XDG_DATA_DIRS="$GUIX_PROFILE/share:$XDG_DATA_DIRS"
EOF
}
--
2.32.0
P
P
Philip McGrath wrote on 4 Jul 2022 04:35
[PATCH v2 2/2] etc/guix-install.sh: Check for profile from 'guix home'.
(address . 56050@debbugs.gnu.org)
9e68ef3237150756a97d0e3eba94a6b08879eeca.1656899134.git.philip@philipmcgrath.com
If "$HOME/.guix-home/profile" exists, use it for GUIX_PROFILE instead of
"$HOME/.guix-profile".

* etc/guix-install.sh (sys_create_init_profile): Check for 'guix home'
profile.
---
etc/guix-install.sh | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

Toggle diff (17 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 62a33a55c4..300681e111 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -524,7 +524,9 @@ export PATH="$_GUIX_PROFILE/bin${PATH:+:}$PATH"
export INFOPATH="$_GUIX_PROFILE/share/info:$INFOPATH"
# GUIX_PROFILE: User's default profile
-GUIX_PROFILE="$HOME/.guix-profile"
+# Prefer the one from 'guix home' if it exists.
+GUIX_PROFILE="$HOME/.guix-home/profile"
+[ -L $GUIX_PROFILE ] || GUIX_PROFILE="$HOME/.guix-profile"
[ -L $GUIX_PROFILE ] || return
GUIX_LOCPATH="$GUIX_PROFILE/lib/locale"
export GUIX_LOCPATH
--
2.32.0
L
L
Ludovic Courtès wrote on 4 Jul 2022 11:11
Re: [PATCH v2 1/2] etc/guix-install.sh: Initialize XDG base directories.
(name . Philip McGrath)(address . philip@philipmcgrath.com)(address . 56050@debbugs.gnu.org)
877d4tgs2u.fsf@gnu.org
Hi!

Philip McGrath <philip@philipmcgrath.com> skribis:

Toggle quote (12 lines)
> The default values from the XDG base directory specification make little
> sense for Guix System, and some scripts in Guix assume that they are not
> "empty or unset": for example, see <https://issues.guix.gnu.org/56050>.
> On foreign distros, however, omitting the default values is likely to
> break software from the distro, perhaps even preventing the desktop
> environment from starting. To smooth over the difference, use the
> system-wide configuration to ensure the environment variables are always
> explicitly set on foreign distros.
>
> * etc/guix-install.sh (sys_create_init_profile): Explicitly initialize
> XDG base directory variables.

[...]

Toggle quote (5 lines)
> +# Explicitly initialize XDG base directory variables to ease compatibility
> +# with Guix System: see <https://issues.guix.gnu.org/56050#3>.
> +export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
> +export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"

I think variable expansion happens at the wrong time:

Toggle snippet (7 lines)
$ cat > /tmp/t <<EOF
> export PATH="$PATH:foobar"
> EOF
$ cat /tmp/t
export PATH="/gnu/store/lq7ysaq5qbxh9xavx1zffgwrg4r8yhsy-profile/bin:/gnu/store/lq7ysaq5qbxh9xavx1zffgwrg4r8yhsy-profile/sbin:/home/ludo/.guix-home/profile/bin:/home/ludo/.guix-home/profile/sbin:/home/ludo/.guix-home/profile/bin:/home/ludo/.guix-home/profile/sbin:/run/setuid-programs:/home/ludo/.config/guix/current/bin:/home/ludo/.guix-profile/bin:/home/ludo/.guix-profile/sbin:/run/current-system/profile/bin:/run/current-system/profile/sbin:/gnu/store/0c1yfbxyv877mlgychfgvmk5ha2jqh52-gzip-1.10/bin:/gnu/store/8fpk2cja3f07xls48jfnpgrzrljpqivr-coreutils-8.32/bin:foobar"

(The problem already exists, and should be fixed, but it’s about
variables that are less likely to be used.)

Could you address that by escaping dollars?

Otherwise LGTM.

Thanks,
Ludo’.
L
L
Ludovic Courtès wrote on 4 Jul 2022 11:13
Re: [PATCH v2 2/2] etc/guix-install.sh: Check for profile from 'guix home'.
(name . Philip McGrath)(address . philip@philipmcgrath.com)(address . 56050@debbugs.gnu.org)
8735fhgs0z.fsf@gnu.org
Philip McGrath <philip@philipmcgrath.com> skribis:

Toggle quote (6 lines)
> If "$HOME/.guix-home/profile" exists, use it for GUIX_PROFILE instead of
> "$HOME/.guix-profile".
>
> * etc/guix-install.sh (sys_create_init_profile): Check for 'guix home'
> profile.

[...]

Toggle quote (4 lines)
> +# Prefer the one from 'guix home' if it exists.
> +GUIX_PROFILE="$HOME/.guix-home/profile"
> +[ -L $GUIX_PROFILE ] || GUIX_PROFILE="$HOME/.guix-profile"

Likewise, we should escape dollar signs.

Ludo’.
P
P
Philip McGrath wrote on 4 Jul 2022 18:36
Re: [PATCH v2 1/2] etc/guix-install.sh: Initialize XDG base directories.
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 56050@debbugs.gnu.org)
99286d24-c62d-4506-b172-dbac712acf9e@www.fastmail.com
Hi,

On Mon, Jul 4, 2022, at 5:11 AM, Ludovic Courtès wrote:
Toggle quote (42 lines)
> Hi!
>
> Philip McGrath <philip@philipmcgrath.com> skribis:
>
>> The default values from the XDG base directory specification make little
>> sense for Guix System, and some scripts in Guix assume that they are not
>> "empty or unset": for example, see <https://issues.guix.gnu.org/56050>.
>> On foreign distros, however, omitting the default values is likely to
>> break software from the distro, perhaps even preventing the desktop
>> environment from starting. To smooth over the difference, use the
>> system-wide configuration to ensure the environment variables are always
>> explicitly set on foreign distros.
>>
>> * etc/guix-install.sh (sys_create_init_profile): Explicitly initialize
>> XDG base directory variables.
>
> [...]
>
>> +# Explicitly initialize XDG base directory variables to ease compatibility
>> +# with Guix System: see <https://issues.guix.gnu.org/56050#3>.
>> +export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
>> +export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
>
> I think variable expansion happens at the wrong time:
>
> --8<---------------cut here---------------start------------->8---
> $ cat > /tmp/t <<EOF
>> export PATH="$PATH:foobar"
>> EOF
> $ cat /tmp/t
> export
> PATH="/gnu/store/lq7ysaq5qbxh9xavx1zffgwrg4r8yhsy-profile/bin:/gnu/store/lq7ysaq5qbxh9xavx1zffgwrg4r8yhsy-profile/sbin:/home/ludo/.guix-home/profile/bin:/home/ludo/.guix-home/profile/sbin:/home/ludo/.guix-home/profile/bin:/home/ludo/.guix-home/profile/sbin:/run/setuid-programs:/home/ludo/.config/guix/current/bin:/home/ludo/.guix-profile/bin:/home/ludo/.guix-profile/sbin:/run/current-system/profile/bin:/run/current-system/profile/sbin:/gnu/store/0c1yfbxyv877mlgychfgvmk5ha2jqh52-gzip-1.10/bin:/gnu/store/8fpk2cja3f07xls48jfnpgrzrljpqivr-coreutils-8.32/bin:foobar"
> --8<---------------cut here---------------end--------------->8---
>
> (The problem already exists, and should be fixed, but it’s about
> variables that are less likely to be used.)
>
> Could you address that by escaping dollars?
>
> Otherwise LGTM.
>

AFAICT, this seems to work. I think this is because of a rule I didn't know about before from the section "Here Documents" under `info "(bash)Redirections"`:

Toggle quote (4 lines)
> If any part of *word* is quoted, the *delimiter* is the result of
> quote removal on *word*, and the lines in the here-document
> are not expanded.

and the beginning EOF is quoted, so it works like this:

Toggle snippet (10 lines)
$ cat quoted-here-doc.sh
#!/bin/sh
cat <<"EOF" > out.sh
export PATH="$PATH:foobar"
EOF
$ ./quoted-here-doc.sh
$ cat out.sh
export PATH="$PATH:foobar"

I'm certainly no expert on shell quoting, though.

-Philip
L
L
Ludovic Courtès wrote on 4 Jul 2022 22:18
Re: bug#56050: [PATCH] home: services: environment-variables: Fix XDG base directories.
(name . Philip McGrath)(address . philip@philipmcgrath.com)(address . 56050@debbugs.gnu.org)
87tu7w7htz.fsf_-_@gnu.org
Philip McGrath <philip@philipmcgrath.com> skribis:

Toggle quote (12 lines)
> The default values from the XDG base directory specification make little
> sense for Guix System, and some scripts in Guix assume that they are not
> "empty or unset": for example, see <https://issues.guix.gnu.org/56050>.
> On foreign distros, however, omitting the default values is likely to
> break software from the distro, perhaps even preventing the desktop
> environment from starting. To smooth over the difference, use the
> system-wide configuration to ensure the environment variables are always
> explicitly set on foreign distros.
>
> * etc/guix-install.sh (sys_create_init_profile): Explicitly initialize
> XDG base directory variables.

[...]

Toggle quote (6 lines)
> If "$HOME/.guix-home/profile" exists, use it for GUIX_PROFILE instead of
> "$HOME/.guix-profile".
>
> * etc/guix-install.sh (sys_create_init_profile): Check for 'guix home'
> profile.

Applied now, thanks, and sorry again for displaying my ignorance! :-)

Ludo’.
L
L
Ludovic Courtès wrote on 4 Jul 2022 23:01
Re: [PATCH v2 1/2] etc/guix-install.sh: Initialize XDG base directories.
(name . Philip McGrath)(address . philip@philipmcgrath.com)(address . 56050@debbugs.gnu.org)
87r1307ftd.fsf@gnu.org
"Philip McGrath" <philip@philipmcgrath.com> skribis:

Toggle quote (19 lines)
> AFAICT, this seems to work. I think this is because of a rule I didn't know about before from the section "Here Documents" under `info "(bash)Redirections"`:
>
>> If any part of *word* is quoted, the *delimiter* is the result of
>> quote removal on *word*, and the lines in the here-document
>> are not expanded.
>
> and the beginning EOF is quoted, so it works like this:
>
> $ cat quoted-here-doc.sh
> #!/bin/sh
> cat <<"EOF" > out.sh
> export PATH="$PATH:foobar"
> EOF
> $ ./quoted-here-doc.sh
> $ cat out.sh
> export PATH="$PATH:foobar"
>
> I'm certainly no expert on shell quoting, though.

Woow, I learned something, thanks! Crazy. (I wonder what Dash does
with that, given that it doesn’t support multi-digit file descriptor
numbers for redirects…)

Ludo’.
A
A
Andrew Tropin wrote on 12 Jul 2022 08:44
Re: [bug#56050] [PATCH v2 2/2] etc/guix-install.sh: Check for profile from 'guix home'.
87r12q25jw.fsf@trop.in
On 2022-07-03 22:35, Philip McGrath wrote:

Toggle quote (25 lines)
> If "$HOME/.guix-home/profile" exists, use it for GUIX_PROFILE instead of
> "$HOME/.guix-profile".
>
> * etc/guix-install.sh (sys_create_init_profile): Check for 'guix home'
> profile.
> ---
> etc/guix-install.sh | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/etc/guix-install.sh b/etc/guix-install.sh
> index 62a33a55c4..300681e111 100755
> --- a/etc/guix-install.sh
> +++ b/etc/guix-install.sh
> @@ -524,7 +524,9 @@ export PATH="$_GUIX_PROFILE/bin${PATH:+:}$PATH"
> export INFOPATH="$_GUIX_PROFILE/share/info:$INFOPATH"
>
> # GUIX_PROFILE: User's default profile
> -GUIX_PROFILE="$HOME/.guix-profile"
> +# Prefer the one from 'guix home' if it exists.
> +GUIX_PROFILE="$HOME/.guix-home/profile"
> +[ -L $GUIX_PROFILE ] || GUIX_PROFILE="$HOME/.guix-profile"
> [ -L $GUIX_PROFILE ] || return
> GUIX_LOCPATH="$GUIX_PROFILE/lib/locale"
> export GUIX_LOCPATH

I think here we don't need to prefer one over another. Let's just
repeat the process for both of them. If home profile exists source it,
if user profile exists source it as well.

--
Best regards,
Andrew Tropin
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmLNGGMACgkQIgjSCVjB
3rAL+Q/+PwVXkPWCwr3FHfpGhZmheO1TIT5ybtxnCGLIH0Du6znYAfMeRn9Zu9SL
Fl5EAtGixEwpOklzu1vF/M72ISYQ84w2uBUCR7HYBHoz2NJT1AksAWznKX4tG7ZD
GxBqV0aylkbIkEao6Abdf9Gwq21O7pOYwdHEw/X1XW4ItK6ofOkZ07ga2KllVgDE
dE1f32bWIFnYLdGDwwYlOfm9ximtOzt552t0D08AineXESh49Rk/ejcxViTNCOrz
d6GEE6tu5D9yy0+/wp/Fytfe1LtbOBD3ZynBEHb2Nprw8sLxAsLsJ2AVRcC75eQ8
dcpzuUsdAkeKxCmBr4Eu1jzkbAgwUjgMpJ/azMCVx7yyEW7c9e8JrJI7pL6M/Yij
frCVMQJI2ShR7YrTDFksNj9utMpAnFtccikuMfZUj/4MNd37pSKRfinEq8wC7SFZ
J11NeVURUUUk/PM85omWzcIgG2rSpUIvQNbmsue9BWW7Ft9u/zO7eozjSSInOmwD
A9dpxPolov9H9xtdqPUmEEu8Myr2aGZS2niPLKiSGA1yehvjHZANHQrgTUOMzqr5
mAen0mXJaEokgzwJpGcnYAOLV0WcmiQKFgrc/fiY7HlCeRohKncPQAYiP/P3CHoF
soqs3B8ebXQ/v2mRXg+W8KyLanq/yxKZIN6e2Lw5q0KkUEdpuYQ=
=yfgI
-----END PGP SIGNATURE-----

M
M
Maxim Cournoyer wrote on 3 Jan 2023 23:24
control message for bug #56050
(address . control@debbugs.gnu.org)
871qobz26c.fsf@gmail.com
tags 56050 + moreinfo
quit
?