Building Derivation results in requirement setuptools>=40.8.0

Hi there, I am new to nix and try to build a derivation for a project that accesses two github repositories: miallib and jiplib. The final goal is to build a derivation for pyjeo (a python package that links to the two dependencies miallib and jiplib). For now, I struggle with the building of the second dependency jiplib.

Both miallib and jiplib are coded in C++ and built with cmake. The derivations are built fine as far as the C++ libraries are concerned (producing the dynamic libraries). However, there is also a python wrapper for the jiplib library that should result in a Python wheel. There is a command in the CMakeLists.txt of jiplib that takes care of this using the pip command:

COMMAND ${Python_EXECUTABLE} -m pip wheel ${CMAKE_CURRENT_BINARY_DIR}

This is where the build process in nix (I use version 24.05 in a Linux environment) fails.

Expected behavior:
A wheel is created for the jiplib library, resulting in the file jiplib-1.1.4-py3-none-any.whl, as in the case when I build the library on a Linux machine just using cmake (not using nix).

Observed error:

ERROR: Could not find a version that satisfies the requirement setuptools>=40.8.0 (from versions: none)
      ERROR: No matching distribution found for setuptools>=40.8.0

There are also some warnings, but I am not sure if these are relevant here:

WARNING: The directory '/homeless-shelter/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
       >       WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f32c2c0ea10>: Failed to establish a new connection: [Errno 111] Connection refused')': /simple/setuptools/

To reproduce the error, I try to build using the command:

nix-build default.nix

where default.nix is:

# default.nix
let
  nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-24.05";
  pkgs = import nixpkgs { config = {}; overlays = []; };
in
{
  jiplib = pkgs.callPackage ./jiplib.nix { };
}

And the two nix files for both jiplib and miallib:

#jiplib.nix
{
  pkgs,
  stdenv,
  fetchFromGitHub,
}:

stdenv.mkDerivation rec {
  pname = "jiplib";
  version = "1.1.9";
  src = pkgs.fetchgit {
    url = "https://github.com/ec-jrc/jeolib-jiplib";
    rev = "d5a9ce09a5c81655f5dfc64bec4576c276e6502a";
    sha256 = "sha256-VZJlsyqHC2NneVXoVU++9uQ6xYoK7Stchei7yGpNslM=";
  };

  buildInputs = [
    (pkgs.callPackage ./miallib.nix {})
    pkgs.gsl
    pkgs.libfann.dev
    pkgs.libtiff.dev
    pkgs.libgeotiff.dev
    pkgs.fftw.dev
    pkgs.fftw
    pkgs.proj.dev
    pkgs.jsoncpp.dev
    pkgs.gdal
    pkgs.openssl.dev
    pkgs.swig
    pkgs.uthash
    pkgs.openblas.dev
    pkgs.cmake
    pkgs.pkg-config
    pkgs.zlib
    pkgs.shapelib
    pkgs.boost.dev
    pkgs.python3
    pkgs.python311Packages.setuptools
    pkgs.python311Packages.numpy
    pkgs.python311Full
    pkgs.python311Packages.pip
    pkgs.python311Packages.virtualenv
    pkgs.less
  ];

and miallib.nix:

#miallib.nix
{
  pkgs,
  stdenv,
  fetchFromGitHub,
}:

stdenv.mkDerivation rec {
  pname = "miallib";
  version = "1.1.6";
  src = pkgs.fetchgit {
    url = "https://github.com/ec-jrc/jeolib-miallib";
    rev = "fb9e772ecbceaf7e258fa38e2c2ad6c1fb62e719";
    sha256 = "sha256-lMZBF4+HDVSKuTRW/sJmmNRgJmyUIBae4qyIUBqK1k0=";
  };

  buildInputs = [
    pkgs.gsl
    pkgs.libtiff.dev
    pkgs.libgeotiff.dev
    pkgs.fftw.dev
    pkgs.fftw
    pkgs.proj.dev
    pkgs.gdal
    pkgs.uthash
    pkgs.openblas.dev
    pkgs.cmake
    pkgs.pkg-config
    pkgs.zlib
    pkgs.shapelib
  ];

I did try to first build miallib, enter the environment with a nix-shell and build the jiplib wheel in there. I succeed building the wheel there, but I am unable to install the wheel using pip. There, the installation fails due to insufficient permission rights (most likely because I am not understanding the build process within a nix-shell environment yet).

Thanks for your help.

Don’t use pip, use buildPythonPackage or the pypaBuildHook or such. Nixpkgs manual describes each in more detail.

1 Like