[systemd-devel] Cannot set PATH environment variable from environment.d

Yeongjin Kwon yeongjinkwon at gmail.com
Sun Dec 4 22:48:10 UTC 2022


Hi, I've been trying to set the PATH environment variable in systemd
user daemon with environment.d but it's not working. I'm using Arch
Linux, and my systemd version is below:
> systemd 252 (252.2-2-arch)
> +PAM +AUDIT -SELINUX -APPARMOR -IMA +SMACK +SECCOMP +GCRYPT +GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY +P11KIT -QRENCODE +TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD -BPF_FRAMEWORK +XKBCOMMON +UTMP -SYSVINIT default-hierarchy=unified

I created a file at the path ~/.config/environment.d/50-my-vars.conf
with the following content:
> PATH=custom_path
> ANOTHER_VAR=foo
and then ran `systemctl --user daemon-reload` and then `systemctl
--user show-environment`. The latter command showed that ANOTHER_VAR
had been set to foo, but PATH had not changed. I replaced the content
of the file with:
> PATH=bar
> ANOTHER_VAR=baz
and daemon-reloaded again, but only ANOTHER_VAR had changed to baz and
PATH remained the same again.

To see if the issue was with my environment.d config, I ran
`/usr/lib/systemd/user-environment-generators/30-systemd-environment-d-generator`.
It showed the same output as my environment.d config.
I also made a script with the following content:
> #!/bin/bash
>
> echo "$PATH" > /tmp/log.txt
and placed it at
/run/systemd/user-environment-generators/99_test_generator. When I
daemon reloaded and checked the value of /tmp/log.txt, it showed the
value of PATH that I set in my environment.d config. I then moved the
script to /run/systemd/user-generators/99_test_generator and daemon
reloaded again, and it also showed the same value.
What I gathered from this is that the problem is not with the
generators. The environment.d generator is working and it's setting
PATH to what I expect, but this change is either undone by something
else later in the daemon reload, or is not being propagated to the
actual systemd environment.

After that, I checked if I could adjust the PATH myself manually. I
ran `systemctl --user set-environment PATH=my_path_value`, and checked
the systemd environment. It showed that PATH had been updated to
my_path_value. This new value of PATH persisted after I daemon
reloaded multiple times.

And so I honestly can't figure out what is going on at this point. I'm
guessing something is preventing a change to PATH from environment
generators from propagating to systemd's actual environment, but I
have no clues as to what that may be. Could someone help me understand
why my environment.d configuration is not setting PATH to what I want?
Thank you.


More information about the systemd-devel mailing list