On Gnome with Systemd, systemd user environment variables are configured using the systemd environment.d mechanism, which doesn't rely on shell scripts, but on configuration files.
In parallel, many environment variables are defined in the Gnome session using exports in scripts in /etc/profile.d/*.
These two systems (the environment.d configuration files and the scripts in /etc/profile.d/*) are not permeable (even if there are ways to manually import these variables, like systemctl --user import-environment)
Moreover, when using Wayland, there is no sourcing of the /etc/profile.d/* scripts as it is done in Gnome on Xorg (using the /etc/gdm/Xsession script, which itself sources /etc/profile which itself sources the /etc/profile.d/* and ~/.profile scripts).
So the variables exported in these /etc/profile.d/* shouldn't appear in the systemd user environment when using Gnome, neither in Xorg, and a fortiori neither with Wayland.
However, this is not the case.
For example, the /etc/profile.d/google-cloud-sdk.sh script exports some custom variables:
export CLOUDSDK_ROOT_DIR=/opt/google-cloud-sdk
export CLOUDSDK_PYTHON=/usr/bin/python
export CLOUDSDK_PYTHON_ARGS=-S
export PATH=$CLOUDSDK_ROOT_DIR/bin:$PATH
export GOOGLE_CLOUD_SDK_HOME=$CLOUDSDK_ROOT_DIR
And after logging in on Gnome on Wayland and on Xorg, we run systemctl --user show-environment
And we see the exact same variables:
...
XDG_RUNTIME_DIR=/run/user/1000
CLOUDSDK_PYTHON=/usr/bin/python
CLOUDSDK_PYTHON_ARGS=-S
CLOUDSDK_ROOT_DIR=/opt/google-cloud-sdk
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
...
GOOGLE_CLOUD_SDK_HOME=$CLOUDSDK_ROOT_DIR
...
Among many other variables.
Two additional remarks:
- variables exported in
~/.profileare not seen in the systemd user environments, which would imply that the/etc/profilescript is itself not sourced: the/etc/profile.d/*scripts seem to be sourced directly - There is no reference to any
/etc/profile.d/*script in the systemd environment generators
So, how is this possible, considering the fact there is no documented way for systemd or gnome to source these /etc/profile.d/* scripts?