Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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/refs/tags/v4.15.11/boring-sys/build/main.rs#L486-L489 29 (fetchpatch { 30 name = "boringssl-44b3df6f03d85c901767250329c571db405122d5.patch"; 31 url = "https://raw.githubusercontent.com/0x676e67/boring2/refs/tags/v4.15.11/boring-sys/patches/boringssl-44b3df6f03d85c901767250329c571db405122d5.patch"; 32 hash = "sha256-JRRATcCXo0HBQTzgCAuLpxC3NEGrTw1cEmC0VHOgO2M="; 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.isClang [ 49 "-Wno-error=reorder-ctor" 50 ] 51 ++ lib.optionals stdenv.cc.isGNU [ 52 "-Wno-error=reorder" 53 "-Wno-error=ignored-attributes" 54 ] 55 ); 56 57 vendorHash = "sha256-06MkjXl0DKFzIH/H+uT9kXsQdPq7qdZh2dlLW/YhJuk="; 58 }); 59 # boring-sys expects the static libraries in build/ instead of lib/ 60 boringssl-wrapper = runCommand "boringssl-wrapper" { } '' 61 mkdir $out 62 ln -s ${boringsslPatched.out}/lib $out/build 63 ln -s ${boringsslPatched.dev}/include $out/include 64 ''; 65in 66buildPythonPackage rec { 67 pname = "primp"; 68 version = "0.15.0"; 69 pyproject = true; 70 71 src = fetchFromGitHub { 72 owner = "deedy5"; 73 repo = "primp"; 74 tag = "v${version}"; 75 hash = "sha256-13o0Ni0dvZaoKgYy2cFQhebwKAJGm5Z2s+gVAddxYxU="; 76 }; 77 78 cargoDeps = rustPlatform.fetchCargoVendor { 79 inherit pname version src; 80 hash = "sha256-UBpf9f3wJgbizHERsm83cuKHiMixj/8JX/IGvteySIo="; 81 }; 82 83 nativeBuildInputs = [ 84 rustPlatform.bindgenHook 85 rustPlatform.cargoSetupHook 86 rustPlatform.maturinBuildHook 87 ]; 88 89 # TODO: Can we improve this? 90 postInstall = lib.optionalString stdenv.hostPlatform.isLinux '' 91 patchelf --add-rpath ${lib.getLib gcc-unwrapped.lib} --add-needed libstdc++.so.6 $out/${python.sitePackages}/primp/primp.abi3.so 92 ''; 93 94 buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ 95 libiconv 96 ]; 97 98 env.BORING_BSSL_PATH = boringssl-wrapper; 99 env.BORING_BSSL_ASSUME_PATCHED = true; 100 101 optional-dependencies = { 102 dev = [ pytest ]; 103 }; 104 105 # Test use network 106 doCheck = false; 107 108 pythonImportsCheck = [ "primp" ]; 109 110 meta = { 111 changelog = "https://github.com/deedy5/primp/releases/tag/${version}"; 112 description = "Python Requests IMPersonate, the fastest Python HTTP client that can impersonate web browsers"; 113 homepage = "https://github.com/deedy5/primp"; 114 license = lib.licenses.mit; 115 maintainers = with lib.maintainers; [ drupol ]; 116 }; 117}