Python install dependency from git+url?

I need to make a shell for a project with the following dependencies

# requirements.txt
PyQt6
...
git+https://gitlab.ost.ch/somerepo.git

my shell looks like this:

# shell.nix
let
  pkgs = import <nixpkgs> {};
in pkgs.mkShell {
  packages = [
    (pkgs.python3.withPackages (python-pkgs: [
      python-pkgs.pyqt6
    ]))
  ];
}

But how to get the git dependency?

I tried to make a venv with --system-site-packages and install it via pip, but PyQt6 is not available in the venv and also can not be installed in a venv on nixos… Any solutions?

There is probably a way to convince the venv to use our wrapped interpreter with the special variable to load the system packages. Other than that you could package the git dependency locally in the shell file.

Yes, that’s what pip’s pip -m venv --system-site-packages .venv normally does, isn’t it? But it doesn’t seem to work on nix. The venv is still empty:

(.venv)$ ls .venv/lib/python3.11/site-packages/
_distutils_hack  distutils-precedence.pth  pip  pip-24.0.dist-info  pkg_resources  setuptools  setuptools-65.5.0.dist-info

or

(.venv)$ pip list
Package    Version
---------- -------
pip        24.0
setuptools 65.5.0

Outsite venv:

$ pip list
Package                   Version
------------------------- --------------
anyio                     4.3.0
argon2-cffi               23.1.0
argon2-cffi-bindings      21.2.0
arrow                     1.3.0
asttokens                 2.4.1
async_generator           1.10
...

Other than that you could package the git dependency locally in the shell file.

Hmpf, any guide to how to do that without having a very deep knowledge of packaging on nix?

Solution: So i came up with this (ugly) hack that seems to work:

  1. Make your shell.nix (with dependencies like python-pkgs.pyqt6 from the nix store as I did above) and open the shell
  2. Find out where the packages are located with python -m site. In my case it was something like /nix/store/vy...44-python3-3.11.9-env/lib/python3.11/site-packages
  3. Create a venv with python -m venv .venv and activate it
  4. Copy the system packages to your venv with cp -P -r /nix/store/vy...44-python3-3.11.9-env/lib/python3.11/site-packages/* .venv/lib/python3.11/site-packages/ (the -P is for copying the symlinks rather than dereferencing it)
  5. Install your git+url package as usual with pip

(btw, I also tried pip2nix but it didn’t work as well with a git+url and the fact that such tools as pypi2nix, python2nix, nix-pip, mach-nix keep popping up and get abandoned/discontinued makes developing Python on nixos still a pain in the a**)

You don’t need deep knowledge. Just look at any other simple python package and adapt from there.