Build c++/python code together

Hi,

I’m trying to install httpstan from: Installation — httpstan 4.10.1 documentation

It involves both python and c++ code.

I’m trying to use a default.nix (that I can invoke with nix-shell) that I’ve scavenged from a previous working default.nix that built something else:

with import <nixpkgs> {};

(let

httpstan = pkgs.python37Packages.buildPythonPackage rec{
    name = "httpstan-${version}";
    version = "4.4.2";
    src = fetchFromGitHub {
        owner = "stan-dev";
        repo = "httpstan";
        rev = version;
        sha256 = "1gjy5glz3qgrv33yyhpqhx3vgy8ff4p5m78p784kr8zlhxlbpy48";
    };

    doCheck = false;
    buildInputs = [
        curl
        which
    ];
    propagatedBuildInputs =  [
        curl
        python37Packages.poetry
    ];

    format = "other";

    buildPhase = ''
        echo "BEGIN-BUILD-THING"
        which curl
        #make
        #curl
    '';

    installPhase = ''
        #echo "BEGIN-INSTALL-THING"
        #echo `pwd`
        #export
        #mkdir $out
        #echo "END-INSTALL-THING"        
    '';

    postFixup = ''
    '';
};

in stdenv.mkDerivation {
    name = "impurePythonEnv";
    buildInputs = [
        pkgs.curl 
        pkgs.which
        httpstan

        (python37.buildEnv.override {
            ignoreCollisions = true;
            extraLibs = [

            ];
    })
  ];
})

The error I’m getting right now is:

/nix/store/sm7kk5n84vaisqvhk1yfsjqls50j8s0m-stdenv-linux/setup: line 1300: which: command not found

I realise there may be other ways of doing this - but I’m also keen to use this general layout because it will save me having to port a load of other nix code to some new format. Getting which and curl available will certainly be good progress from my perspective. As a last resort, I’d still be interested in alternative approaches, of course.

Thanks for any pointers,

Nawal.

You’re getting this because buildPythonPackage has strictDeps = true; which means that it tries to separate what should run on the host platform vs what should be done on the target platform. In this case, buildInputs represents libraries and other utilities which should be used on the target platform (e.g. linking). However, you should use nativeBuildInputs to include tools which need to be ran on the host platform.

To solve your immediate issue, put which into nativeBuildInputs.

Other tips: I wouldn’t overwrite things such as buildPhase or installPhase. If there are actions which need to be done before doing a phase, you should use the prehooks, preBuild and preInstall.

Looking at GitHub - stan-dev/httpstan: HTTP interface to Stan, a package for Bayesian inference., you want format = "pyproject";, and it will build the python package using their pyproject.toml.

Thank you! Was able to get which and curl to work using buildInputs.