1{ stdenv 2, fetchurl 3, buildPythonPackage 4, isPy35, isPy27 5, cudaSupport ? false 6, cudatoolkit ? null 7, cudnn ? null 8, linuxPackages ? null 9, numpy 10, six 11, protobuf3_2 12, swig 13, werkzeug 14, mock 15, zlib 16}: 17 18assert cudaSupport -> cudatoolkit != null 19 && cudnn != null 20 && linuxPackages != null; 21 22# unsupported combination 23assert ! (stdenv.isDarwin && cudaSupport); 24 25# tensorflow is built from a downloaded wheel, because the upstream 26# project's build system is an arcane beast based on 27# bazel. Untangling it and building the wheel from source is an open 28# problem. 29 30buildPythonPackage rec { 31 pname = "tensorflow"; 32 version = "1.1.0"; 33 name = "${pname}-${version}"; 34 format = "wheel"; 35 disabled = ! (isPy35 || isPy27); 36 37 src = let 38 tfurl = sys: proc: pykind: 39 let 40 tfpref = if proc == "gpu" 41 then "gpu/tensorflow_gpu" 42 else "cpu/tensorflow"; 43 in 44 "https://storage.googleapis.com/tensorflow/${sys}/${tfpref}-${version}-${pykind}.whl"; 45 dls = 46 { 47 darwin.cpu = { 48 py2 = { 49 url = tfurl "mac" "cpu" "py2-none-any" ; 50 sha256 = "1fgf26lw0liqxc9pywc8y2mj8l1mv48nhkav0pag9vavdacb9mqr"; 51 }; 52 py3 = { 53 url = tfurl "mac" "cpu" "py3-none-any" ; 54 sha256 = "0z5p1fra7bih0vqn618i2w3vyy8d1rkc72k7bmjq0rw8msl717ia"; 55 }; 56 }; 57 linux-x86_64.cpu = { 58 py2 = { 59 url = tfurl "linux" "cpu" "cp27-none-linux_x86_64"; 60 sha256 = "0ld3hqx3idxk0zcrvn3p9yqnmx09zsj3mw66jlfw6fkv5hznx8j2"; 61 }; 62 py3 = { 63 url = tfurl "linux" "cpu" "cp35-cp35m-linux_x86_64"; 64 sha256 = "0ahz9222rzqrk43lb9w4m351klkm6mlnnvw8xfqip28vbmymw90b"; 65 }; 66 }; 67 linux-x86_64.cuda = { 68 py2 = { 69 url = tfurl "linux" "gpu" "cp27-none-linux_x86_64"; 70 sha256 = "1baa9jwr6f8f62dyx6isbw8yyrd0pi1dz1srjblfqsyk1x3pnfvh"; 71 }; 72 py3 = { 73 url = tfurl "linux" "gpu" "cp35-cp35m-linux_x86_64"; 74 sha256 = "0606m2awy0ifhniy8lsyhd0xc388dgrwksn87989xlgy90wpxi92"; 75 }; 76 }; 77 }; 78 in 79 fetchurl ( 80 if stdenv.isDarwin then 81 if isPy35 then 82 dls.darwin.cpu.py3 83 else 84 dls.darwin.cpu.py2 85 else if isPy35 then 86 if cudaSupport then 87 dls.linux-x86_64.cuda.py3 88 else dls.linux-x86_64.cpu.py3 89 else 90 if cudaSupport then 91 dls.linux-x86_64.cuda.py2 92 else 93 dls.linux-x86_64.cpu.py2 94 ); 95 96 propagatedBuildInputs = with stdenv.lib; 97 [ numpy six protobuf3_2 swig werkzeug mock ] 98 ++ optionals cudaSupport [ cudatoolkit cudnn stdenv.cc ]; 99 100 # Note that we need to run *after* the fixup phase because the 101 # libraries are loaded at runtime. If we run in preFixup then 102 # patchelf --shrink-rpath will remove the cuda libraries. 103 postFixup = let 104 rpath = stdenv.lib.makeLibraryPath 105 (if cudaSupport then 106 [ stdenv.cc.cc.lib zlib cudatoolkit cudnn 107 linuxPackages.nvidia_x11 ] 108 else 109 [ stdenv.cc.cc.lib zlib ] 110 ); 111 in 112 '' 113 find $out -name '*.so' -exec patchelf --set-rpath "${rpath}" {} \; 114 ''; 115 116 doCheck = false; 117 118 meta = with stdenv.lib; { 119 description = "TensorFlow helps the tensors flow"; 120 homepage = http://tensorflow.org; 121 license = licenses.asl20; 122 maintainers = with maintainers; [ jpbernardy ]; 123 platforms = with platforms; if cudaSupport then linux else linux ++ darwin; 124 }; 125}