4

Consider the following setup:

  1. I have GDM installed
  2. I have multiple graphical sessions configured, both X11 and Wayland: i3, sway, gnome(x11).

I want to export different sets of environment variables for each of the graphical sessions. For example, I want to set VAR_A=1 for i3, VAR_A=2 for gnome and VAR_A=3 for sway.

There are some more features I need to consider:

  1. systemd-user units should inherit these variables. For example, if I have a service in $HOME/.config/systemd/user/, then it should be launched with VAR_A=1 if I run it from i3.

  2. It should be possible to switch between graphical sessions without manual reconfiguration. For example, if I would exit i3 and launch sway, I wouldn't have to manually replace symlinks or recreate files.

  3. It should be fault-tolerant solution. For example, if I'd accidentally pull of power cord while in i3 and launch sway session afterwards, there wouldn't be a situation, when I'd get i3 environment variables on sway session.

I don't care, if these sets of variables would be loaded in non-graphical sessions (like ssh or tty). I'm also don't mind to change display manager, but I don't really enjoy starting graphical session with startx or its wayland equivalents.

The only way I found is to tinker *.desktop files in /usr/share/xsessions/ and /usr/share/wayland-sessions: wrap every executable in shell script, load variables from session-specific file in $HOME/.config and create symlink to this file in $HOME/environment.d/.

Is there any other solutions to this problem?

0 Answers0