Whonix Wiki Download Docs News Support Tips Issues Contribute DONATE

How to set global environment variables as a Linux distribution? - /etc/environment.d

How to set global environment variables as a Linux distribution?

Possibilities…


A) systemd /etc/environment.d might not be designed for that:

Pretty weird that systemd implemented /etc/environment.d in a way that is different from what would be expected similar to /etc/environment.


B) Perhaps systemd DefaultEnvironment=?

  • /etc/systemd/user.conf
    • DefaultEnvironment=TESTVAR=xxx
    • works for Qubes terminal emulator but fails for virtual console (dom0: sudo xl console vm-name).
  • /etc/systemd/system.conf
    • DefaultEnvironment=TESTVAR=xxx
    • works for
      • Qubes Debian terminal emulator and in virtual console
      • Debian terminal emulator and in virtual console
  • /usr/lib/systemd/system.conf.d/30_kicksecure.conf
[Manager]
DefaultEnvironment=TESTVAR=1
  • Works for Qubes terminal emulator and in virtual console.

C) Perhaps systemd Environment= for getty? (login shell)


D) Perhaps systemd EnvironmentFile= for getty? (login shell)


E) Debian /etc/environment.d but they didn’t like my feature request. That was probably pre systemd introducing their version of /etc/environment.d. Back then I failed to follow-up with use case examples for some reason as they requested to explain why this feature was requested.

Another attempt to for a feature request /etc/environment.d from Debian (now under a different folder since it’s already taken). Even if they reject it, they might suggest - ideally - an already existing better mechanism.


F) A feature request against PAM upstream, because quote:

The /etc/environment file is owned by pam.


Related discussions:

All packages shipped by Kicksecure / Whonix setting environment variables should deprecate their use of /etc/X11/Xsession.d and /etc/profile.d. Instead. the systemd DefaultEnvironment mechanism should be used.

This style:

Of course, split into different files and contained in the packages that require these.


/etc/X11/Xsession.d and /etc/profile.d mechanism:

  • Works in Debian (and Qubes Debian) in Xorg
  • Doesn’t work for virtual console with zsh.
  • Works with Wayland?
  • Works on non-systemd systems.
    • Related: ⚓ T998 Whonix without systemD (Rejected.)
    • Therefore not important since there are no ports / maintainers for non-systemd enabled systems anyway and also one on the horizon. Other init systems would need to support something similar to DefaultEnvironment.

systemd DefaultEnvironment mechanism:

  • Works in Debian (and Qubes Debian) in Xorg
  • Doesn’t work for virtual console with zsh.
  • Probably works with Wayland.
  • Only for systemd enabled Linux distributions.

Just to note, this is for Bourne shells, not Z shells (unless in compatibility mode)

1 Like

As mentioned here:

systemd DefaultEnvironment mechanism doesn’t work with display manager lightdm for some reason.

Therefore porting all of Kicksecure / Whonix to systemd DefaultEnvironment mechanism is probably not a good idea until that is resolved and this being more tested in more environments.