Bundling xontrib packages with xonsh

If you use xonsh v0.14.0 in channel 23.11 and have xontrib load vox in your config file, xonsh will complain

The following xontribs are enabled but not installed:
   ['vox']

Using xonsh: Add wrapper by adisbladis · Pull Request #240246 · NixOS/nixpkgs · GitHub, I understand we can do

programs.xonsh.enable = true;
programs.xonsh.package = pkgs.xonsh.override { extraPackages = ps: [
  ps.requests
]; };

and then in xonsh import requests works. But how would I add xontrib-vox from GitHub - xonsh/xontrib-vox: Python virtual environment manager for xonsh.? I tried the following (copying How to install and use a python package from GitHub? - #9 by ldeck) but it didn’t work.

  programs.xonsh.package = pkgs.xonsh.override { extraPackages = ps: [
    ps.buildPythonPackage rec {
      name = "xontrib-vox";
      version = "0.0.1";

      src = pkgs.fetchFromGitHub {
      owner = "xonsh";
        repo = "${name}";
        rev = "${version}";
        sha256 = "06csyhq0h63vq4w17q032dg1cx3j4xrr76maf7a0x4jqcvj4w79q";
      };

      meta = {
        homepage = "https://github.com/xonsh/xontrib-vox";
        description = "Python virtual environment manager for xonsh.";
        license = pkgs.lib.licenses.mit;
        maintainers = [ ];
      };
    }
  ]; };

Try adding parens around the extra package you’re adding, for me that was required for it to be evaluated.

e.g.

  programs.xonsh.package = pkgs.xonsh.override { extraPackages = ps: [
    (ps.buildPythonPackage rec {
      name = "xontrib-vox";
      version = "0.0.1";

      src = pkgs.fetchFromGitHub {
      owner = "xonsh";
        repo = "${name}";
        rev = "${version}";
        sha256 = "06csyhq0h63vq4w17q032dg1cx3j4xrr76maf7a0x4jqcvj4w79q";
      };

      meta = {
        homepage = "https://github.com/xonsh/xontrib-vox";
        description = "Python virtual environment manager for xonsh.";
        license = pkgs.lib.licenses.mit;
        maintainers = [ ];
      };
    })
  ]; };
2 Likes

Thanks, much appreciated. BTW, do you know why parens are needed? ok it’s because otherwise ps.buildPythonPackage and rec {...} are considered list items

I also had to take some stuff from this person’s config in order to avoid the xontrib modules trying to install xonsh as a dependency. So the final code is

programs.xonsh.package = pkgs.xonsh.override { extraPackages = ps: [
  (ps.buildPythonPackage rec {
    name = "xontrib-vox";
    version = "0.0.1";

    src = pkgs.fetchFromGitHub {
    owner = "xonsh";
      repo = "${name}";
      rev = "${version}";
      sha256 = "06csyhq0h63vq4w17q032dg1cx3j4xrr76maf7a0x4jqcvj4w79q";
    };

    meta = {
      homepage = "https://github.com/xonsh/xontrib-vox";
      description = "Python virtual environment manager for xonsh.";
      license = pkgs.lib.licenses.mit;
      maintainers = [ ];
    };

    prePatch = ''
      pkgs.lib.substituteInPlace pyproject.toml --replace '"xonsh>=0.12.5"' ""
    '';
    patchPhase = "sed -i -e 's/^dependencies.*$/dependencies = []/' pyproject.toml";
    doCheck = false;
  })
  (ps.buildPythonPackage rec {
    name = "xontrib-fish-completer";
    version = "0.0.1";

    src = pkgs.fetchFromGitHub {
    owner = "xonsh";
      repo = "${name}";
      rev = "${version}";
      sha256 = "sha256-PhhdZ3iLPDEIG9uDeR5ctJ9zz2+YORHBhbsiLrJckyA=";
    };

    meta = {
      homepage = "https://github.com/xonsh/xontrib-fish-completer";
      description = "Populate rich completions using fish and remove the default bash based completer";
      license = pkgs.lib.licenses.mit;
      maintainers = [ ];
    };

    prePatch = ''
      pkgs.lib.substituteInPlace pyproject.toml --replace '"xonsh>=0.12.5"' ""
    '';
    patchPhase = "sed -i -e 's/^dependencies.*$/dependencies = []/' pyproject.toml";
    doCheck = false;
  })
]; };
1 Like

Hi all, and thank you for this thread I was able to install a few contribs using this method: xontrib-vox, xontrib-fish-completer, xontrib-sh, xontrib-prompt-starship, and xontrib-ssh-agent.

However the shared method doesn’t seem to work for PEP 517/518 type installs or at least installs that require poetry. I was trying to install xontrib-zoxide and got all kind of errors, so I changed it up a bit but still getting errors thrown at me:

      # xontrib-zoxide
      (ps.buildPythonPackage rec {
        name = "xontrib-zoxide";
        version = "v1.0.0";
        format = "pyproject";
        src = pkgs.fetchFromGitHub {
          owner = "dyuri";
          repo = "${name}";
          rev = "${version}";
          sha256 = "9xAR2R7IwGttv84qVb+8TkW6OAK6OGLW3o/tDQnUwII=";
        };
        nativeBuildInputs = [pkgs.python3Packages.pip pkgs.python3Packages.poetry-core];
        meta = {
          homepage = "https://github.com/dyuri/xontrib-zoxide";
          description = "Zoxide support for xonsh";
          license = pkgs.lib.licenses.mit;
          maintainers = [];
        };
      })

Any suggestions would be welcome, because there are two additional xontrib that follow this same method xontrib-clp & xontrib-dotdot

1 Like

re xontrib-zoxide - it won’t work when built as it now tries to create some cache and tries at runtime to copy code into the same directory as the main xontrib file which fails in nix as this is readonly see Caching on a read-only setup · Issue #5 · dyuri/xontrib-zoxide · GitHub

As for the others you need to add some build inputs.

My code now includes in the buildPythonPackage call

 buildInputs = [
        pdm-pep517
        hatchling
        setuptools
        pkgs.python3Packages.poetry-core
      ];

You don’t need all of these for one build but just need one at a time but I found it easier just to keep adding them as I needed. So far no conflicts between them.

1 Like

@mark How did you get around NixOS ‘xontrib_zoxide-1.0.0-py3-none-any.whl’ checking for xonsh as a dependency and causing the build to fail because it isn’t installed yet?

I am trying to add xontrib-zoxide to the program.xonsh like @andrew222651 did with vox. But even with the pre and post patch he added it still trys to bring in ‘xonsh’ as a dependency.

I think the issue is that ‘*.whl’ file.

And maybe I am just approaching it all wrong. It builds fine up to the point of the check dependencies phase.

Any way you could share your snippet for installing that particular xontrib-zoxide.

Thanks

I did not use the xontrib for zoxide, just put that exec line in my xsh.rc as xontrib-zoxide does not work in nix. See the GitHub issue I mentioned above.

However I think you just put xonsh as part of the buildInputs,

1 Like

ah, thanks. I misunderstood your initial reply. As long as zoxide is installed that command will work in the .xonshrc …

Gotcha. Thanks.

In the meantime, I’m going also going to fork xontrib-zoxide and see how difficult it would be to tweak it to look for $XDG_CACHE_HOME per the issue.

Thanks again, that was driving me crazy.

I have no idea what they are trying to do with the patch - it is all python code why not just do as a python package.

I have probably missed something but as I commented I think it needs explaining before changes are made.

I spent a day last week dealing with this :frowning: