Skip to content
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

[Suggestion] Update XDG_CONFIG_HOME when created with --home #420

Closed
bsvh opened this issue Sep 17, 2022 · 5 comments
Closed

[Suggestion] Update XDG_CONFIG_HOME when created with --home #420

bsvh opened this issue Sep 17, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@bsvh
Copy link
Contributor

bsvh commented Sep 17, 2022

Is your feature request related to a problem? Please describe.
I created a distrobox with a separate home for working on some software in a clean environment. I noticed that the software was creating config files in my $XDG_CONFIG_HOME, which is set to $HOME/.config. This was unexpected for me, as setting --home was specifically so that user configuration files were not loaded.

Describe the solution you'd like
Unset $XDG_CONFIG_HOME, $XDG_CACHE_HOME, $XDG_DATA_HOME, and $XDG_DATA_DIRS.

Describe alternatives you've considered
You could also set $XDG_ to the standard locations in the container's home, but I think that is making too many assumptions and could be handled by --env. You could also leave it as is and let the user update --env, but I think if someone is using --home they don't want to keep the $XDG_ vars set.

@bsvh bsvh added the enhancement New feature or request label Sep 17, 2022
@orowith2os
Copy link
Contributor

It's probably better to set the XDG base dir variables inside of the custom home, and not unset them; we shouldn't be promoting having the variables unset. The user can override them if desired.

@luc14n0
Copy link
Contributor

luc14n0 commented Apr 3, 2023

Ignoring XDG_* variables inherited from the user's shell configs when using --home might be a better term than unset, but in the end it's basically the same thing: not having them on the container's environment. Of course that re-setting them based on the value passed to --home is another option too.

After a quick assessment, even adding options to keep them (but reset them based on --home's value) and to get rid of them shouldn't be hard.

@luc14n0
Copy link
Contributor

luc14n0 commented Apr 4, 2023

By the way, a quick solution one could use would to go to config file where they are setting the XDG_CONFIG_HOME variable and add some logic so to make a given Distrobox container to either use a different value or just not set the variable at all, something like:

  1. First the logic in the RC file of your shell:
if [ "$DBX_CONTAINER" = "my-container" ]; then
    XDG_CONFIG_HOME=/same/location/used/with/--home
else
    XDG_CONFIG_HOME=/path/to/location/of/choice/on/the/host/system
fi

This was the different values strategy.

if [ "$DBX_CONTAINER" != "my-container" ]; then
    XDG_CONFIG_HOME=/path/to/location/of/choice/on/the/host/system
fi

And this one, selective setting strategy. Only setting XDG_CONFIG_HOME on environments that don't have DBX_CONTAINER=my-container

  1. And now all we need to do is to finally set the variable when launching the Distrobox container.
$ distrobox enter --additional-flags '--env DBX_CONTAINER=my-container' --name my-container-name

The basic idea is to set a specific variable in the container environment that can be checked in the shell config file(s). I personally use this kind of logic to selective choose what the config files do based on where the shell is being opened, whether it's on the host or on a (specific) Distrobox container.

@misobarisic
Copy link
Contributor

misobarisic commented Apr 4, 2023

Distrobox already adds $CONTAINER_ID env variable. You can use it instead of setting something similar manually.

@luc14n0
Copy link
Contributor

luc14n0 commented Apr 5, 2023

Yes, for this particular case using CONTAINER_ID should suffice.

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

No branches or pull requests

4 participants