easybuild-framework icon indicating copy to clipboard operation
easybuild-framework copied to clipboard

Incorrect handling of XDG_DATA_DIRS

Open bsteinb opened this issue 5 years ago • 2 comments

In #3133 a mechanism for modifying XDG_DATA_DIRS was added. However, the logic used there has undesired consequences on systems where XDG_DATA_DIRS is undefined (or empty). According to the XDG Base Directory spec:

If $XDG_DATA_DIRS is either not set or empty, a value equal to /usr/local/share/:/usr/share/ should be used.

EasyBuild simply prepends to the variable and thus overrides the implicit default value of /usr/local/share/:/usr/share/ if XDG_DATA_DIRS is undefined before loading a module that wants to prepend to it.

On one of our systems this leads to Emacs not working if certain modules are loaded, because it can no longer find icons for the GUI.

A better approach for setting XDG_DATA_DIRS would be to check if it is set to a non-empty value and prepend to it if it is, initialize to the implicit default /usr/local/share/:/usr/share/ and prepend to that if it is not.

bsteinb avatar Jun 18 '20 12:06 bsteinb

Thanks a lot for the bug report @bsteinb! We'll try and get that sorted out.

That may not be trivial though, since the logic to decide whether we should add /usr/local/share/:/usr/share/ first needs to go in the generated module file...

boegel avatar Jul 04 '20 19:07 boegel

we have lua code in a module that is always loaded (gentoo or nixpkgs):

if os.getenv("XDG_DATA_DIRS") then
        prepend_path("XDG_DATA_DIRS", pathJoin(root, "usr/share"))
else
        setenv("XDG_DATA_DIRS", pathJoin(root, "usr/share") .. ":/usr/local/share:/usr/share")
end
if os.getenv("XDG_CONFIG_DIRS") then
        prepend_path("XDG_CONFIG_DIRS", pathJoin(root, "etc/xdg"))
else
        setenv("XDG_CONFIG_DIRS", pathJoin(root, "etc/xdg") .. ":/etc/xdg")
end

I'm not sure if that would work for EB in general though. A system in general could initialize XDG_DATA_DIRS (to /etc/xdg) and XDG_CONFIG_DIRS (to /usr/local/share:/usr/share when setting up Lmod or similar).

On our build node the issue is sidestepped also by the existence of flatpak which has this file:

[oldeman@build-node ~]$ rpm -qf /etc/profile.d/flatpak.sh 
flatpak-1.0.9-9.el7_7.x86_64
[oldeman@build-node ~]$ cat /etc/profile.d/flatpak.sh
# /etc/profile.d/flatpak.sh - set XDG_DATA_DIRS

if [ "${XDG_DATA_DIRS#*flatpak}" = "${XDG_DATA_DIRS}" ]; then
    XDG_DATA_DIRS="${XDG_DATA_HOME:-"$HOME/.local/share"}/flatpak/exports/share:/var/lib/flatpak/exports/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
fi

export XDG_DATA_DIRS

bartoldeman avatar Jul 04 '20 20:07 bartoldeman