diff mbox series

[bug#56050,v2,1/2] etc/guix-install.sh: Initialize XDG base directories.

Message ID 605a74b1f064e2b057f6c9d57692dda5bccf8edf.1656899134.git.philip@philipmcgrath.com
State New
Headers show
Series etc/guix-install.sh: Initialize 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 July 4, 2022, 2:35 a.m. UTC
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(-)

Comments

Ludovic Courtès July 4, 2022, 9:11 a.m. UTC | #1
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.

Thanks,
Ludo’.
Philip McGrath July 4, 2022, 4:36 p.m. UTC | #2
Hi,

On Mon, Jul 4, 2022, at 5:11 AM, Ludovic Courtès wrote:
> 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"`:

> 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:

--8<---------------cut here---------------start------------->8---
$ 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"
--8<---------------cut here---------------end--------------->8---

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

-Philip
Ludovic Courtès July 4, 2022, 8:18 p.m. UTC | #3
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.

[...]

> 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’.
Ludovic Courtès July 4, 2022, 9:01 p.m. UTC | #4
"Philip McGrath" <philip@philipmcgrath.com> skribis:

> 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’.
diff mbox series

Patch

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
 }