enter: better control over copied host envvars#1695
Conversation
Currently, all host environment variables are copied into the container, except for a hardcoded few that are ignored: https://github.com/89luca89/distrobox/blob/3b9f0e8d3d8bd102e1636a22afffafe00777d30b/distrobox-enter#L434 This is not always the desired behavior, particularly on host distros like NixOS or Guix that break from the FHS and need to set a lot of environment variables to work around the resulting issues: 89luca89#1516 Therefore, provide a --no-envvars option to disable the default copying of environment variables, and an --additional-envvars option to copy specific ones. It was suggested to use `env -u distrobox` in order to unset specific environment variables: 89luca89#656 However, there are usually too many copied environment variables to unset them all individually. `env -i distrobox` will unset environment variables, but that includes PATH and other things needed for distrobox to execute correctly on the host. Other instances of this feature being requested: 89luca89#508 89luca89#743 89luca89#1173
|
I thought I should give a specific example of how this is useful, so here goes: I installed Distrobox for the first time, on Guix. When I tried to run Emacs from a Fedora container, it segfaulted. I spent hours trawling through bug trackers and Then I noticed that After fixing this, it dawned on me that I was probably seeing the same issue with Emacs. Eventually, after painstakingly unsetting dozens of environment variables, I managed to get it to launch fine. With this PR, I just have to pass Hopefully that gives an idea of why this might be a desirable change. |
dottorblaster
left a comment
There was a problem hiding this comment.
Thanks for the PR!
I took the liberty to give you some suggestions about the naming. We would like to merge this but we also would like the naming of the options (and of course the naming of the associated variables) to be --empty-env and --add-env.
Can I also ask you to rebase this PR against the latest main?
Thank you so much!
| --no-tty/-T: do not instantiate a tty | ||
| --no-workdir/-nw: always start the container from container's home directory | ||
| --no-envvars: don't copy host environment variables (default is to copy whenever reasonable) | ||
| --additional-envvars: comma-separated list of additional host environment variables to copy |
There was a problem hiding this comment.
| --additional-envvars: comma-separated list of additional host environment variables to copy | |
| --add-env: comma-separated list of additional host environment variables to copy |
Co-authored-by: Alessio Biancalana <alessio@dottorblaster.it>
Co-authored-by: Alessio Biancalana <alessio@dottorblaster.it>
Co-authored-by: Alessio Biancalana <alessio@dottorblaster.it>
Co-authored-by: Alessio Biancalana <alessio@dottorblaster.it>
Co-authored-by: Alessio Biancalana <alessio@dottorblaster.it>
Co-authored-by: Alessio Biancalana <alessio@dottorblaster.it>
| if [ "${empty_env}" -eq 0 ]; then | ||
| set +o xtrace | ||
| # disable logging for this snippet, or it will be too talkative. | ||
| for i in $(printenv | grep '=' | grep -Ev ' |"|`|\$' | |
Currently, all host environment variables are copied into the container, except for a hardcoded few that are ignored:
distrobox/distrobox-enter
Line 435 in 3b9f0e8
This is not always the desired behavior, particularly on host distros like NixOS or Guix that break from the FHS and need to set a lot of environment variables to work around the resulting issues:
#1516
Therefore, provide a
--no-envvarsoption to disable the default copying of environment variables, and an--additional-envvarsoption to copy specific ones.It was suggested to use
env -u distroboxin order to unset specific environment variables:#656
However, there are usually too many copied environment variables to unset them all individually.
env -i distroboxwill unset all environment variables, but that includes PATH and other things needed for distrobox to execute correctly on the host.Other instances of this feature being requested:
#508
#743
#1173