at master 4.8 kB view raw
1{ 2 lib, 3 stdenv, 4 python, 5 buildPythonPackage, 6 callPackage, 7 fetchurl, 8 autoPatchelfHook, 9 bash, 10 dejavu_fonts, 11 expat, 12 fontconfig, 13 lato, 14 libGL, 15 makeWrapper, 16 nspr, 17 nss, 18 sbclPackages, 19 sqlite, 20}: 21 22buildPythonPackage rec { 23 pname = "kaleido"; 24 version = "0.2.1"; 25 format = "wheel"; 26 27 src = 28 { 29 # This library is so cursed that I have to use fetchurl instead of fetchPypi. I am not happy. 30 x86_64-linux = fetchurl { 31 url = "https://files.pythonhosted.org/packages/py2.py3/k/kaleido/kaleido-${version}-py2.py3-none-manylinux1_x86_64.whl"; 32 hash = "sha256-qiHPG/HHj4+lCp99ReEAPDh709b+CnZ8+780S5W9w6g="; 33 }; 34 aarch64-linux = fetchurl { 35 url = "https://files.pythonhosted.org/packages/py2.py3/k/kaleido/kaleido-${version}-py2.py3-none-manylinux2014_aarch64.whl"; 36 hash = "sha256-hFgZhEyAgslGnZwX5CYh+/hcKyN++KhuyKhSf5i2USo="; 37 }; 38 x86_64-darwin = fetchurl { 39 url = "https://files.pythonhosted.org/packages/py2.py3/k/kaleido/kaleido-${version}-py2.py3-none-macosx_10_11_x86_64.whl"; 40 hash = "sha256-ym9z5/8AquvyhD9z8dO6zeGTDvUEEJP+drg6FXhQSac="; 41 }; 42 aarch64-darwin = fetchurl { 43 url = "https://files.pythonhosted.org/packages/py2.py3/k/kaleido/kaleido-${version}-py2.py3-none-macosx_11_0_arm64.whl"; 44 hash = "sha256-u5pdH3EDV9XUMu4kDvZlim0STD5hCTWBe0tC2px4fAU="; 45 }; 46 } 47 ."${stdenv.hostPlatform.system}" 48 or (throw "Unsupported system for ${pname}: ${stdenv.hostPlatform.system}"); 49 50 nativeBuildInputs = (lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ]) ++ [ 51 makeWrapper 52 ]; 53 buildInputs = [ 54 bash 55 dejavu_fonts 56 expat 57 fontconfig 58 lato 59 libGL 60 nspr 61 nss 62 sbclPackages.cl-dejavu 63 sqlite 64 ]; 65 66 pythonImportsCheck = [ "kaleido" ]; 67 68 postInstall = '' 69 # Expose kaleido binary 70 mkdir -p $out/bin 71 ln -s $out/${python.sitePackages}/kaleido/executable/bin/kaleido $out/bin/kaleido 72 73 # Relace bundled libraries with nixpkgs-packaged libraries 74 rm -rf $out/${python.sitePackages}/kaleido/executable/lib 75 mkdir -p $out/${python.sitePackages}/kaleido/executable/lib 76 ln -s ${expat}/lib/* $out/${python.sitePackages}/kaleido/executable/lib/ 77 ln -s ${nspr}/lib/* $out/${python.sitePackages}/kaleido/executable/lib/ 78 ln -s ${nss}/lib/* $out/${python.sitePackages}/kaleido/executable/lib/ 79 ln -s ${sqlite}/lib/* $out/${python.sitePackages}/kaleido/executable/lib/ 80 81 # Replace bundled font configuration with nixpkgs-packaged font configuration 82 rm -rf $out/${python.sitePackages}/kaleido/executable/etc/fonts 83 mkdir -p $out/${python.sitePackages}/kaleido/executable/etc/fonts/conf.d 84 ln -s ${fontconfig.out}/etc/fonts/fonts.conf $out/${python.sitePackages}/kaleido/executable/etc/fonts/ 85 ls -s ${fontconfig.out}/etc/fonts/conf.d/* $out/${python.sitePackages}/kaleido/executable/etc/fonts/conf.d/ 86 ln -s ${sbclPackages.cl-dejavu}/dejavu-fonts-ttf-2.37/fontconfig/* $out/${python.sitePackages}/kaleido/executable/etc/fonts/conf.d/ 87 88 # Replace bundled fonts with nixpkgs-packaged fonts 89 # Currently this causes an issue where the fonts aren't found. I'm not sure why, so I'm leaving this commented out for now. 90 #rm -rf $out/${python.sitePackages}/kaleido/executable/xdg/fonts 91 #mkdir -p $out/${python.sitePackages}/kaleido/executable/xdg/fonts/truetype/dejavu $out/${python.sitePackages}/kaleido/executable/xdg/fonts/truetype/lato 92 #ln -s ${dejavu_fonts}/share/fonts/truetype/* $out/${python.sitePackages}/kaleido/executable/xdg/fonts/truetype/dejavu/ 93 #ln -s ${lato}/share/fonts/lato/* $out/${python.sitePackages}/kaleido/executable/xdg/fonts/truetype/lato/ 94 '' 95 + lib.optionalString (!stdenv.hostPlatform.isDarwin) '' 96 # Replace bundled swiftshader with libGL 97 rm -rf $out/${python.sitePackages}/kaleido/executable/bin/swiftshader 98 ln -s ${libGL}/lib $out/${python.sitePackages}/kaleido/executable/bin/swiftshader 99 ''; 100 101 passthru.tests = lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) { 102 kaleido = callPackage ./tests.nix { }; 103 }; 104 105 meta = { 106 description = "Fast static image export for web-based visualization libraries with zero dependencies"; 107 homepage = "https://github.com/plotly/Kaleido"; 108 changelog = "https://github.com/plotly/Kaleido/releases"; 109 platforms = [ 110 "x86_64-linux" 111 "x86_64-darwin" 112 "aarch64-linux" 113 "aarch64-darwin" 114 ]; 115 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; # Trust me, I'm not happy. But after literal hours of trying to reverse-engineer their build system and getting nowhere, I'll use the stupid binaries >:( 116 license = lib.licenses.mit; 117 maintainers = with lib.maintainers; [ pandapip1 ]; 118 }; 119}