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

Xonsh adds unwanted entries to PATH #248978

Closed
amacfie opened this issue Aug 13, 2023 · 5 comments · Fixed by #294328 or #325813
Closed

Xonsh adds unwanted entries to PATH #248978

amacfie opened this issue Aug 13, 2023 · 5 comments · Fixed by #294328 or #325813
Labels
0.kind: bug Something is broken

Comments

@amacfie
Copy link

amacfie commented Aug 13, 2023

Describe the bug

Using xonsh in a nix-shell environment can override the Python interpreter, which is a problem if the environment is supposed to use a specific one.

Steps To Reproduce

sudo docker run -ti --rm nixos/nix bash
nix-channel --update

Then create shell.nix containing

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  packages = [
    (pkgs.python311.withPackages (ps: [
      ps.requests
    ]))
    pkgs.xonsh
  ];
}

Then inside xonsh, a different Python interpreter is used:

nix-shell
xonsh
python -c "import requests"  # -> ModuleNotFoundError: No module named 'requests'

Expected behavior

Running xonsh should not modify the PATH such that a different python executable is used. In the above, when we run python we should get the requests library.

Workarounds

Running $PATH.pop(0) removes the problematic PATH entry but this is pretty hacky.

Notify maintainers

@vrthra

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.35`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.17.0`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
@amacfie amacfie added the 0.kind: bug Something is broken label Aug 13, 2023
@charmoniumQ
Copy link
Contributor

charmoniumQ commented Nov 7, 2023

I think the recommended way to do this is to add an override to xonsh.

      (pkgs.xonsh.override {
        extraPackages = pypkgs: ps: [ ps.requests ];
      })

See #240246

@amacfie
Copy link
Author

amacfie commented Jan 18, 2024

I think the recommended way to do this is to add an override to xonsh.

      (pkgs.xonsh.override {
        extraPackages = pypkgs: ps: [ ps.requests ];
      })

See #240246

That's a help but if I launch a nested xonsh by running xonsh -i in xonsh, the extra packages are gone.

I've removed these unwanted PATH entries by doing, e.g. in configuration.nix:

programs.xonsh.enable = true;
programs.xonsh.package = pkgs.xonsh.override {
  xonsh-unwrapped = pkgs.xonsh-unwrapped.overridePythonAttrs (
    old: {dontWrapPythonPrograms = true;}
  );
};

Everything works fine so far.

@amacfie
Copy link
Author

amacfie commented Apr 24, 2024

@SamLukeYes since your PR was reverted is this issue still fixed?

ETA: looks ok but if anyone still has dontWrapPythonPrograms = true in their config they should probably remove it before upgrading xonsh or they may get #301444.

@SamLukeYes
Copy link
Member

@SamLukeYes since your PR was reverted is this issue still fixed?

ETA: looks ok but if anyone still has dontWrapPythonPrograms = true in their config they should probably remove it before upgrading xonsh or they may get #301444.

To make it clear, dontWrapPythonPrograms = true was reapplied in #302385, while reverting #297628.

@SamLukeYes
Copy link
Member

Oops, it seems we have re-introduced this issue in #314728

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
3 participants