1{ 2 stdenv, 3 config, 4 lib, 5 buildPythonPackage, 6 fetchPypi, 7 python, 8 pythonOlder, 9 pythonAtLeast, 10 openssl_1_1, 11 zlib, 12 setuptools, 13 cudaSupport ? config.cudaSupport or false, 14 cudaPackages_11 ? { }, 15 addDriverRunpath, 16 # runtime dependencies 17 httpx, 18 numpy, 19 protobuf, 20 pillow, 21 decorator, 22 astor, 23 paddle-bfloat, 24 opt-einsum, 25}: 26 27let 28 pname = "paddlepaddle" + lib.optionalString cudaSupport "-gpu"; 29 version = "2.5.0"; 30 format = "wheel"; 31 pyShortVersion = "cp${builtins.replaceStrings [ "." ] [ "" ] python.pythonVersion}"; 32 cpuOrGpu = if cudaSupport then "gpu" else "cpu"; 33 allHashAndPlatform = import ./binary-hashes.nix; 34 hash = 35 allHashAndPlatform."${stdenv.system}"."${cpuOrGpu}"."${pyShortVersion}" 36 or (throw "${pname} has no binary-hashes.nix entry for '${stdenv.system}.${cpuOrGpu}.${pyShortVersion}' attribute"); 37 platform = allHashAndPlatform."${stdenv.system}".platform; 38 src = fetchPypi ({ 39 inherit 40 version 41 format 42 hash 43 platform 44 ; 45 pname = builtins.replaceStrings [ "-" ] [ "_" ] pname; 46 dist = pyShortVersion; 47 python = pyShortVersion; 48 abi = pyShortVersion; 49 }); 50in 51buildPythonPackage { 52 inherit 53 pname 54 version 55 format 56 src 57 ; 58 59 disabled = pythonOlder "3.9" || pythonAtLeast "3.11"; 60 61 libraryPath = lib.makeLibraryPath ( 62 # TODO: remove openssl_1_1 and zlib, maybe by building paddlepaddle from 63 # source as suggested in the following comment: 64 # https://github.com/NixOS/nixpkgs/pull/243583#issuecomment-1641450848 65 [ 66 openssl_1_1 67 zlib 68 ] 69 ++ lib.optionals cudaSupport ( 70 with cudaPackages_11; 71 [ 72 cudatoolkit.lib 73 cudatoolkit.out 74 cudnn 75 ] 76 ) 77 ); 78 79 postFixup = lib.optionalString stdenv.hostPlatform.isLinux '' 80 function fixRunPath { 81 p=$(patchelf --print-rpath $1) 82 patchelf --set-rpath "$p:$libraryPath" $1 83 ${lib.optionalString cudaSupport '' 84 addDriverRunpath $1 85 ''} 86 } 87 fixRunPath $out/${python.sitePackages}/paddle/fluid/libpaddle.so 88 ''; 89 90 nativeBuildInputs = [ addDriverRunpath ]; 91 92 propagatedBuildInputs = [ 93 setuptools 94 httpx 95 numpy 96 protobuf 97 pillow 98 decorator 99 astor 100 paddle-bfloat 101 opt-einsum 102 ]; 103 104 pythonImportsCheck = [ "paddle" ]; 105 106 # no tests 107 doCheck = false; 108 109 meta = with lib; { 110 description = "PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice &"; 111 homepage = "https://github.com/PaddlePaddle/Paddle"; 112 license = licenses.asl20; 113 maintainers = with maintainers; [ happysalada ]; 114 platforms = 115 [ "x86_64-linux" ] 116 ++ optionals (!cudaSupport) [ 117 "x86_64-darwin" 118 "aarch64-darwin" 119 ]; 120 }; 121}