Change env for the main session?

Hi, I’m looking to make a GNOME extension that modifies the environment of the main shell / session and not just its own env. Specifically, I’m wanting to modify $XDG_DATA_DIRS to define custom folders for storing .desktop files. Is this something that is possible? My early testing doesn’t show any way to do it so far.

.profile on each login to add something, maybe .bashrc for bash scripts, but pressume that bash(sh) is available with some permissions or environment variables set is not always accepted

env command tells what is accessible and present, tweaking system settings is mess elsewhere and also some preferences maybe in /etc/… somewhere or user settings… GNOME prefers dbus, dconf and similars… and dconf-editor could do that via UI, but applications have their own settings there and environment like GNOME DEnvironment preciselly do that when load settings from there and put their own settings in their own config or runtime files…

With systemd you can drop a .conf file in ~/.config/environment.d/ to affect the user’s environment (on login). To add a directory to $XDG_DATA_DIRS you could use a line like:

XDG_DATA_DIRS=${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}/your/path/to/add

That is looking to be the route I take. One noticable downside however is that the user has to log out and log back in for the extension to take effect (to load the file in ~/.config/environment.d). Still exploring around for other possible avenues.

You cannot change the environment of a session at run time: environment variables are only ever read when a process starts.