about summary refs log tree commit diff
path: root/pkgs/development/python-modules/dm-sonnet/default.nix
blob: ffff1829948e034957404e5e393bbae04db8a735 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{ lib
, fetchFromGitHub
, buildBazelPackage
, buildPythonPackage
, git
, python
, six
, absl-py
, semantic-version
, contextlib2
, wrapt
, tensorflow
, tensorflow-probability
, tensorflow-estimator
}:

let
  version = "1.33";

  # first build all binaries and generate setup.py using bazel
  bazel-build = buildBazelPackage {
    name = "dm-sonnet-bazel-${version}";

    src = fetchFromGitHub {
      owner = "deepmind";
      repo = "sonnet";
      rev = "v${version}";
      sha256 = "1nqsja1s8jrkq6v1whgh7smk17313mjr9vs3k5c1m8px4yblzhqc";
    };

    nativeBuildInputs = [
      git # needed to fetch the bazel deps (protobuf in particular)
    ];

    # see https://github.com/deepmind/sonnet/blob/master/docs/INSTALL.md
    bazelTarget = ":install";

    fetchAttrs = {
      sha256 = "1xwrha692if7rwqc0qalgpx9b8indgdan8ppwlcs2v47wjvgg6h3";
    };

    bazelFlags = [
      # https://github.com/deepmind/sonnet/issues/134
      "--incompatible_disable_deprecated_attr_params=false"
    ];

    buildAttrs = {
      preBuild = ''
        patchShebangs .
      '';

      installPhase = ''
        # do not generate a wheel, instead just copy the generated files to $out to be installed by buildPythonPackage
        sed -i 's,.*bdist_wheel.*,cp -rL . "$out"; exit 0,' bazel-bin/install

        # the target directory "dist" does not actually matter since we're not generating a wheel
        bazel-bin/install dist
      '';
    };
  };

# now use pip to install the package prepared by bazel
in buildPythonPackage {
  pname = "dm-sonnet";
  inherit version;

  src = bazel-build;

  propagatedBuildInputs = [
    six
    absl-py
    semantic-version
    contextlib2
    wrapt
    tensorflow
    tensorflow-probability
    tensorflow-estimator
  ];

  # not sure how to properly run the real test suite -- through bazel?
  checkPhase = ''
    ${python.interpreter} -c "import sonnet"
  '';

  meta = with lib; {
    description = "TensorFlow-based neural network library";
    homepage = "https://sonnet.dev";
    license = licenses.asl20;
    maintainers = with maintainers; [ timokau ];
    platforms = platforms.linux;
  };
}