2017-02-15 12:30:30 +01:00
|
|
|
{ stdenv
|
2017-10-03 15:50:39 +02:00
|
|
|
, symlinkJoin
|
2017-09-16 17:00:48 +02:00
|
|
|
, lib
|
2017-02-15 12:30:30 +01:00
|
|
|
, fetchurl
|
|
|
|
, buildPythonPackage
|
2017-09-16 17:00:48 +02:00
|
|
|
, isPy3k, isPy35, isPy36, isPy27
|
2017-02-26 11:03:27 +01:00
|
|
|
, cudaSupport ? false
|
2017-02-27 15:23:23 +01:00
|
|
|
, cudatoolkit ? null
|
|
|
|
, cudnn ? null
|
2017-02-26 11:03:27 +01:00
|
|
|
, linuxPackages ? null
|
2017-02-15 12:30:30 +01:00
|
|
|
, numpy
|
|
|
|
, six
|
2017-09-08 20:24:14 +02:00
|
|
|
, protobuf
|
2017-02-15 12:30:30 +01:00
|
|
|
, mock
|
2017-09-11 11:23:40 +02:00
|
|
|
, backports_weakref
|
2017-02-15 12:30:30 +01:00
|
|
|
, zlib
|
2017-09-16 17:00:48 +02:00
|
|
|
, tensorflow-tensorboard
|
2017-02-15 12:30:30 +01:00
|
|
|
}:
|
|
|
|
|
2017-02-27 15:23:23 +01:00
|
|
|
assert cudaSupport -> cudatoolkit != null
|
|
|
|
&& cudnn != null
|
2017-02-26 11:03:27 +01:00
|
|
|
&& linuxPackages != null;
|
|
|
|
|
|
|
|
# unsupported combination
|
|
|
|
assert ! (stdenv.isDarwin && cudaSupport);
|
|
|
|
|
2017-02-15 12:30:30 +01:00
|
|
|
# tensorflow is built from a downloaded wheel, because the upstream
|
|
|
|
# project's build system is an arcane beast based on
|
|
|
|
# bazel. Untangling it and building the wheel from source is an open
|
|
|
|
# problem.
|
|
|
|
|
|
|
|
buildPythonPackage rec {
|
|
|
|
pname = "tensorflow";
|
2017-09-11 11:23:40 +02:00
|
|
|
version = "1.3.0";
|
2017-02-15 12:30:30 +01:00
|
|
|
name = "${pname}-${version}";
|
|
|
|
format = "wheel";
|
2017-09-16 17:00:48 +02:00
|
|
|
disabled = ! (isPy35 || isPy36 || isPy27);
|
2017-02-15 12:30:30 +01:00
|
|
|
|
2017-10-03 15:50:39 +02:00
|
|
|
# cudatoolkit is split (see https://github.com/NixOS/nixpkgs/commit/bb1c9b027d343f2ce263496582d6b56af8af92e6)
|
|
|
|
# However this means that libcusolver is not loadable by tensor flow. So we undo the split here.
|
|
|
|
cudatoolkit_joined = symlinkJoin {
|
|
|
|
name = "unsplit_cudatoolkit";
|
|
|
|
paths = [ cudatoolkit.out
|
|
|
|
cudatoolkit.lib ];};
|
|
|
|
|
2017-02-26 11:03:27 +01:00
|
|
|
src = let
|
|
|
|
tfurl = sys: proc: pykind:
|
|
|
|
let
|
|
|
|
tfpref = if proc == "gpu"
|
|
|
|
then "gpu/tensorflow_gpu"
|
|
|
|
else "cpu/tensorflow";
|
|
|
|
in
|
|
|
|
"https://storage.googleapis.com/tensorflow/${sys}/${tfpref}-${version}-${pykind}.whl";
|
|
|
|
dls =
|
|
|
|
{
|
|
|
|
darwin.cpu = {
|
|
|
|
py2 = {
|
|
|
|
url = tfurl "mac" "cpu" "py2-none-any" ;
|
2017-09-11 11:23:40 +02:00
|
|
|
sha256 = "0nkymqbqjx8rsmc8vkc26cfsg4hpr6lj9zrwhjnfizvkzbbsh5z4";
|
2017-02-26 11:03:27 +01:00
|
|
|
};
|
|
|
|
py3 = {
|
|
|
|
url = tfurl "mac" "cpu" "py3-none-any" ;
|
2017-09-11 11:23:40 +02:00
|
|
|
sha256 = "1rj4m817w3lajnb1lgn3bwfwwk3qwvypyx11dim1ybakbmsc1j20";
|
2017-02-26 11:03:27 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
linux-x86_64.cpu = {
|
|
|
|
py2 = {
|
|
|
|
url = tfurl "linux" "cpu" "cp27-none-linux_x86_64";
|
2017-09-11 11:23:40 +02:00
|
|
|
sha256 = "09pcyx0yfil4dm6cij8n3907pfgva07a38avrbai4qk5h6hxm8w9";
|
2017-02-26 11:03:27 +01:00
|
|
|
};
|
2017-09-16 17:00:48 +02:00
|
|
|
py35 = {
|
|
|
|
url = tfurl "linux" "cpu" "cp35-cp35m-linux_x86_64";
|
|
|
|
sha256 = "0p10zcf41pi33bi025fibqkq9rpd3v0rrbdmc9i9yd7igy076a07";
|
|
|
|
};
|
|
|
|
py36 = {
|
2017-09-10 16:37:02 +02:00
|
|
|
url = tfurl "linux" "cpu" "cp36-cp36m-linux_x86_64";
|
2017-09-11 11:23:40 +02:00
|
|
|
sha256 = "1qm8lm2f6bf9d462ybgwrz0dn9i6cnisgwdvyq9ssmy2f1gp8hxk";
|
2017-09-10 16:37:02 +02:00
|
|
|
};
|
2017-02-26 11:03:27 +01:00
|
|
|
};
|
|
|
|
linux-x86_64.cuda = {
|
|
|
|
py2 = {
|
|
|
|
url = tfurl "linux" "gpu" "cp27-none-linux_x86_64";
|
2017-09-11 11:23:40 +02:00
|
|
|
sha256 = "10yyyn4g2fsv1xgmw99bbr0fg7jvykay4gb5pxrrylh7h38h6wah";
|
2017-02-26 11:03:27 +01:00
|
|
|
};
|
2017-09-16 17:00:48 +02:00
|
|
|
py35 = {
|
|
|
|
url = tfurl "linux" "gpu" "cp35-cp35m-linux_x86_64";
|
|
|
|
sha256 = "0icwnhkcf3fxr6bmbihqzipnn4pxybd06qv7l3k0p4xdgycwzmzk";
|
|
|
|
};
|
|
|
|
py36 = {
|
2017-09-10 16:37:02 +02:00
|
|
|
url = tfurl "linux" "gpu" "cp36-cp36m-linux_x86_64";
|
2017-09-11 11:23:40 +02:00
|
|
|
sha256 = "12g3akkr083gs3sisjbmm0lpsk8phn3dvy7jjfadfxshqc7za14i";
|
2017-09-10 16:37:02 +02:00
|
|
|
};
|
2017-02-26 11:03:27 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
fetchurl (
|
|
|
|
if stdenv.isDarwin then
|
2017-09-16 17:00:48 +02:00
|
|
|
if isPy3k then
|
2017-09-10 16:37:02 +02:00
|
|
|
dls.darwin.cpu.py3
|
2017-09-11 11:23:40 +02:00
|
|
|
else
|
|
|
|
dls.darwin.cpu.py2
|
2017-02-26 11:03:27 +01:00
|
|
|
else
|
2017-09-16 17:00:48 +02:00
|
|
|
if isPy35 then
|
|
|
|
if cudaSupport then
|
|
|
|
dls.linux-x86_64.cuda.py35
|
|
|
|
else
|
|
|
|
dls.linux-x86_64.cpu.py35
|
|
|
|
else if isPy36 then
|
|
|
|
if cudaSupport then
|
|
|
|
dls.linux-x86_64.cuda.py36
|
|
|
|
else
|
|
|
|
dls.linux-x86_64.cpu.py36
|
2017-02-26 11:03:27 +01:00
|
|
|
else
|
2017-09-16 17:00:48 +02:00
|
|
|
if cudaSupport then
|
|
|
|
dls.linux-x86_64.cuda.py2
|
|
|
|
else
|
|
|
|
dls.linux-x86_64.cpu.py2
|
2017-02-26 11:03:27 +01:00
|
|
|
);
|
2017-02-15 12:30:30 +01:00
|
|
|
|
2017-09-16 17:00:48 +02:00
|
|
|
propagatedBuildInputs =
|
|
|
|
[ numpy six protobuf mock backports_weakref ]
|
|
|
|
++ lib.optional (!isPy36) tensorflow-tensorboard
|
2017-10-03 15:50:39 +02:00
|
|
|
++ lib.optionals cudaSupport [ cudatoolkit_joined cudnn stdenv.cc ];
|
2017-02-15 12:30:30 +01:00
|
|
|
|
2017-09-11 11:23:40 +02:00
|
|
|
# tensorflow-gpu depends on tensorflow_tensorboard, which cannot be
|
|
|
|
# built at the moment (some of its dependencies do not build
|
|
|
|
# [htlm5lib9999999 (seven nines) -> tensorboard], and it depends on an old version of
|
|
|
|
# bleach) Hence we disable dependency checking for now.
|
2017-09-16 17:00:48 +02:00
|
|
|
installFlags = lib.optional isPy36 "--no-dependencies";
|
2017-09-11 11:23:40 +02:00
|
|
|
|
2017-02-26 11:03:27 +01:00
|
|
|
# Note that we need to run *after* the fixup phase because the
|
|
|
|
# libraries are loaded at runtime. If we run in preFixup then
|
|
|
|
# patchelf --shrink-rpath will remove the cuda libraries.
|
|
|
|
postFixup = let
|
|
|
|
rpath = stdenv.lib.makeLibraryPath
|
|
|
|
(if cudaSupport then
|
2017-10-03 15:50:39 +02:00
|
|
|
[ stdenv.cc.cc.lib zlib cudatoolkit_joined cudnn
|
2017-02-26 11:03:27 +01:00
|
|
|
linuxPackages.nvidia_x11 ]
|
|
|
|
else
|
2017-05-29 19:24:34 +02:00
|
|
|
[ stdenv.cc.cc.lib zlib ]
|
2017-02-26 11:03:27 +01:00
|
|
|
);
|
|
|
|
in
|
|
|
|
''
|
|
|
|
find $out -name '*.so' -exec patchelf --set-rpath "${rpath}" {} \;
|
2017-02-15 12:30:30 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = false;
|
|
|
|
|
|
|
|
meta = with stdenv.lib; {
|
2017-02-26 11:03:27 +01:00
|
|
|
description = "TensorFlow helps the tensors flow";
|
2017-02-15 12:30:30 +01:00
|
|
|
homepage = http://tensorflow.org;
|
|
|
|
license = licenses.asl20;
|
2017-09-12 09:59:28 +02:00
|
|
|
maintainers = with maintainers; [ jyp ];
|
2017-02-26 11:03:27 +01:00
|
|
|
platforms = with platforms; if cudaSupport then linux else linux ++ darwin;
|
2017-02-15 12:30:30 +01:00
|
|
|
};
|
|
|
|
}
|