DavHau / mach-nix

Create highly reproducible python environments
MIT License
863 stars 106 forks source link

"collision between" with cffi #298

Open adamlwgriffiths opened 3 years ago

adamlwgriffiths commented 3 years ago

I get a collision with cffi against itself when trying to install Python 3.8 and raylib-python-cffi.

collision between `/nix/store/m00mi8warrl8kh7qbssrlcnhmnhd5aqs-python3.8-cffi-1.14.5/lib/python3.8/site-packages/cffi-1.14.5.dist-info/WHEEL' and `/nix/store/sp2pz3j1j0csa27m75mdrrhb52pm1c6w-python3.8-cffi-1.14.5/lib/python3.8/site-packages/cffi-1.14.5.dist-info/WHEEL'

As you can see, the same version has been pulled out twice, but with different hashes.

Here's my cut down shell.nix which demonstrates the issue

{ pkgs ? import <nixpkgs> {} }:

let
  mach-nix = import (builtins.fetchGit {
    url = "https://github.com/DavHau/mach-nix/";
    ref = "3.3.0";
  }) {};
  raylib-python-cffi = mach-nix.buildPythonPackage {
    src = builtins.fetchGit {
      url = "https://github.com/adamlwgriffiths/raylib-python-cffi";
      ref = "dynamic-only";
      rev = "d65c7407fc8b151c0c777771df6a6187b52a74a6";
    };
  };
  custom-python = mach-nix.mkPython {
    python = "python38";
    packagesExtra = [
      raylib-python-cffi
    ];
    providers = {
      _default = "nixpkgs,wheel,sdist";
    };
  };
in pkgs.mkShell {
  buildInputs = with pkgs; [
    custom-python
  ];

  shellHook = ''
    export USE_EXTERNAL_RAYLIB=
  '';
}
adamlwgriffiths commented 3 years ago

Ok, I'm having more trouble with cffi in a different shell where im trying to pull in poetry. Not sure what's going on.

Executing pipInstallPhase
/build/SecretStorage-3.3.1/dist /build/SecretStorage-3.3.1
Processing ./SecretStorage-3.3.1-py3-none-any.whl
Requirement already satisfied: cryptography>=2.0 in /nix/store/b09a13zp017h964rbq3pfsq6x83ka2xm-python3.8-cryptography-3.4.7/lib/python3.8/site-packages (from SecretStorage==3.3.1) (3.4.7)
Requirement already satisfied: jeepney>=0.6 in /nix/store/h4j7xgj69f61fz6y6yyrh771lljww59k-python3.8-jeepney-0.6.0/lib/python3.8/site-packages (from SecretStorage==3.3.1) (0.6.0)
INFO: pip is looking at multiple versions of <Python from Requires-Python> to determine which version is compatible with other requirements. This could take a while.
INFO: pip is looking at multiple versions of secretstorage to determine which version is compatible with other requirements. This could take a while.
ERROR: Could not find a version that satisfies the requirement cffi>=1.12 (from cryptography)
ERROR: No matching distribution found for cffi>=1.12
builder for '/nix/store/g54fhzi2iyij6imjsywx35fw86rvxrb4-python3.8-secretstorage-3.3.1.drv' failed with exit code 1
adamlwgriffiths commented 3 years ago

Ok so this has been causing me a lot of trouble with anything that pulls in cffi - which turns out to be quite a few libs (twine, poetry, etc).

The solution seems to be to explicitly specify the same dependency (cffi>=1.12) in the mach-nix.mkPython.requirements field. Eg:

  custom-python = mach-nix.mkPython {
    requirements = ''
      setuptools
      cffi>=1.12
      twine
    '';
...

Doing that seems to get mach-nix to understand what to do. But if left to its own devices the provided libraries dependencies seem to confuse mach-nix.

DavHau commented 3 years ago

The problem seems to be caused by different provider settings passed to buildPythonPackage and mkPython.