summary refs log tree commit diff
path: root/pkgs/development/python-modules/jupyterhub/default.nix
blob: c2855d6c8773b8f4543251d634ac2003d75a54fd (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
{ lib
, stdenv
, buildPythonPackage
, pythonOlder
, fetchPypi
, fetchzip
, alembic
, async_generator
, certipy
, python-dateutil
, entrypoints
, jinja2
, jupyter-telemetry
, oauthlib
, pamela
, prometheus-client
, requests
, sqlalchemy
, tornado
, traitlets
, nodePackages
, beautifulsoup4
, cryptography
, notebook
, pytest-asyncio
, pytestCheckHook
, requests-mock
, virtualenv
}:

let
  # js/css assets that setup.py tries to fetch via `npm install` when building
  # from source. https://github.com/jupyterhub/jupyterhub/blob/master/package.json
  bootstrap =
    fetchzip {
      url = "https://registry.npmjs.org/bootstrap/-/bootstrap-3.4.1.tgz";
      sha256 = "1ywmxqdccg0mgx0xknrn1hlrfnhcwphc12y9l91zizx26fqfmzgc";
    };
  font-awesome =
    fetchzip {
      url = "https://registry.npmjs.org/font-awesome/-/font-awesome-4.7.0.tgz";
      sha256 = "1xnxbdlfdd60z5ix152m8r2kk9dkwlqwpypky1mm3dv64ajnzdbk";
    };
  jquery =
    fetchzip {
      url = "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz";
      sha256 = "0yi9ql493din1qa1s923nd5zvd0klk1sx00xj1wx2yambmq86vm9";
    };
  moment =
    fetchzip {
      url = "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz";
      sha256 = "0ifzzla4zffw23g3xvhwx3fj3jny6cjzxfzl1x0317q8wa0c7w5i";
    };
  requirejs =
    fetchzip {
      url = "https://registry.npmjs.org/requirejs/-/requirejs-2.3.6.tgz";
      sha256 = "165hkli3qcd59cjqvli9r5f92i0h7czkmhcg1cgwamw2d0b7xibz";
    };

in

buildPythonPackage rec {
  pname = "jupyterhub";
  version = "1.3.0";
  disabled = pythonOlder "3.6";

  src = fetchPypi {
    inherit pname version;
    sha256 = "13pf6qhimpaxj20871ff5rvwwan59320cdhhrn9cfh6314971zq5";
  };

  # Most of this only applies when building from source (e.g. js/css assets are
  # pre-built and bundled in the official release tarball on pypi).
  #
  # Stuff that's always needed:
  #   * At runtime, we need configurable-http-proxy, so we substitute the store
  #     path.
  #
  # Other stuff that's only needed when building from source:
  #   * js/css assets are fetched from npm.
  #   * substitute store path for `lessc` commmand.
  #   * set up NODE_PATH so `lessc` can find `less-plugin-clean-css`.
  #   * don't run `npm install`.
  preBuild = ''
    export NODE_PATH=${nodePackages.less-plugin-clean-css}/lib/node_modules

    substituteInPlace jupyterhub/proxy.py --replace \
      "'configurable-http-proxy'" \
      "'${nodePackages.configurable-http-proxy}/bin/configurable-http-proxy'"

    substituteInPlace jupyterhub/tests/test_proxy.py --replace \
      "'configurable-http-proxy'" \
      "'${nodePackages.configurable-http-proxy}/bin/configurable-http-proxy'"

    substituteInPlace setup.py --replace \
      "'npm'" "'true'"

    declare -A deps
    deps[bootstrap]=${bootstrap}
    deps[font-awesome]=${font-awesome}
    deps[jquery]=${jquery}
    deps[moment]=${moment}
    deps[requirejs]=${requirejs}

    mkdir -p share/jupyter/hub/static/components
    for dep in "''${!deps[@]}"; do
      if [ ! -e share/jupyter/hub/static/components/$dep ]; then
        cp -r ''${deps[$dep]} share/jupyter/hub/static/components/$dep
      fi
    done
  '';

  propagatedBuildInputs = [
    # https://github.com/jupyterhub/jupyterhub/blob/master/requirements.txt
    alembic
    async_generator
    certipy
    python-dateutil
    entrypoints
    jinja2
    jupyter-telemetry
    oauthlib
    pamela
    prometheus-client
    requests
    sqlalchemy
    tornado
    traitlets
  ];

  preCheck = ''
    substituteInPlace jupyterhub/tests/test_spawner.py --replace \
      "'jupyterhub-singleuser'" "'$out/bin/jupyterhub-singleuser'"
  '';

  checkInputs = [
    # https://github.com/jupyterhub/jupyterhub/blob/master/dev-requirements.txt
    beautifulsoup4
    cryptography
    notebook
    pytest-asyncio
    pytestCheckHook
    requests-mock
    virtualenv
  ];

  disabledTests = [
    # Tries to install older versions through pip
    "test_upgrade"
    # Testcase fails to find requests import
    "test_external_service"
    # attempts to do ssl connection
    "test_connection_notebook_wrong_certs"
  ];

  meta = with lib; {
    # darwin: E   OSError: dlopen(/nix/store/43zml0mlr17r5jsagxr00xxx91hz9lky-openpam-20170430/lib/libpam.so, 6): image not found
    broken = (stdenv.isLinux && stdenv.isAarch64) || stdenv.isDarwin;
    description = "Serves multiple Jupyter notebook instances";
    homepage = "https://jupyter.org/";
    license = licenses.bsd3;
    maintainers = with maintainers; [ ixxie cstrahan ];
  };
}