Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 906337 - app-shells/zsh-5.9-r3: Allow users to override PATH
Summary: app-shells/zsh-5.9-r3: Allow users to override PATH
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Piotr Karbowski (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-05-14 19:38 UTC by Morteza
Modified: 2023-05-16 20:54 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Morteza 2023-05-14 19:38:15 UTC
I have to rename /etc/zsh/zprofile everytime on a new install because zprofile execute /etc/profile.env which replaces user defined PATH
I tried to use `typeset -U path` like exaplined in archwiki https://wiki.archlinux.org/title/zsh#Configuring_$PATH and it didn't change anything.

Reproducible: Always

Actual Results:  
-


-
Comment 1 Mike Gilbert gentoo-dev 2023-05-15 21:42:13 UTC
Where are you defining your "user defined PATH"?
Comment 2 Piotr Karbowski (RETIRED) gentoo-dev 2023-05-16 07:29:07 UTC
If you alter PATH in either /etc/profile.d/* or in .zshrc in user home directory it will not be overwritten by zprofile.

There's also comment inside /etc/zsh/zprofile

    # You should override these in your ~/.zprofile (or equivalent) for per-user
    # settings.  For system defaults, you can add a new file in /etc/profile.d/.
Comment 3 Morteza 2023-05-16 17:40:52 UTC
(In reply to Mike Gilbert from comment #1)
> Where are you defining your "user defined PATH"?

$HOME/.zshenv
Comment 4 Morteza 2023-05-16 17:48:05 UTC
(In reply to Piotr Karbowski from comment #2)
> If you alter PATH in either /etc/profile.d/* or in .zshrc in user home
> directory it will not be overwritten by zprofile.
> 
> There's also comment inside /etc/zsh/zprofile
> 
>     # You should override these in your ~/.zprofile (or equivalent) for
> per-user
>     # settings.  For system defaults, you can add a new file in
> /etc/profile.d/.

why should i define PATH in .zshrc? make n sense .zshenv is where all environment vars should go
I have customized user zshenv in .config/zsh/.zprofile as well
Comment 5 Mike Gilbert gentoo-dev 2023-05-16 17:55:17 UTC
Maybe we could source /etc/profile.env from /etc/zsh/zshenv instead of /etc/zsh/zprofile?
Comment 6 Piotr Karbowski (RETIRED) gentoo-dev 2023-05-16 19:27:29 UTC
@floppym I am afraid we would have regression bug from 10 years ago if we change it into /etc/zsh/zshenv, see bug 19924 that both me and you participated in. We did it back then and it broke many users, myself including and was ultimately reverted.

Taking a look at man 1 zshall

       Commands are then read from $ZDOTDIR/.zshenv.  If the shell is  a  login  shell,
       commands  are read from /etc/zprofile and then $ZDOTDIR/.zprofile.  Then, if the
       shell is  interactive,  commands  are  read  from  /etc/zshrc  and  then  $ZDOT‐
       DIR/.zshrc.   Finally,  if  the  shell  is a login shell, /etc/zlogin and $ZDOT‐
       DIR/.zlogin are read. 


Meaning that .zshenv as Morteza uses is rather unfortunate place to put environmental variables in, it is not something like /etc/env.d or /etc/profile.env, but in fact it is the same script like .zshrc or .zlogin, just executed as the very first one in the following order.

Going with the what Morteza request would mean that for every zsh instance we would throw out .zshrc configuration if it is overwritten at any point in /etc/zsh/zshenv, and it is what I consider the default modus operandi to set PATH inside .zshrc, much like it is in .bashrc.

@Morteza: use .zshrc or .zprofile to set PATH, even with the workflow that you insist on using with zshenv, if you were to set PATH during runtime of shell and then spawn another zsh instance or zsh script, it would overwrite it and therefore not work, like starting zsh after loading Python's virtualenv leading to dropped venv's bin directory.
Comment 7 Mike Gilbert gentoo-dev 2023-05-16 19:37:51 UTC
Ah ha! Thanks for reminding me of bug 19924; has it really been 10 years!?
Comment 8 Piotr Karbowski (RETIRED) gentoo-dev 2023-05-16 19:45:43 UTC
I know right! I had the 'Wait, this happened before!' and then I found bug 19924 today.
Comment 9 Morteza 2023-05-16 19:54:12 UTC
Thanks for your detailed comment
archlinux profile.env appends to PATH instead of overriding it entirely maybe that would fix the issue
I'm too sensitive about splitting configs and env variables that's why they are zsh(rc) and zsh(env)
Comment 10 Piotr Karbowski (RETIRED) gentoo-dev 2023-05-16 20:03:15 UTC
I am afraid appending would break the workflow of how `env-update` and `/etc/env.d/` works on gentoo, and therefore would lack a way to pruge the PATH or other variables set there in case those env.d files were removed.

The only idea I have left if for you to move whatever you want in .zshenv to separated file, say ~/.env, and source it .zshrc, this way you maintain your separated environmental variable file from config, sort of. You could put as the very first line of .zshrc

    . "${HOME}/.env"

And continue with your day, for your needs, if you *only* setup environmental variables there, you could even symlink it to .zshenv, or have it source .zshenv, though remember you'd need to export them for child processes to see them.
Comment 11 Morteza 2023-05-16 20:25:35 UTC
that's not identical as i have to set ZDOTDIR in .zshenv as well so there will be two env file(.zshenv and .env)
I will continue removing /etc/zsh/zprofile that's a cleaner solution.
Comment 12 Piotr Karbowski (RETIRED) gentoo-dev 2023-05-16 20:54:42 UTC
That way you are abandoning the PATH set by /etc/env.d, which could lead to many issues along the way, like not working clang/llvm being one of them. I would highly recommend you rethink your workflow as you are en route to enormous number of issues just from the desire to use PATH out of .zshenv.

Regardless, I will be closing this as WONTFIX as there's no action I see we could carry. Should you believe otherwise now or in future, you have means to reopen it.