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: - -
Where are you defining your "user defined PATH"?
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/.
(In reply to Mike Gilbert from comment #1) > Where are you defining your "user defined PATH"? $HOME/.zshenv
(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
Maybe we could source /etc/profile.env from /etc/zsh/zshenv instead of /etc/zsh/zprofile?
@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.
Ah ha! Thanks for reminding me of bug 19924; has it really been 10 years!?
I know right! I had the 'Wait, this happened before!' and then I found bug 19924 today.
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)
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.
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.
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.