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

[Error] Environment Variables Not Set Correctly When Using distrobox-enter -- command #1488

Open
ZefQ opened this issue Jul 22, 2024 · 3 comments
Labels
bug Something isn't working wait-on-user waiting for a reply

Comments

@ZefQ
Copy link

ZefQ commented Jul 22, 2024

Describe the bug
When exporting applications installed in a distrobox container to the host, the environment variables within the container are not correctly set up when executing commands via distrobox-enter -- command. This results in the PATH environment variable from the host being used instead of the one from the container, causing the application to fail to find its executable.

To Reproduce

  1. Export an application from a distrobox container to the host, that is not installed in a path that is also a part of the host $PATH creating a .desktop file.
  2. Attempt to run the exported application from the host.
  3. Check the PATH environment variable by running echo $PATH through distrobox-enter.

Expected behavior
The PATH environment variable should reflect the container's environment, ensuring that the application can locate its executable.

Actual behavior
The PATH environment variable reflects the host's environment, causing the application to fail due to missing paths.

Example
On the host:

❯ echo $PATH
/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/username/.local/bin:/home/username/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin

Using distrobox-enter -- command:

❯ /usr/bin/distrobox-enter -n withnix -- echo $PATH
/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/username/.local/bin:/home/username/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin

Entering the container interactively:

❯ /usr/bin/distrobox-enter -n withnix
username@fedora:/home/username/Dev/distrobox/with-nix> echo $PATH
/home/username/.distrobox/withnix/.nix-profile/bin:/usr/local/bin:/usr/bin:/bin
username@fedora:/home/username/Dev/distrobox/with-nix> logout

Desktop (please complete the following information):

  • Are you using podman, docker or lilipod?
    • Podman
  • Which version or podman, docker or lilipod?
    • 5.1.1
  • Which version of distrobox?
    • 1.7.2.1
  • Which host distribution?
    • Aurora (Fedora Silverblue)
  • How did you install distrobox?
  • Preinstalled but changed to latest from git instead of the provided one

Additional context
Im using openSUSE with the nix package-manager inside the container so i need ~/.nix-profile/bin on the path to able to find the applications.

If you would like to reproduce it with a nix package there is also a bug with the distrobox-export command. because the path .nix-profile/share/applications is a symlinc to /nix/store/...
I solved that problem by adding a trailing / to line 435 so the find command only checks for files and links inside applications

[ -d "${xdg_data_dir}/applications" ] && canon_dirs="${canon_dirs} ${xdg_data_dir}/applications/"

@ZefQ ZefQ added the bug Something isn't working label Jul 22, 2024
@trianglecirclexyz
Copy link

I am having the same issue. I have installed and exported Android Studio in an Ubuntu container as well as the Flutter/Dart SDKs which are all in the container path. Exporting Android Studio works but the path is still the hosts' which breaks everything.

@SadSock
Copy link

SadSock commented Aug 19, 2024

I am having the same issue.

@89luca89
Copy link
Owner

The problem relies in the command you're using to test this, just doing enter -- echo $PATH will just print the host PATH because $PATH is evaluated by the shell BEFORE entering into distrobox

try

luca-linux@framework13:~$ distrobox enter default_distrobox -- sh -c "echo \$PATH"
/var/lib/flatpak/exports/bin:/home/luca-linux/bin:/home/luca-linux/.local/share/flatpak/exports/bin:/home/luca-linux/.local/bin:/home/luca-linux/.config/emacs/bin/:/var/lib/flatpak/exports/bin:/home/luca-linux/bin:/home/luca-linux/.local/share/flatpak/exports/bin:/home/luca-linux/.local/bin:/home/luca-linux/.config/emacs/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/luca-linux/.local/flutter/flutter/bin:/home/luca-linux/.local/flutter/flutter/bin/cache/dart-sdk/bin/snapshots:/usr/sbin:/usr/local/sbin:/home/luca-linux/.local/flutter/flutter/bin:/home/luca-linux/.local/flutter/flutter/bin/cache/dart-sdk/bin/snapshots:/usr/sbin:/usr/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
luca-linux@framework13:~$ echo $PATH
/var/lib/flatpak/exports/bin:/home/luca-linux/bin:/home/luca-linux/.local/share/flatpak/exports/bin:/home/luca-linux/.local/bin:/home/luca-linux/.config/emacs/bin/:/var/lib/flatpak/exports/bin:/home/luca-linux/bin:/home/luca-linux/.local/share/flatpak/exports/bin:/home/luca-linux/.local/bin:/home/luca-linux/.config/emacs/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/luca-linux/.local/flutter/flutter/bin:/home/luca-linux/.local/flutter/flutter/bin/cache/dart-sdk/bin/snapshots:/usr/sbin:/usr/local/sbin:/home/luca-linux/.local/flutter/flutter/bin:/home/luca-linux/.local/flutter/flutter/bin/cache/dart-sdk/bin/snapshots:/usr/sbin:/usr/local/sbin
luca-linux@framework13:~$ 

This indeed shows a different path

@89luca89 89luca89 added the wait-on-user waiting for a reply label Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wait-on-user waiting for a reply
Projects
None yet
Development

No branches or pull requests

4 participants