You are not logged in.

#1 2017-06-25 14:31:32

n0rv
Member
Registered: 2012-02-27
Posts: 50

How to set system-wide $PATH for all systemd units in user instance?

How it works for me:
1. I don't use login manager, so I log in into tty
2. Systemd user instance runs and then starts all the things..

Problem: $PATH in login shell (zsh) is different than in interactive shell.

Login shell:

/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl

Interactive shell:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin

Of course, problem lies in systemd configuration.

What I tried:
1. ZSH PATH configuration, but this obviously don't work, because /etc/profile is not sourced for interactive shells.
2. Systemd PATH configuration, but this also don't work. I'm not even sure how it is supposed to work. Putting this in ~/.zprofile or using in interactive shell don't take any effect.

What I somewhat dislike, but I can live with that if there is no better solution.
1. Sourcing /etc/profile every time I start interactive shell. Simple, but I don't like it, because /etc/profile is supposed (I think) to be sourced once.
2. Setting $PATH manually in systemd configuration.

So. How to set $PATH in user instance to system wide $PATH, whatever it is, without setting it manually?

Last edited by n0rv (2017-06-25 14:33:38)

Offline

#2 2017-06-25 14:55:35

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,545
Website

Re: How to set system-wide $PATH for all systemd units in user instance?

You link to the wiki page that tells you how to set the PATH for interactive zsh shell sessions, yet you do not do what it instructs.  Perhaps you should.

(edit: removed potential misunderstanding - note that one of your comments is a bit ambiguous and rubbed me quite the wrong way "Of course, problem lies in systemd configuration" initially read like you were blaming systemd.  I'm now not quite sure if that was the intent.  If it was, you should reconsider.)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2017-06-25 18:57:47

n0rv
Member
Registered: 2012-02-27
Posts: 50

Re: How to set system-wide $PATH for all systemd units in user instance?

You link to the wiki page that tells you how to set the PATH for interactive zsh shell sessions, yet you do not do what it instructs.

It don't work. I mean, do I need to add missing paths (perl, java) to $PATH manually in ~/.zprofile?

I think this is related to systemd configuration, because following command have different results depending on where I run it.

In tty:

$ systemctl --user show-environment | grep PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl

In all interactive shells:

$ systemctl --user show-environment | grep PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin

That difference bugs me, because I don't know why this happen and how to change this.

Last edited by n0rv (2017-06-25 19:08:53)

Offline

#4 2017-06-25 19:13:31

Scimmia
Fellow
Registered: 2012-09-01
Posts: 13,729

Re: How to set system-wide $PATH for all systemd units in user instance?

Sounds like you have a DM that's screwing things up.

Offline

#5 2017-06-25 19:34:19

n0rv
Member
Registered: 2012-02-27
Posts: 50

Re: How to set system-wide $PATH for all systemd units in user instance?

I don't use DM.

My previous post contains some wrong information, show-environment command has different result in tty, so I post it again.

I put this into my ~/.zprofile script:

echo $PATH > zprofile.txt
systemctl --user show-environment >> zprofile.txt

Contents of zprofile.txt file looks like this:

/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1003/dbus/user_bus_socket
HOME=/home/ill
JOURNAL_STREAM=9:84231
LANG=pl_PL.UTF-8
LOGNAME=ill
MAIL=/var/spool/mail/ill
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
SHELL=/bin/zsh
USER=ill
XDG_RUNTIME_DIR=/run/user/1003

As you can see $PATH set by shell is different than set by systemd.

Edit: I know that systemd don't inherit environment by default, but I can't find option to change that. Or it doesn't exist?

Edit2: Ok, I took a shower and now understand how this works. Systemd user instance and login shell are separate, unrelated things and systemd can't inherit environment (even if it would) from login shell, because user instance was launched by system instance, not login shell.
So, I need to set environment separately (or change the way of starting things).

Solved.

Last edited by n0rv (2017-06-25 20:10:05)

Offline

#6 2017-06-25 20:03:46

loqs
Member
Registered: 2014-03-06
Posts: 19,114

Re: How to set system-wide $PATH for all systemd units in user instance?

Perhaps this is an X-Y problem why can the service not specify the canonical path to the executable?

Offline

Board footer

Powered by FluxBB