at 25.11-pre 3.4 kB view raw
1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 fetchFromGitHub, 6 rustPlatform, 7 pytest, 8 runCommand, 9 boringssl, 10 libiconv, 11 gcc-unwrapped, 12 python, 13 fetchpatch, 14}: 15 16let 17 boringsslPatched = boringssl.overrideAttrs (oa: { 18 # boringssl source obtained from https://github.com/0x676e67/boring2/tree/1a0f1cd24e728aac100df68027c820f858199224/boring-sys/deps 19 src = fetchFromGitHub { 20 owner = "google"; 21 repo = "boringssl"; 22 rev = "44b3df6f03d85c901767250329c571db405122d5"; 23 hash = "sha256-REELo7X9aFy2OHjubYLO1UQXLTgekD4QFd2vyFthIrg="; 24 }; 25 modRoot = "./src"; 26 patches = [ 27 # A patch required to build boringssl compatible with `boring-sys2`. 28 # See https://github.com/0x676e67/boring2/blob/1a0f1cd24e728aac100df68027c820f858199224/boring-sys/build/main.rs#L486-L489 29 (fetchpatch { 30 name = "boringssl-44b3df6f03d85c901767250329c571db405122d5.patch"; 31 url = "https://raw.githubusercontent.com/0x676e67/boring2/4edbff8cade24d5d83cc372c4502b59c5192b5a1/boring-sys/patches/boringssl-44b3df6f03d85c901767250329c571db405122d5.patch"; 32 hash = "sha256-lM+2lLvfDHnxLl+OgZ6R8Y4Z6JfA9AiDqboT1mbxmao="; 33 }) 34 ]; 35 36 # Remove bazel specific build file to make way for build directory 37 # This is a problem on Darwin because of case-insensitive filesystem 38 preBuild = 39 (lib.optionalString stdenv.hostPlatform.isDarwin '' 40 rm ../BUILD 41 '') 42 + oa.preBuild; 43 44 env.NIX_CFLAGS_COMPILE = 45 oa.env.NIX_CFLAGS_COMPILE 46 + " " 47 + toString ( 48 lib.optionals stdenv.cc.isGNU [ 49 "-Wno-error=ignored-attributes" 50 ] 51 ); 52 53 vendorHash = "sha256-06MkjXl0DKFzIH/H+uT9kXsQdPq7qdZh2dlLW/YhJuk="; 54 }); 55 # boring-sys expects the static libraries in build/ instead of lib/ 56 boringssl-wrapper = runCommand "boringssl-wrapper" { } '' 57 mkdir $out 58 ln -s ${boringsslPatched.out}/lib $out/build 59 ln -s ${boringsslPatched.dev}/include $out/include 60 ''; 61in 62buildPythonPackage rec { 63 pname = "primp"; 64 version = "0.14.0"; 65 pyproject = true; 66 67 src = fetchFromGitHub { 68 owner = "deedy5"; 69 repo = "primp"; 70 tag = "v${version}"; 71 hash = "sha256-LrSygeioJlccOH1oyagw02ankkZK+H6Mzrgy8tB83mo="; 72 }; 73 74 cargoDeps = rustPlatform.fetchCargoVendor { 75 inherit src; 76 name = "${pname}-${version}"; 77 hash = "sha256-iPf25DMGNHrWYByNTylB6bPpLfzs0ADwgkjfhVxiiXA="; 78 }; 79 80 nativeBuildInputs = [ 81 rustPlatform.bindgenHook 82 rustPlatform.cargoSetupHook 83 rustPlatform.maturinBuildHook 84 ]; 85 86 # TODO: Can we improve this? 87 postInstall = lib.optionalString stdenv.hostPlatform.isLinux '' 88 patchelf --add-rpath ${lib.getLib gcc-unwrapped.lib} --add-needed libstdc++.so.6 $out/${python.sitePackages}/primp/primp.abi3.so 89 ''; 90 91 buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ 92 libiconv 93 ]; 94 95 env.BORING_BSSL_PATH = boringssl-wrapper; 96 env.BORING_BSSL_ASSUME_PATCHED = true; 97 98 optional-dependencies = { 99 dev = [ pytest ]; 100 }; 101 102 # Test use network 103 doCheck = false; 104 105 pythonImportsCheck = [ "primp" ]; 106 107 meta = { 108 changelog = "https://github.com/deedy5/primp/releases/tag/${version}"; 109 description = "Python Requests IMPersonate, the fastest Python HTTP client that can impersonate web browsers"; 110 homepage = "https://github.com/deedy5/primp"; 111 license = lib.licenses.mit; 112 maintainers = with lib.maintainers; [ drupol ]; 113 }; 114}