Building python bindings for custom derivation

Hi,

I’m trying to build and install a C++ library that also has python bindings. From what information I could gather, the approach in this case is to call toPythonModule. I’ve tried this in various forms and it does not work. Here’s what I have:

feat.nix:

let
  pkgs = import <nixos-unstable> {};
  stdenv = pkgs.gcc10Stdenv;

  eigency = pkgs.python38Packages.buildPythonPackage rec {
    pname = "eigency";
    version = "1.77" ;

    src = pkgs.python38Packages.fetchPypi {
      inherit pname version;
      sha256 = "13cf96e00020fd900aa5f8905036488afd27c89212bfc07b60ac5412073ea7d7";
    };

    doCheck = false;

    # build time deps
    nativeBuildInputs = with pkgs.python38Packages; [
      cython
      setuptools
      setuptools_scm
    ];

    ## runtime deps
    propagatedBuildInputs = with pkgs; [
      python38Packages.numpy
      eigen
    ];

    meta = with pkgs.stdlib; {
      homepage = "https://pypi.org/project/eigency";
    };
  };
in
  pkgs.python38Packages.toPythonModule (stdenv.mkDerivation rec {
    pname = "feat";
    version = "0.4";

    nativeBuildInputs = with pkgs; [ 
      cmake 
      autoPatchelfHook 
      (python38.withPackages( ps: with ps; [ cython setuptools setuptools_scm ])) 
    ];

    buildInputs = with pkgs; [ 
      eigen shogun eigency 
    ];

    enablePython = true;

    CFLAGS = "-march=znver2 -O3";

    src = pkgs.fetchFromGitHub {
      owner = "lacava"; 
      repo = "feat";
      rev = "b778a44ae64deeb4a5d7c652ba593154f117ef6e";
      sha256 = "1y16dwdy1cx7xxg5j90rzj1jyf4ccri8xrw5lsnx0krdap5a7fz7";
    };

    installPhase = ''
      mkdir -p $out/bin
      install -m755 -D feat $out/bin/feat
      install -m755 -D libfeat_lib.so $out/bin/libfeat_lib.so
    '';

     # This is how the Python bindings should be built
     # cd ../python
     # python setup.py install --home=$out

    meta = with stdenv.lib; {
      description = "A feature engineering automation tool for learning data representations";
      homepage = "https://github.com/lacava/feat";
      license = stdenv.lib.licenses.gpl3;
      platforms = stdenv.lib.platforms.linux;
    };
  })

default.nix:

let
  pkgs = import <nixos-unstable> {};
  feat = import ./feat.nix; 
in 
  pkgs.gcc10Stdenv.mkDerivation rec {
    name = "feat-env";
    buildInputs = [ feat  ];
  }

This works without errors but the python bindings are not built. If I try to add

cd ../python
python setup.py install --home=$out

in the installPhase in feat.nix then it does try to build the bindings but fails because it cannot find the Eigen include headers.

Can anyone shed some light on this issue? What would be the best practice to get this working?

Thanks.

Looking at

you might need to set those environment variables.

Thanks a lot for the help. You were right, I needed to set those environment variables.
It mostly works now, it is building the egg but then it fails at the creating dist step:
ValueError: ZIP does not support timestamps before 1980

Now I am trying to unset SOURCE_DATE_EPOCH but I am not doing it correctly:

    preInstall = ''
      echo "Preinstall phase"
      echo $SOURCE_DATE_EPOCH
      export SOURCE_DATE_EPOCH=$(date +%s)
      echo $SOURCE_DATE_EPOCH
      export EIGEN3_INCLUDE_DIR=${pkgs.eigen}/include/eigen3
      export SHOGUN_DIR=${pkgs.shogun}/include/shogun
      export SHOGUN_LIB=${pkgs.shogun}/lib
      '';

    installPhase = ''
      runHook preInstall

      cd ../python
      SOURCE_DATE_EPOCH=$(date +%s) python setup.py install --home=$out    

      mkdir -p $out/bin
      install -m755 -D feat $out/bin/feat
      install -m755 -D libfeat_lib.so $out/bin/libfeat_lib.so
    '';

No matter if I unset the variable or set it to a value >1980, it seems that the python setup is not reading the correct value. Any ideas what to do next? Thanks.