View previous topic :: View next topic |
Author |
Message |
Massimo B. Veteran
Joined: 09 Feb 2005 Posts: 1810 Location: PB, Germany
|
Posted: Thu Sep 05, 2024 8:04 am Post subject: Understanding package.env, env, package.bashrc, bashrc |
|
|
Discussion about https://wiki.gentoo.org/wiki//etc/portage/package.env and the discussion https://wiki.gentoo.org/wiki/Talk:/etc/portage/package.env#.2Fetc.2Fportage.2Fenv
Quote from https://wiki.gentoo.org/index.php?title=Talk:/etc/portage/package.env&oldid=1310546#.2Fetc.2Fportage.2Fenv:
Quote: | /etc/portage/env
Currently there is no wiki for this location. Eventhough the man-page says in section "package.env" "Beginners should be careful to recognize the difference between these two types", it's not clearly described in the later section "/etc/portage/env/". The Wiki does not make it clearer. From my understanding, in /etc/portage/env there can be 2 type of files. One is placed in the parent dir and must be referenced by /etc/portage/package.env entries, the other is placed like /etc/portage/env/${CATEGORY}/${PN}. The difference is the time of sourcing.
Then there is package.bashrc with referenced files located in bashrc/ but in section "bashrc" of the man-page I read "Additional package-specific bashrc files can be created in /etc/portage/env.".
I'm confused. Is there somewhere the complete call-stack of all env and bashrc files? |
Like for the example in https://wiki.gentoo.org/wiki//etc/portage/package.env#Use_different_MAKEOPTS_for_a_specific_package :
What is the difference between /etc/portage/env/makeopts-jobs-28.conf: | MAKEOPTS="${MAKEOPTS} --jobs=28" |
/etc/portage/package.env: | dev-qt/qtwebengine makeopts-jobs-28.conf | and /etc/portage/env/dev-qt/qtwebengine: | MAKEOPTS="${MAKEOPTS} --jobs=28" | ?
If there is
/etc/portage/env/${CATEGORY}/${PN} in parallel to /etc/portage/env/myconf AND /etc/portage/package.env/ reference, is there also
/etc/portage/bashrc/${CATEGORY}/${PN} in parallel to /etc/portage/bashrc/myconf AND /etc/portage/package.bashrc/ reference
? _________________ HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770 |
|
Back to top |
|
|
Genone Retired Dev
Joined: 14 Mar 2003 Posts: 9608 Location: beyond the rim
|
Posted: Thu Sep 05, 2024 9:07 am Post subject: Re: Understanding package.env, env, package.bashrc, bashrc |
|
|
Massimo B. wrote: | If there is
/etc/portage/env/${CATEGORY}/${PN} in parallel to /etc/portage/env/myconf AND /etc/portage/package.env/ reference, is there also
/etc/portage/bashrc/${CATEGORY}/${PN} in parallel to /etc/portage/bashrc/myconf AND /etc/portage/package.bashrc/ reference
? |
There is no /etc/portage/package.bashrc, that is only available for profiles (for whatever reason), not users. There is /etc/portage/bashrc (a file, not directory) which is sourced globally before package-specific bashrc files.
Quote: | What is the difference between
/etc/portage/env/makeopts-jobs-28.conf:
MAKEOPTS="${MAKEOPTS} --jobs=28"
/etc/portage/package.env:
dev-qt/qtwebengine makeopts-jobs-28.conf
and
/etc/portage/env/dev-qt/qtwebengine:
MAKEOPTS="${MAKEOPTS} --jobs=28"
? |
In that example there is effectively no difference. That comes up when you want to do more fancy stuff:
The first is processed by portage when setting up the initial environment. As stated in the manpage, these files are processed like make.conf, so they can't contain arbitrary bash code and should only be used for setting up environment variables. On the upside you can modify certain variables here that are locked or ineffective when actual bashrc files are processed.
The second is actually sourced by bash when the actual ebuild phase is executed, so it is much more flexible in what it can do syntax-wise. However it will only affect the code executed in ebuild phases, not the base environment used by portage itself.
Quote: | I'm confused. Is there somewhere the complete call-stack of all env and bashrc files? |
Unlikely as it isn't a single call-stack and the complete thing is rather messy. Reason is history: Originally none of these files existed, they were added gradually over time for different incompatible (edge-case) purposes and therefore had to be implemented in different parts of portage.
TL;DR: Just stick to the manpage recommendation: If you want to adjust the ebuild environment (variables), use package.env, that has the best chance to actually do what you expect. If you want to actually execute code, use bashrc files. |
|
Back to top |
|
|
Massimo B. Veteran
Joined: 09 Feb 2005 Posts: 1810 Location: PB, Germany
|
Posted: Thu Sep 05, 2024 9:26 am Post subject: |
|
|
Again, if for the second approach /etc/portage/env/dev-qt/qtwebengine is a sourced bashrc, then it should be better placed at /etc/portage/bashrc/dev-qt/qtwebengine, because it is unusual that some /etc/portage/env tree may contain completely different file types inside.
And what is then the difference to some /etc/portage/package.bashrc/myqtwebenginebashrc: | dev-qt/qtwebengine myqtwebenginebashrc |
/etc/portage/bashrc/myqtwebenginebashrc: | MAKEOPTS="${MAKEOPTS} --jobs=28" |
_________________ HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770 |
|
Back to top |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 22618
|
Posted: Thu Sep 05, 2024 12:43 pm Post subject: |
|
|
You can disagree with what paths were chosen, but they are now locked by history, and convincing anyone to change them is probably difficult. The current values may not be optimal or make the most sense, but they are supported now and people are using them. |
|
Back to top |
|
|
Massimo B. Veteran
Joined: 09 Feb 2005 Posts: 1810 Location: PB, Germany
|
Posted: Thu Sep 05, 2024 12:47 pm Post subject: |
|
|
Sure, I agree. I just try to understand the differences between the currently implemented approaches. _________________ HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770 |
|
Back to top |
|
|
Genone Retired Dev
Joined: 14 Mar 2003 Posts: 9608 Location: beyond the rim
|
Posted: Thu Sep 05, 2024 1:06 pm Post subject: |
|
|
Massimo B. wrote: | Again, if for the second approach /etc/portage/env/dev-qt/qtwebengine is a sourced bashrc, then it should be better placed at /etc/portage/bashrc/dev-qt/qtwebengine, because it is unusual that some /etc/portage/env tree may contain completely different file types inside. |
Agreed, but that has historic reasons as well: /etc/portage/env was first used by a custom bashrc loader (long before package.env was even thought of). When that logic was integrated into portage itself the location was kept to avoid breaking user setups. That package.env later reused that location was probably an unfortunate decision in review, can't recall when that happened and if I had any input on that or was already gone.
Quote: | And what is then the difference to some /etc/portage/package.bashrc/myqtwebenginebashrc: | dev-qt/qtwebengine myqtwebenginebashrc |
/etc/portage/bashrc/myqtwebenginebashrc: | MAKEOPTS="${MAKEOPTS} --jobs=28" |
|
As mentioned in the last post: There is no /etc/portage/package.bashrc, and /etc/portage/bashrc being a directory will likely trigger bash errors. See previous post. |
|
Back to top |
|
|
Massimo B. Veteran
Joined: 09 Feb 2005 Posts: 1810 Location: PB, Germany
|
Posted: Fri Sep 06, 2024 8:15 am Post subject: |
|
|
Genone wrote: | As mentioned in the last post: There is no /etc/portage/package.bashrc, and /etc/portage/bashrc being a directory will likely trigger bash errors. See previous post. |
Really? In man portage I find: Quote: | package.bashrc
Per-package bashrc mechanism. Contains a list of bashrc files to be sourced before emerging a given atom. The bashrc files must be stored in bashrc/, in the profile directory. |
I thought that means /etc/portage/package.bashrc and /etc/portage/bashrc. But it rather means "/bashrc in the profile directory" which is /etc/portage/profile/bashrc, right? What about package.bashrc, where can that be found? _________________ HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770 |
|
Back to top |
|
|
logrusx Advocate
Joined: 22 Feb 2018 Posts: 2401
|
Posted: Fri Sep 06, 2024 8:59 am Post subject: |
|
|
Massimo B. wrote: | Genone wrote: | As mentioned in the last post: There is no /etc/portage/package.bashrc, and /etc/portage/bashrc being a directory will likely trigger bash errors. See previous post. |
Really? In man portage I find: Quote: | package.bashrc
Per-package bashrc mechanism. Contains a list of bashrc files to be sourced before emerging a given atom. The bashrc files must be stored in bashrc/, in the profile directory. |
I thought that means /etc/portage/package.bashrc and /etc/portage/bashrc. But it rather means "/bashrc in the profile directory" which is /etc/portage/profile/bashrc, right? What about package.bashrc, where can that be found? |
Code: | SPECIFIC FILE DESCRIPTIONS
/etc/portage/make.profile/ or /etc/make.profile/
...
package.bashrc
Per-package bashrc mechanism. Contains a list of bashrc files to be sourced before emerging a given atom. The bashrc files must be stored in bashrc/, in the profile directory.
...
|
Did you miss the above part?
Also for completeness:
Code: | SYNOPSIS
/etc/portage/make.profile/ or /etc/make.profile/
site-specific overrides go in /etc/portage/profile/
...
package.bashrc
...
|
However I find it a bit confusing as package.accept_keywords is right above package.bashrc. Is there a separate package.accept_keywords under /etc/portage/make.profile/ or /etc/make.profile/ or /etc/portage/profile?
Best Regards,
Georgi |
|
Back to top |
|
|
Genone Retired Dev
Joined: 14 Mar 2003 Posts: 9608 Location: beyond the rim
|
Posted: Sat Sep 07, 2024 2:27 am Post subject: |
|
|
Massimo B. wrote: | Genone wrote: | As mentioned in the last post: There is no /etc/portage/package.bashrc, and /etc/portage/bashrc being a directory will likely trigger bash errors. See previous post. |
Really? In man portage I find: Quote: | package.bashrc
Per-package bashrc mechanism. Contains a list of bashrc files to be sourced before emerging a given atom. The bashrc files must be stored in bashrc/, in the profile directory. |
|
Yes, but that is not in the section about /etc/portage. I agree that it is probably confusing that profile stuff is listed before user config files.
Quote: | What about package.bashrc, where can that be found? |
As already said, that is only for profiles, not for users. And no idea why it even exists for profiles. Just forget about it.
Quote: | However I find it a bit confusing as package.accept_keywords is right above package.bashrc. Is there a separate package.accept_keywords under /etc/portage/make.profile/ or /etc/make.profile/ or /etc/portage/profile? |
Yes. Not sure why profiles would need that AND package.keywords (which is different from the old package.keywords user config file), but it is available. |
|
Back to top |
|
|
Massimo B. Veteran
Joined: 09 Feb 2005 Posts: 1810 Location: PB, Germany
|
Posted: Mon Oct 21, 2024 6:33 am Post subject: |
|
|
In this context, a question about a usecase:
Currently I have:
/etc/portage/package.env/proxy : | */* http_proxy
app-custom/mycustompackage no_proxy |
/etc/portage/env/http_proxy: | http_proxy="http://wwwcache:8080"
https_proxy="http://wwwcache:8080" |
/etc/portage/env/no_proxy : | http_proxy=""
https_proxy="" |
Now I like to set a http proxy depending on the current network. Where can I add code to check the current network address? env/ does only contain environment variables?
It's not clear from the man-page: Quote: | /etc/portage/env/
package-specific bashrc files | That would actually mean, it interprets bash code like any bashrc.
Would I need to add /etc/portage/bashrc/mycustompackagebashrc for every single package? _________________ HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770 |
|
Back to top |
|
|
flexibeast Guru
Joined: 04 Apr 2022 Posts: 440 Location: Naarm/Melbourne, Australia
|
Posted: Mon Oct 21, 2024 7:39 am Post subject: |
|
|
You're mixing up two different contexts:
* Configuring the environment of the Portage build process. This is where you would use /etc/portage/package.env and /etc/portage/env. You would only be using these paths if you wanted to change the environment of the build process every time the network changes (which i assume is not the case).
* Configuring your system's environment more generally. In that case, you can drop a shell script into /etc/env.d/ - note the lack of "portage" in that path. Alternatively, you can put something in your personal ~/.bash_login file (or equivalent, e.g. ~/.zlogin) to set up environment variables when you log in.
For example, if the network is known by the time you log in, you could put something in your ~/.bash_login to set the proxy based on the output of some command that determines what network you're connected to. _________________ https://wiki.gentoo.org/wiki/User:Flexibeast |
|
Back to top |
|
|
logrusx Advocate
Joined: 22 Feb 2018 Posts: 2401
|
Posted: Mon Oct 21, 2024 8:06 am Post subject: |
|
|
Massimo B. wrote: | In this context, a question about a usecase:
Currently I have:
/etc/portage/package.env/proxy : | */* http_proxy
app-custom/mycustompackage no_proxy |
/etc/portage/env/http_proxy: | http_proxy="http://wwwcache:8080"
https_proxy="http://wwwcache:8080" |
|
I think this won't work. Both will match for mycustompackage and you'll have both proxy and no_proxy.
But also your concept it totally wrong. This configures the environment during the emerge process. See flexibeast's comment above.
Best Regards,
Georgi |
|
Back to top |
|
|
Massimo B. Veteran
Joined: 09 Feb 2005 Posts: 1810 Location: PB, Germany
|
Posted: Mon Oct 21, 2024 12:57 pm Post subject: |
|
|
flexibeast wrote: | You're mixing up two different contexts | What makes you think I would confuse /etc/portage/env with /etc/env.d ?
flexibeast wrote: | For example, if the network is known by the time you log in, you could put something in your ~/.bash_login to set the proxy based on the output of some command that determines what network you're connected to. | Actually yes. But I like to set different proxies per package and for Portage only, not globally. And if setting globally this would rather be a task for NetworkManager.
So currently I'm able to set specific proxies for specific packages, but I can't add code to make that depending on the current network. _________________ HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770 |
|
Back to top |
|
|
logrusx Advocate
Joined: 22 Feb 2018 Posts: 2401
|
Posted: Mon Oct 21, 2024 1:21 pm Post subject: |
|
|
You didn't make that clear.
My first remark still applies.
Best Regards,
Georgi |
|
Back to top |
|
|
Massimo B. Veteran
Joined: 09 Feb 2005 Posts: 1810 Location: PB, Germany
|
Posted: Mon Oct 21, 2024 1:55 pm Post subject: |
|
|
It works like that, I tried. The later has precedence and overwrites the */* default. _________________ HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770 |
|
Back to top |
|
|
Genone Retired Dev
Joined: 14 Mar 2003 Posts: 9608 Location: beyond the rim
|
Posted: Mon Oct 21, 2024 9:15 pm Post subject: |
|
|
Short version, you can't use package.env for that, at least not on its own.
What you can do is to write a custom script for downloading files that adjusts your proxy settings based on whatever condition you like, and then specify that as FETCHCOMMAND in make.conf instead of the default. Wouldn't be surprised if someone already did such a thing as well.
Would only affect regular distfiles downloading though, not any other network access that ebuilds or eclasses might do (e.g. using git).
Quote: | I think this won't work. Both will match for mycustompackage and you'll have both proxy and no_proxy. |
While it does process both files, only the last assigment will hold. So effectively it does work as long as both files set the same variables and are processed in the correct order (not sure if that is properly specified or an implementation detail).
Massimo B. wrote: | But I like to set different proxies per package and for Portage only, not globally. |
Just out of curiosity, why would you want to set proxy per package? Or do you actually want to set it per host? |
|
Back to top |
|
|
flexibeast Guru
Joined: 04 Apr 2022 Posts: 440 Location: Naarm/Melbourne, Australia
|
Posted: Mon Oct 21, 2024 11:46 pm Post subject: |
|
|
Massimo B. wrote: | What makes you think I would confuse /etc/portage/env with /etc/env.d ? |
Because i spend a lot of time writing documentation, helping users with their issues, and clarifying misunderstandings, sometimes involving experienced users. (An all-too-common example is people not making a distinction between the D-Bus system bus and a D-Bus session bus.) As a result, and in the absence of you being explicit about what you're trying to do - "I want to change the network proxy on a per-package basis when building packages" - i assumed that, as an experienced user, you'd provided all relevant information, and that your question wasn't just limited to the build process. And logrusx, who also spends a lot of time trying to help users, apparently interpreted your question the same way. _________________ https://wiki.gentoo.org/wiki/User:Flexibeast |
|
Back to top |
|
|
logrusx Advocate
Joined: 22 Feb 2018 Posts: 2401
|
Posted: Tue Oct 22, 2024 4:45 am Post subject: |
|
|
flexibeast wrote: | i assumed that, as an experienced user, you'd provided all relevant information, and that your question wasn't just limited to the build process. And logrusx, who also spends a lot of time trying to help users, apparently interpreted your question the same way. |
TBH I was surprised too from what looked like and experienced user wanted to do and now that you mention it, I'm even more surprised when I realize an experienced user didn't make their intentions clear.
Best Regards,
Georgi |
|
Back to top |
|
|
Massimo B. Veteran
Joined: 09 Feb 2005 Posts: 1810 Location: PB, Germany
|
Posted: Fri Oct 25, 2024 10:23 am Post subject: |
|
|
Massimo B. wrote: | Currently I have:
/etc/portage/package.env/proxy : | */* http_proxy
app-custom/mycustompackage no_proxy |
/etc/portage/env/http_proxy: | http_proxy="http://wwwcache:8080"
https_proxy="http://wwwcache:8080" |
/etc/portage/env/no_proxy : | http_proxy=""
https_proxy="" |
Now I like to set a http proxy depending on the current network. |
Sorry for being unclear or confusing as an experienced user. I thought showing the configuration that is currently working, with the new requirement "depending on the current network" makes it clear enough:
I'm setting a http_proxy environment for the currently emerged package. It is already package specific, that works. But I can't add code somewhere to make that network related like this:
Being in network A, I need that proxy setup as above. Being in network B, I don't need any proxy at all. _________________ HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770 |
|
Back to top |
|
|
|