1{ stdenv 2, lib 3, fetchurl 4, buildPythonPackage 5, isPy3k, isPy36, pythonOlder 6, astor 7, gast 8, numpy 9, six 10, termcolor 11, protobuf 12, absl-py 13, grpcio 14, mock 15, backports_weakref 16, enum34 17, tensorflow-tensorboard 18, cudaSupport ? false 19, cudatoolkit ? null 20, cudnn ? null 21, nvidia_x11 ? null 22, zlib 23, python 24, symlinkJoin 25}: 26 27# We keep this binary build for two reasons: 28# - the source build doesn't work on Darwin. 29# - the source build is currently brittle and not easy to maintain 30 31assert cudaSupport -> cudatoolkit != null 32 && cudnn != null 33 && nvidia_x11 != null; 34let 35 cudatoolkit_joined = symlinkJoin { 36 name = "unsplit_cudatoolkit"; 37 paths = [ cudatoolkit.out 38 cudatoolkit.lib ];}; 39 40in buildPythonPackage rec { 41 pname = "tensorflow"; 42 version = "1.9.0"; 43 format = "wheel"; 44 45 src = let 46 pyVerNoDot = lib.strings.stringAsChars (x: if x == "." then "" else x) "${python.majorVersion}"; 47 pyver = if stdenv.isDarwin then builtins.substring 0 1 pyVerNoDot else pyVerNoDot; 48 platform = if stdenv.isDarwin then "mac" else "linux"; 49 unit = if cudaSupport then "gpu" else "cpu"; 50 key = "${platform}_py_${pyver}_${unit}"; 51 dls = import ./tf1.9.0-hashes.nix; 52 in fetchurl dls.${key}; 53 54 propagatedBuildInputs = [ protobuf numpy termcolor grpcio six astor absl-py gast tensorflow-tensorboard ] 55 ++ lib.optional (!isPy3k) mock 56 ++ lib.optionals (pythonOlder "3.4") [ backports_weakref enum34 ]; 57 58 # Upstream has a pip hack that results in bin/tensorboard being in both tensorflow 59 # and the propageted input tensorflow-tensorboard which causes environment collisions. 60 # another possibility would be to have tensorboard only in the buildInputs 61 # https://github.com/tensorflow/tensorflow/blob/v1.7.1/tensorflow/tools/pip_package/setup.py#L79 62 postInstall = '' 63 rm $out/bin/tensorboard 64 ''; 65 66 installFlags = "--no-dependencies"; # tensorflow wants setuptools 39, can't allow that. 67 # Note that we need to run *after* the fixup phase because the 68 # libraries are loaded at runtime. If we run in preFixup then 69 # patchelf --shrink-rpath will remove the cuda libraries. 70 postFixup = let 71 rpath = stdenv.lib.makeLibraryPath 72 ([ stdenv.cc.cc.lib zlib ] ++ lib.optionals cudaSupport [ cudatoolkit_joined cudnn nvidia_x11 ]); 73 in 74 lib.optionalString (stdenv.isLinux) '' 75 rrPath="$out/${python.sitePackages}/tensorflow/:${rpath}" 76 internalLibPath="$out/${python.sitePackages}/tensorflow/python/_pywrap_tensorflow_internal.so" 77 find $out -name '*${stdenv.hostPlatform.extensions.sharedLibrary}' -exec patchelf --set-rpath "$rrPath" {} \; 78 ''; 79 80 81 meta = with stdenv.lib; { 82 description = "Computation using data flow graphs for scalable machine learning"; 83 homepage = http://tensorflow.org; 84 license = licenses.asl20; 85 maintainers = with maintainers; [ jyp abbradar ]; 86 platforms = with platforms; linux ++ lib.optionals (!cudaSupport) darwin; 87 # Python 2.7 build uses different string encoding. 88 # See https://github.com/NixOS/nixpkgs/pull/37044#issuecomment-373452253 89 broken = stdenv.isDarwin && !isPy3k; 90 }; 91}