Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ buildPackages
2, lib
3, buildPythonPackage
4, protobuf
5, isPyPy
6}:
7
8let
9 versionMajor = lib.versions.major protobuf.version;
10 versionMinor = lib.versions.minor protobuf.version;
11 versionPatch = lib.versions.patch protobuf.version;
12in
13buildPythonPackage {
14 inherit (protobuf) pname src;
15
16 # protobuf 3.21 coresponds with its python library 4.21
17 version =
18 if lib.versionAtLeast protobuf.version "3.21"
19 then "${toString (lib.toInt versionMajor + 1)}.${versionMinor}.${versionPatch}"
20 else protobuf.version;
21
22 disabled = isPyPy;
23
24 sourceRoot = "source/python";
25
26 prePatch = ''
27 if [[ "$(<../version.json)" != *'"python": "'"$version"'"'* ]]; then
28 echo "Python library version mismatch. Derivation version: $version, actual: $(<../version.json)"
29 exit 1
30 fi
31 '';
32
33 buildInputs = [ protobuf ];
34
35 propagatedNativeBuildInputs = [
36 # For protoc of the same version.
37 buildPackages."protobuf${lib.versions.major protobuf.version}_${lib.versions.minor protobuf.version}"
38 ];
39
40 setupPyGlobalFlags = [ "--cpp_implementation" ];
41
42 pythonImportsCheck = [
43 "google.protobuf"
44 "google.protobuf.internal._api_implementation" # Verify that --cpp_implementation worked
45 ];
46
47 passthru = {
48 inherit protobuf;
49 };
50
51 meta = with lib; {
52 description = "Protocol Buffers are Google's data interchange format";
53 homepage = "https://developers.google.com/protocol-buffers/";
54 license = licenses.bsd3;
55 maintainers = with maintainers; [ knedlsepp ];
56 };
57}