Skip to content

Xonsh adds unwanted entries to PATH #248978

Description

@andrew222651

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`

Activity

  1. added
    0.kind: bug
    on Aug 13, 2023
  2. charmoniumQ commented on Nov 7, 2023

    @charmoniumQ
    Contributor

    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

  3. andrew222651 commented on Jan 18, 2024

    @andrew222651
    Author

    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.

  4. andrew222651 commented on Apr 24, 2024

    @andrew222651
    Author

    @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.

  5. SamLukeYes commented on Apr 24, 2024

    @SamLukeYes
    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.

  6. SamLukeYes commented on Jul 9, 2024

    @SamLukeYes
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions