If you're new to Wayland as I am, you haven't failed to be frustrated by the greeter / Sway not sourcing any of the usual X or profile configuration files. In i3, you export your variables in .profile and they're set everywhere for the whole session. Not so in Sway.
That means if you have a custom PATH or some exported variable you would like to define session-wide - setting QT_QPA_PLATFORMTHEME so all QT apps use the correct theme in Gnome for instance - you can't. Not the usual way anyway.
Those variables are set if you run a terminal with the shell in login mode, if they're defined in /etc/profile or .profile, but not if you run the program directly in Sway, such as wofi / rofi for example, or any program that needs an environment variable that isn't set.
Here's how to set environment variables for the entire session in Sway:
-
Choose a greeter that understands systemd's environment.d. Unfortunately, there aren't very many. GDM and Plasma are the only two that I know of that do.
-
Define your environment variables in
~/.config/environment.d/envvars.conf
. You can define them the usual way like in profile, including extending variables like $PATH, e.g.:QT_QPA_PLATFORMTHEME=qt5ct PATH=$PATH:/usr/games:~/scripts
-
Either reboot for the changes to take effect, or run
systemctl --user daemon-reload
to get systemd to parse your file again, then log out and back in as with Xorg.
Unfortunately, simply logging out and back in without informing systemd of your changes isn't enough - which is why you need to reboot if you don't do the daemon-reload command.
That's it!
Not too obvious, and not great. But in fairness, it's no more confusing than the mess of shell and X configuration files that existed before systemd and Wayland. It's just that systemd and Wayland are an entirely different complete trainwreck that takes getting used to 😃
That's correct. He's a big fat stinking turd.