You are not logged in.
Upon login to raw Linux console (no desktop environment), command shell environment variables can simply be set from /etc/profile (or /etc/csh.login). But when a login/display manager is used, those shell login files are generally not used.
I run Sway and I'm aware of one method of using a wrapper script that sets environment variables then starts sway and hence terminal shells started within sway inherit the environment. That itself is adequate for my needs. However, is use of systemd, e.g. .conf files in /etc/environment.d, a more standard method? If so, how would a login/display manager acquire the environment variables from systemd? Do some login/display managers already have support for systemd /etc/environment.d .conf files?
Update: I found this, which is helpful: https://wiki.archlinux.org/title/Enviro … nd_session
In some cases PAM may be involved.
https://wiki.archlinux.org/title/Enviro … ng_pam_env
Solution: https://bbs.archlinux.org/viewtopic.php … 5#p2271195
Last edited by Gregory_M (2025-11-05 07:22:30)
Offline
systemctl --user show-environment. and /usr/lib/systemd/user-environment-generators/30-systemd-environment-d-generator ouput systemd environment variables.
Environment variables can be specified in .conf files in
/etc/environment.d/
~/.config/environment.d/
PAM also supports system-wide environment variables in /etc/environment. However, use of systemd is generally favored over PAM now and note that systemd supports both system-wide and per-user environment variables. PAM only supports system-wide as per-user PAM is deprecated..
Some display manager(s) or DE(s) integrate with systemd directly for environment variables. However, commands such as systemctl --user show-environment (see above) can be used for multiple scenarios including desktop console login, desktop window environment, and even server. This is powerful because A.) It's independent of scenario and B.) It allows specifying environment variable values in one location that is independent of the particular shell - i.e. specifically for environment variables, this use of systemd allows deprecation of /etc/profile and ~/.profile files (as well as the analogous files for shells that are not Bourne-compatible).
The output of
systemctl --user show-environment (or 30-systemd-environment-d-generator)is a simple list of ENV_VAR=value entries that can be used as environment variables for various shells. Granted, command shells generally require some scripting for that purpose, but the list is in a very simple form, and so the integration scripting is generally not complex.
Summary:
In any environment (console, server, desktop windowing environment), systemd .conf files can be used as a single source for all environment variables for various command shells and desktop environments. However, traditional shell profile files (or analogous files, depending upon the particular shell), can also be used, including for desktop environments. For use of either systemd or traditional shell environment files for environment variables in desktop environments (e.g. Sway) wrapper scripts that set the environment variables and run the window manager can be used. Some login/display managers and/or desktop environments already integrate use of systemd for environment variables. (GNOME is actually becoming systemd-dependent, that's a separate topic, but it shows the trend towards systemd and that systemd, as an infrastructure, supports management of environment variables.)
Last edited by Gregory_M (2025-11-05 07:48:47)
Offline
Icommand shell environment variables can simply be set from /etc/profile (or /etc/csh.login). But when a login/display manager is used, those shell login files are generally not used.
What makes you think a display manager doesn't start a login shell when it starts a user session ?
Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.
clean chroot building not flexible enough ?
Try clean chroot manager by graysky
Offline
What makes you think a display manager doesn't start a login shell when it starts a user session ?
Because: I see no reason why a display manager needs to invoke the user-specific shell (/etc/passwd) to start the window environment. In the case of sway for example, sway is an executable that can be run and I am not aware of any need that window environments must be started within a shell process rather than directly from the display/login manager process (including any greeter sub-process of display manager).
However, I do now understand and agree that systemd is not an adequate replacement for the /etc/profile process, e.g. PATH entries that me be added by files in /etc/profile.d as needed.
My current strategy is to use the wrapper script approach (as needed) when a display/login manager is used.
Thank You
Last edited by Gregory_M (2025-11-06 23:48:26)
Offline