@@ -0,0 +1,85 @@
1+{ lib
2+, fetchFromGitHub
3+, buildBazelPackage
4+, buildPythonPackage
5+, git
6+, python
7+, six
8+, absl-py
9+, semantic-version
10+, contextlib2
11+, wrapt
12+, tensorflow
13+, tensorflow-probability
14+}:
15+
16+let
17+ version = "1.30";
18+
19+ # first build all binaries and generate setup.py using bazel
20+ bazel-build = buildBazelPackage rec {
21+ name = "dm-sonnet-bazel-${version}";
22+
23+ src = fetchFromGitHub {
24+ owner = "deepmind";
25+ repo = "sonnet";
26+ rev = "v${version}";
27+ sha256 = "1dli4a4arx2gmb4p676pfibvnpag9f13znisrk9381g7xpqqmaw6";
28+ };
29+
30+ nativeBuildInputs = [
31+ git # needed to fetch the bazel deps (protobuf in particular)
32+ ];
33+
34+ # see https://github.com/deepmind/sonnet/blob/master/docs/INSTALL.md
35+ bazelTarget = ":install";
36+
37+ fetchAttrs = {
38+ sha256 = "1qwq6xp6gdmy8f0k96q3nsgqs56adrbgq39g5smwik6griwfx9mr";
39+ };
40+
41+ buildAttrs = {
42+ preBuild = ''
43+ patchShebangs .
44+ '';
45+
46+ installPhase = ''
47+ # do not generate a wheel, instead just copy the generated files to $out to be installed by buildPythonPackage
48+ sed -i 's,.*bdist_wheel.*,cp -rL . "$out"; exit 0,' bazel-bin/install
49+
50+ # the target directory "dist" does not actually matter since we're not generating a wheel
51+ bazel-bin/install dist
52+ '';
53+ };
54+ };
55+
56+# now use pip to install the package prepared by bazel
57+in buildPythonPackage rec {
58+ pname = "dm-sonnet";
59+ inherit version;
60+
61+ src = bazel-build;
62+
63+ propagatedBuildInputs = [
64+ six
65+ absl-py
66+ semantic-version
67+ contextlib2
68+ wrapt
69+ tensorflow
70+ tensorflow-probability
71+ ];
72+
73+ # not sure how to properly run the real test suite -- through bazel?
74+ checkPhase = ''
75+ ${python.interpreter} -c "import sonnet"
76+ '';
77+
78+ meta = with lib; {
79+ description = "TensorFlow-based neural network library";
80+ homepage = https://sonnet.dev;
81+ license = licenses.asl20;
82+ maintainers = with maintainers; [ timokau ];
83+ platforms = platforms.linux;
84+ };
85+}