Skip to content

enter: better control over copied host envvars #1695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

45mg
Copy link

@45mg 45mg commented Feb 21, 2025

Currently, all host environment variables are copied into the container, except for a hardcoded few that are ignored:

grep -Ev '^(CONTAINER_ID|FPATH|HOST|HOSTNAME|HOME|PATH|PROFILEREAD|SHELL|XDG_SEAT|XDG_VTNR|XDG_.*_DIRS|^_)'); do

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-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:
#656
However, there are usually too many copied environment variables to unset them all individually.
env -i distrobox will 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

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
@45mg
Copy link
Author

45mg commented Feb 21, 2025

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 gdbing the coredump, to no avail.

Then I noticed that git was also broken in the container. This time the error message was easier to search for, and I realised that GIT_EXEC_PATH=/run/current-system/profile/libexec/git-core set by Guix was being copied into the container by distrobox-enter, which was preventing Git from looking under /usr/libexec/git-core. (There were several other such environment variables, too.)

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 --clean-path --no-envvars --additional-envvars WAYLAND_DISPLAY,XDG_SESSION_TYPE.

Hopefully that gives an idea of why this might be a desirable change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant