Export variables set via /environment.d/.conf files (original) (raw)
Description:
filesystem provides /etc/profile setting environment variables.
Recently, systemd got a new feature for configuring environment
variables via */environment.d/*.conf files. Environment variables
configured via these files end up in the environment block of
the systemd user manager. Thus, every service executed by it
is aware of them. However, up to now, these environment variables
do not necessarily end up in login sessions. For instance if
one logs in via the console or ssh, these environment variables
are not set. On the other hand gnome seems to import them
along with also executing a login shell, thus reading /etc/profile.
This leads to the problem mentioned in
https://github.com/systemd/systemd/issues/6414: The environment
variable PATH, if configured via e.g. some file in ~/.config/environment.d/
is overwritten, because /etc/profile is executed as well. On
the other hand an environment variable PATH1 would have a value as
expected.
This feature request is about to make sure that environment variables
have consistent values, independently of whether one logs in via the
console or some graphical session.
A way to achieve this would be to add the following line to /etc/profile
right after the execution of scripts in /etc/profile.d/:
export $(/usr/lib/systemd/user-environment-generators/30-systemd-environment-d-generator)
A user can then configure environment variables either via the logic provided
by systemd or via ~/.profile. Further, this opens up the possibility to smoothly
migrate some scripts in /etc/profile.d to the systemd-logic of setting environment
variables. Examples of such scripts are "jre.sh", "libreoffice-*.sh", "locale.sh",
"mozilla.sh", ...
Thus, environment variables seen by services executed by the systemd user manager
process would get consistent with the ones seen in login sessions.
Additional info:
* filesystem 2017.10-2
Steps to reproduce:
1. Create a file ~/.config/environment.d/10-path.conf with
the following content PATH=foo${PATH:+:$PATH}
and PATH1=foo${PATH:+:$PATH}
2. Log into gnome and execute env in a terminal.
One gets PATH=X and PATH1=foo:X.
3. Login via getty and execute env.
One gets PATH=X and PATH1 is not defined.
Expected would be PATH=foo:X and PATH1=foo:X in
both cases.