2018-03-15 00:08:06 +00:00
|
|
|
{ stdenv
|
|
|
|
, lib
|
|
|
|
, fetchurl
|
|
|
|
, buildPythonPackage
|
2019-10-16 10:32:31 +01:00
|
|
|
, isPy3k, pythonOlder, isPy38
|
2018-06-07 12:30:29 +01:00
|
|
|
, astor
|
|
|
|
, gast
|
2019-06-22 12:43:06 +01:00
|
|
|
, google-pasta
|
|
|
|
, wrapt
|
2018-03-15 00:08:06 +00:00
|
|
|
, numpy
|
|
|
|
, six
|
2018-06-07 12:30:29 +01:00
|
|
|
, termcolor
|
2018-03-15 00:08:06 +00:00
|
|
|
, protobuf
|
|
|
|
, absl-py
|
2018-08-07 09:36:04 +01:00
|
|
|
, grpcio
|
2018-03-15 00:08:06 +00:00
|
|
|
, mock
|
|
|
|
, backports_weakref
|
2019-02-28 10:59:17 +00:00
|
|
|
, tensorflow-estimator
|
2018-03-15 00:08:06 +00:00
|
|
|
, tensorflow-tensorboard
|
|
|
|
, cudaSupport ? false
|
2018-05-30 15:38:51 +01:00
|
|
|
, cudatoolkit ? null
|
|
|
|
, cudnn ? null
|
|
|
|
, nvidia_x11 ? null
|
|
|
|
, zlib
|
|
|
|
, python
|
|
|
|
, symlinkJoin
|
2018-08-28 15:02:28 +01:00
|
|
|
, keras-applications
|
|
|
|
, keras-preprocessing
|
2019-10-02 08:32:48 +01:00
|
|
|
, addOpenGLRunpath
|
2018-03-15 00:08:06 +00:00
|
|
|
}:
|
|
|
|
|
2018-05-30 15:38:51 +01:00
|
|
|
# We keep this binary build for two reasons:
|
|
|
|
# - the source build doesn't work on Darwin.
|
|
|
|
# - the source build is currently brittle and not easy to maintain
|
2018-03-15 00:08:06 +00:00
|
|
|
|
2018-05-30 15:38:51 +01:00
|
|
|
assert cudaSupport -> cudatoolkit != null
|
|
|
|
&& cudnn != null
|
|
|
|
&& nvidia_x11 != null;
|
2019-07-13 20:37:01 +01:00
|
|
|
|
|
|
|
# unsupported combination
|
|
|
|
assert ! (stdenv.isDarwin && cudaSupport);
|
|
|
|
|
2018-05-30 15:38:51 +01:00
|
|
|
let
|
2019-07-13 20:37:01 +01:00
|
|
|
packages = import ./binary-hashes.nix;
|
|
|
|
|
|
|
|
variant = if cudaSupport then "-gpu" else "";
|
|
|
|
pname = "tensorflow${variant}";
|
2018-05-30 15:38:51 +01:00
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
in buildPythonPackage {
|
2019-07-13 20:37:01 +01:00
|
|
|
inherit pname;
|
|
|
|
inherit (packages) version;
|
2018-03-15 00:08:06 +00:00
|
|
|
format = "wheel";
|
|
|
|
|
2019-10-16 10:32:31 +01:00
|
|
|
disabled = isPy38;
|
|
|
|
|
2018-05-30 15:38:51 +01:00
|
|
|
src = let
|
2019-09-09 00:38:31 +01:00
|
|
|
pyVerNoDot = lib.strings.stringAsChars (x: if x == "." then "" else x) python.pythonVersion;
|
2018-08-07 09:36:04 +01:00
|
|
|
pyver = if stdenv.isDarwin then builtins.substring 0 1 pyVerNoDot else pyVerNoDot;
|
2018-05-30 15:38:51 +01:00
|
|
|
platform = if stdenv.isDarwin then "mac" else "linux";
|
|
|
|
unit = if cudaSupport then "gpu" else "cpu";
|
2018-08-07 09:36:04 +01:00
|
|
|
key = "${platform}_py_${pyver}_${unit}";
|
2019-07-13 20:37:01 +01:00
|
|
|
in fetchurl packages.${key};
|
2018-03-15 00:08:06 +00:00
|
|
|
|
2019-06-22 12:43:06 +01:00
|
|
|
propagatedBuildInputs = [
|
|
|
|
protobuf
|
|
|
|
numpy
|
|
|
|
termcolor
|
|
|
|
grpcio
|
|
|
|
six
|
|
|
|
astor
|
|
|
|
absl-py
|
|
|
|
gast
|
|
|
|
google-pasta
|
|
|
|
wrapt
|
|
|
|
tensorflow-estimator
|
|
|
|
tensorflow-tensorboard
|
|
|
|
keras-applications
|
|
|
|
keras-preprocessing
|
|
|
|
] ++ lib.optional (!isPy3k) mock
|
|
|
|
++ lib.optionals (pythonOlder "3.4") [ backports_weakref ];
|
2018-08-02 21:15:52 +01:00
|
|
|
|
2019-10-02 08:32:48 +01:00
|
|
|
nativeBuildInputs = lib.optional cudaSupport addOpenGLRunpath;
|
|
|
|
|
2018-08-02 21:15:52 +01:00
|
|
|
# Upstream has a pip hack that results in bin/tensorboard being in both tensorflow
|
|
|
|
# and the propageted input tensorflow-tensorboard which causes environment collisions.
|
2018-08-07 09:36:04 +01:00
|
|
|
# another possibility would be to have tensorboard only in the buildInputs
|
2018-08-02 21:15:52 +01:00
|
|
|
# https://github.com/tensorflow/tensorflow/blob/v1.7.1/tensorflow/tools/pip_package/setup.py#L79
|
|
|
|
postInstall = ''
|
|
|
|
rm $out/bin/tensorboard
|
|
|
|
'';
|
|
|
|
|
2018-05-30 15:38:51 +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
|
2019-07-13 20:37:01 +01:00
|
|
|
([ stdenv.cc.cc.lib zlib ] ++ lib.optionals cudaSupport [ cudatoolkit.out cudatoolkit.lib cudnn nvidia_x11 ]);
|
2018-05-30 15:38:51 +01:00
|
|
|
in
|
2019-07-13 20:37:01 +01:00
|
|
|
lib.optionalString stdenv.isLinux ''
|
2018-09-21 10:36:43 +01:00
|
|
|
rrPath="$out/${python.sitePackages}/tensorflow/:$out/${python.sitePackages}/tensorflow/contrib/tensor_forest/:${rpath}"
|
2018-05-30 15:38:51 +01:00
|
|
|
internalLibPath="$out/${python.sitePackages}/tensorflow/python/_pywrap_tensorflow_internal.so"
|
2019-10-02 08:32:48 +01:00
|
|
|
find $out -type f \( -name '*.so' -or -name '*.so.*' \) | while read lib; do
|
|
|
|
patchelf --set-rpath "$rrPath" "$lib"
|
|
|
|
${lib.optionalString cudaSupport ''
|
|
|
|
addOpenGLRunpath "$lib"
|
|
|
|
''}
|
|
|
|
done
|
2018-05-30 15:38:51 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
|
2018-03-15 00:08:06 +00:00
|
|
|
meta = with stdenv.lib; {
|
|
|
|
description = "Computation using data flow graphs for scalable machine learning";
|
|
|
|
homepage = http://tensorflow.org;
|
|
|
|
license = licenses.asl20;
|
|
|
|
maintainers = with maintainers; [ jyp abbradar ];
|
2019-07-13 20:37:01 +01:00
|
|
|
platforms = [ "x86_64-linux" "x86_64-darwin" ];
|
2018-03-15 00:08:06 +00:00
|
|
|
# Python 2.7 build uses different string encoding.
|
|
|
|
# See https://github.com/NixOS/nixpkgs/pull/37044#issuecomment-373452253
|
2018-05-30 15:38:51 +01:00
|
|
|
broken = stdenv.isDarwin && !isPy3k;
|
2018-03-15 00:08:06 +00:00
|
|
|
};
|
|
|
|
}
|