FS#77447 - [filesystem][bash|zsh|...] Missing ~/.local/bin from $PATH as per systemd spec

Attached to Project: Arch Linux
Opened by Martin Rys (C0rn3j) - Friday, 10 February 2023, 00:07 GMT
Last edited by Buggy McBugFace (bugbot) - Saturday, 25 November 2023, 20:14 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Sébastien Luttringer (seblu)
Architecture All
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 3
Private No

Details

Description:
systemd specification requires ~/.local/bin/ to be in $PATH, as per https://www.freedesktop.org/software/systemd/man/file-hierarchy.html -
~/.local/bin/
"Executables that shall appear in the user's $PATH search path."

This can be verified on the running system with `systemd-path user-binaries` which will output the path.

To fix this in Bash, one could use following code which is taken from Debian and should be put at the end of https://github.com/archlinux/svntogit-packages/blob/packages/bash/trunk/dot.bash_profile :
```
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
```

I am not sure how to fix this globally for all shells without edits for each, aside from perhaps a drop-in in /etc/profile.d?

Repro of an issue - This path is used by pip which puts its executables into it when installed with --user:

`pip install shell-gpt --user`
`sgpt` will fail because it is in `~/.local/bin/sgpt`

This task depends upon

Closed by  Buggy McBugFace (bugbot)
Saturday, 25 November 2023, 20:14 GMT
Reason for closing:  Moved
Additional comments about closing:  https://gitlab.archlinux.org/archlinux/p ackaging/packages/filesystem/issues/3
Comment by Yuri Cherio (cherio) - Friday, 10 February 2023, 01:08 GMT
Just a note, you shouldn't simply append PATH without checking whether the path you are adding wasn't previously added. Nested login shells will result in multiple ~/.local/bin/ entries in the PATH variable. For this reason "/etc/profile" relies on "append_path" function to ensure the path is not added multiple times.
Comment by Toolybird (Toolybird) - Friday, 10 February 2023, 21:09 GMT
I guess the best place would be "filesystem" as it owns /etc/profile and sets some default paths.
Comment by Michel Koss (MichelKoss1) - Saturday, 11 February 2023, 15:25 GMT
To be clear: the docs doesn't say systemd requires ~/.local/bin/ to be in $PATH similarly as it doesn't require EFI partition be mounted in /efi. It's some suggestion/recommendation.

Arch doesn't add any user owned directory in $PATH by default and doing so may be questionable especially when you prepend those before binaries from /usr as in your example. Putting something that clashes with important system binary could wreak havoc.
Comment by Martin Rys (C0rn3j) - Saturday, 11 February 2023, 16:16 GMT
Here's some existing conversation about this issue and other distro behavior -

Debian and Ubuntu set it - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=839155

Fedora, RHEL and CentOS set it - https://bugzilla.redhat.com/show_bug.cgi?id=1583227

Arch is the outlier here.

As for your concern about clashing with system binaries, that's why other distributions add the user binaries path to the end of $PATH, so such clashes cannot happen in a way that the user binary is preferred.
Comment by Michel Koss (MichelKoss1) - Saturday, 11 February 2023, 16:42 GMT
It's not true: ubunu/debian adds user binary path at the front of $PATH which mean ~/.local/bin/sudo would take over /usr/bin/sudo

Just download "bash" deb package and see /etc/skel/.profile file:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi

It;s worth noting that the fact ubuntu/debian set this in /etc/skel/.profile not /etc/profile means it's effective only for newly created user accounts on system. If Arch is going to add this in PATH it should also be done only for new accounts not manipulate existing ones.
Comment by Martin Rys (C0rn3j) - Saturday, 11 February 2023, 18:29 GMT
Sorry, you're correct at least for Debian(-based), it's even in the example I posted in the OP...

Loading...