@@ -1,8 +1,64 @@
1−{ lib, fetchzip }:
1+{ lib
2+, stdenv
3+, fetchFromGitHub
4+, python
5+, cmake
6+}:
27
3−fetchzip {
4− url = "https://github.com/lief-project/LIEF/releases/download/0.9.0/LIEF-0.9.0-Linux.tar.gz";
5− sha256 = "1c47hwd00bp4mqd4p5b6xjfl89c3wwk9ccyc3a2gk658250g2la6";
8+let
9+ pyEnv = python.withPackages (ps: [ ps.setuptools ]);
10+in
11+stdenv.mkDerivation rec {
12+ pname = "lief";
13+ version = "0.11.4";
14+
15+ src = fetchFromGitHub {
16+ owner = "lief-project";
17+ repo = "LIEF";
18+ rev = version;
19+ sha256 = "DgsTrJ2+zdXJK6CdDOan7roakaaxQiwrVeiQnzJnk0A=";
20+ };
21+
22+ outputs = [ "out" "py" ];
23+
24+ nativeBuildInputs = [
25+ cmake
26+ ];
27+
28+ # Not a propagatedBuildInput because only the $py output needs it; $out is
29+ # just the library itself (e.g. C/C++ headers).
30+ buildInputs = [
31+ python
32+ ];
33+
34+ dontUseCmakeConfigure = true;
35+
36+ buildPhase = ''
37+ runHook preBuild
38+
39+ substituteInPlace setup.py \
40+ --replace 'cmake_args = []' "cmake_args = [ \"-DCMAKE_INSTALL_PREFIX=$prefix\" ]"
41+ ${pyEnv.interpreter} setup.py --sdk build --parallel=$NIX_BUILD_CORES
42+
43+ runHook postBuild
44+ '';
45+
46+ # I was unable to find a way to build the library itself and have it install
47+ # to $out, while also installing the Python bindings to $py without building
48+ # the project twice (using cmake), so this is the best we've got. It uses
49+ # something called CPack to create the tarball, but it's not obvious to me
50+ # *how* that happens, or how to intercept it to just get the structured
51+ # library output.
52+ installPhase = ''
53+ runHook preInstall
54+
55+ mkdir -p $out $py/nix-support
56+ echo "${python}" >> $py/nix-support/propagated-build-inputs
57+ tar xf build/*.tar.gz --directory $out --strip-components 1
58+ ${pyEnv.interpreter} setup.py install --skip-build --root=/ --prefix=$py
59+
60+ runHook postInstall
61+ '';
662
763 meta = with lib; {
864 description = "Library to Instrument Executable Formats";