6 Setting Environmental Variables
Sergey A edited this page 2023-01-16 16:37:21 +03:00

How you set variables will depend on how sway was started. The explanation below was based on these sources

Environment variables are inherited from the process that starts sway. You need to set variables there.

Some of the possible options are:

  • login manager: check the documentation.
  • login shell: export them there before launching sway.
  • user service: use the EnvironmentFile= key and an environment file.

Login Manager

PAM

You can set environment variables through pam_env, however they will be set system-wide, including across different sessions and users.
There are two ways you can configure PAM to load environment variables, by editing /etc/security/pam_env.conf or /etc/environment.

Example for /etc/security/pam_env.conf (QT_QPA_PLATFORMTHEME being the variable we want to edit, qt5ct being the value we want to set):

QT_QPA_PLATFORMTHEME DEFAULT=qt5ct

Example for /etc/environment consisting of the same variable/value:

QT_QPA_PLATFORMTHEME=qt5ct

You could also edit ~/.pam_environment the same way you would with /etc/environment, however that is deprecated since PAM 1.5.0 and will likely be removed at some point in the future. Therefore, this method is discouraged. See their changelog.

For more information about this approach, see this ArchWiki page.

Set the Sway Config

Technically, you could set them in your sway config.

Login Shell

If you launch sway from your login shell, your ~/.zprofile or ~/.profile should work.

User Service

You can set variables using the environment.d. Environment variables set there will be read by the --user systemd, and since everything is started in its hierarchy variables will properly propagate. This will not work with some login managers.

For more info: man environment.d

Example with sddm as login manager