Packaging a python wheel-only library

I’m trying to package jaxlib at the moment, and fetchPypi. Here’s my simple derivation:

{ lib, fetchPypi, buildPythonPackage }:

buildPythonPackage rec {
  version = "0.1.70";
  pname = "jaxlib";
  src = fetchPypi {
    inherit pname version;
    sha256 = "sha256-4VU0aAoFts7ZLa3eMHvTsiB+/Rqq7DBOlhl7AK11YNM=";
  };
}

But fetchPypi isn’t happy when I attempt to build it:

❯ nix-build -A python3Packages.jaxlib
these 2 derivations will be built:
  /nix/store/0wjpnyj64z9hgdmbi1sdig7vacs2616y-jaxlib-0.1.70.tar.gz.drv
  /nix/store/imb09583y9vl4yk1l0rkxqdxpifgmd0k-python3.9-jaxlib-0.1.70.drv
building '/nix/store/0wjpnyj64z9hgdmbi1sdig7vacs2616y-jaxlib-0.1.70.tar.gz.drv'...

trying https://files.pythonhosted.org/packages/source/j/jaxlib/jaxlib-0.1.70.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (22) The requested URL returned error: 404

trying https://pypi.io/packages/source/j/jaxlib/jaxlib-0.1.70.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   122  100   122    0     0   1487      0 --:--:-- --:--:-- --:--:--  1506
100   273  100   273    0     0   1358      0 --:--:-- --:--:-- --:--:--  1358
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (22) The requested URL returned error: 404
error: cannot download jaxlib-0.1.70.tar.gz from any mirror
...
error: 1 dependencies of derivation '/nix/store/imb09583y9vl4yk1l0rkxqdxpifgmd0k-python3.9-jaxlib-0.1.70.drv' failed to build

I believe this is because jaxlib does not have a source distribution on pypi, but only offers wheels (jaxlib · PyPI). How does one nix-ify a python package like this?

Pass format=“wheel”; to fetchPypi

I tried

src = fetchPypi {
  inherit pname version;
  sha256 = "sha256-4VU0aAoFts7ZLa3eMHvTsiB+/Rqq7DBOlhl7AK11YNM=";
  format = "wheel";
  python = "cp39";
  platform = "macosx_10_9_x86_64";
};

which gets the correct file name: jaxlib-0.1.70-cp39-none-macosx_10_9_x86_64.whl, but the url that fetchPypi attempts is still a 404: https://files.pythonhosted.org/packages/py2.py3/j/jaxlib/jaxlib-0.1.70-cp39-none-macosx_10_9_x86_64.whl.

According to pypi’s website the correct link is https://files.pythonhosted.org/packages/52/93/a1f104b7e312cf44284284259cc66928aceb09483b86b6d5a3d02c16ab23/jaxlib-0.1.70-cp39-none-macosx_10_9_x86_64.whl.

Update:

src = fetchPypi {
  inherit pname version format;
  sha256 = "sha256-pRPXgoYO1n/uFlfGbkUlebYCSjoFvVumhNRKgAld8lA=";
  dist = "cp39";
  python = "cp39";
  platform = "macosx_10_9_x86_64";
};

did the trick!

2 Likes

Can I ask you how did you solve it?
I have a similar problem packaging pyvista, whose wheel url is
https://files.pythonhosted.org/packages/35/61/be354dda968290574da958791b305c2c5f40ed401a561c7c73393e5c4fc0/pyvista-0.36.0-py3-none-any.whl

while if I use

    src = python3Packages.fetchPypi {
      inherit pname;
      inherit version;
      inherit format;
      dist="cp39";
      python="py3";
      platform="any";
      sha256 = "5eddabc8ad22627c667ae9da92c38ade5ef29304f85c5a9445d1f14b5dd4e35c";
    };

it tries to fetch wheel from url https://files.pythonhosted.org/packages/cp39/p/pyvista/pyvista-0.36.1-py3-none-any.whl

Hosted by Flying Circus.