NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.15k stars 13.42k forks source link

Can't install xonsh modules #75786

Closed JonathanReeve closed 9 months ago

JonathanReeve commented 4 years ago

Issue description

To install extensions in the xonsh shell, according to the documentation, you run xontrib z, where z is the name of the extension you want to install. Running that gives:

The following xontribs are enabled but not installed: 
   z
To install them run 
    xpip install xontrib-z

However, running xpip fails on NixOS with:

/nix/store/drr8qcgiccfc5by09r5zc30flgwh1mbx-python3-3.7.5/bin/python3.7: No module named pip

It'd be great if this command worked as expected. But even better, it'd be great to have the Xontribs (xonsh extensions) installable via nix, too, somehow. You can list them with pip search xontrib, so they're just python modules. Someone with more nix-fu than I could probably make an option programs.xonsh.plugins that could install those python modules, such that programs.xonsh.plugins = [ z simplejump shedule ]; would install the python modules xontrib-schedule, xontrib-simplejump, and xontrib-z.

Steps to reproduce

  1. Install xonsh
  2. Run xpip, either with or without arguments.
  3. Notice that it fails, and you can't install a xonsh extension.

Technical details

Please run nix run nixpkgs.nix-info -c nix-info -m and paste the result.

KoviRobi commented 4 years ago

For the xontrib in nix, looks like the modules just need to be on the $PYTHONPATH, so perhaps we just need to wrap xonsh like we wrap python default.nix wrapper.nix with-packages.nix. Perhaps we could even just use the python wrapper.nix.

I might have a play around with xonsh, and then if you haven't already, try to package stuff for it. Until then, you could try installing xontrib-z into some path, then putting that into your $PYTHONPATH?

stale[bot] commented 4 years ago

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

JonathanReeve commented 4 years ago

This is still relevant, as far I I know.

shadowrylander commented 3 years ago

I actually use this mach-nix overlay: https://github.com/shadowrylander/shadowrylander/blob/system/etc/nixos/shared/global/_overlays/xonsh.nix

Unfortunately at the moment, there seems to be an infinite recursion error with the newPkgs statement; it works when using a flake, however!

tex commented 3 years ago

Does anyone successfully solved this? @shadowrylander link is no longer available...

shadowrylander commented 3 years ago

@tex I believe I'm still using the overlay in this issue! Though there still seems to be some problems.

danilevy1212 commented 3 years ago

I can confirm than adding package to your $PYTHONPATH does work. Also from inside the xonsh shell, adding my local pip site-packages directory to sys.path does work, which is not ideal. It would be nice to be able to have some sort of wrapper to add xcontrib modules more easily without clashing with NixOS philosophy.

Lassulus commented 3 years ago

so I'm currently using xonsh like this in my configuration:

{ config, lib, pkgs, ... }: let

  mach-nix = import (builtins.fetchGit {
    url = "https://github.com/DavHau/mach-nix/";
    ref = "refs/tags/3.3.0";
  }) {
    pkgs = pkgs;
  };

  pyenv = mach-nix.mkPython {
    requirements = ''
      xontrib-sh
      xxh-xxh
    '';
  };

  xonshrc = pkgs.writeText "xonshrc" ''
    $PROMPT = '{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {cwd}{NO_COLOR}> '
    $XONSH_COLOR_STYLE = 'rrt'
    xontrib load sh
  '';

  xonsh_with_plugins = pkgs.xonsh.overrideAttrs (old: {
    propagatedBuildInputs = old.propagatedBuildInputs ++ pyenv.python.pkgs.selectPkgs pyenv.python.pkgs;
  });

in {
  environment.variables.XONSHRC = builtins.toString xonshrc;
  environment.systemPackages = [
    xonsh_with_plugins
  ];
}

this works for me and I can install any plugins/python lib that way

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

airways commented 2 years ago

This is still happening to me.

@Lassulus where does this config go for your workaround? I tried to put it into ~/.xonshrc and that resulted in syntax errors so that might not be the right place?

Edit: My issue seems to have been completely different, I somehow didn't have pip installed? hrm

sudo apt install python3-pip was all I needed to do.

Lassulus commented 2 years ago

uhm, I posted a nixos config. I would guess you are not on nixos since you are using apt-get?

airways commented 2 years ago

Oh yes indeed, very sorry about that. I didn't realize what repo I was in, and this issue was highly ranked when I searched Google for this error.

charmoniumQ commented 9 months ago

I was trying to do this without mach-nix, but I couldn't figure it out?

{ pkgs, config, ... }:
let
  python = pkgs.python311;
  pythonPkgs = with python.pkgs; [
    (python.pkgs.toPythonModule pkgs.xonsh)
    (python.pkgs.buildPythonPackage rec {
      pname = "xontrib-prompt-starship";
      version = "0.3.4";
      src = pkgs.fetchPypi {
        inherit pname version;
        sha256 = "2106d4e13618891f12657bd44f32ffba48cdeca18239031369de1a6fa4ff152b";
      };
      doCheck = false;
    })
  ];
in {
  home = {
    packages = [ (python.withPackages (ps: pythonPkgs)) ];
  };
}

But no dice,

@ home-manager switch
...
@ xontrib load starship_prompt
The following xontribs are enabled but not installed: 
   ['starship_prompt']
Please make sure that they are installed correctly by checking https://xonsh.github.io/awesome-xontribs/
SamLukeYes commented 9 months ago

There's a way to install xonsh modules introduced by https://github.com/NixOS/nixpkgs/pull/240246. I think this issue can be closed.