forked from tweag/jupyenv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
78 lines (71 loc) · 2.41 KB
/
default.nix
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
{ overlays ? []
, config ? {}
, pkgs ? import ./nix { inherit config overlays; }
, python3 ? pkgs.python3
}:
with (import ./lib/directory.nix { inherit pkgs; });
with (import ./lib/docker.nix { inherit pkgs; });
let
# Kernel generators.
kernels = pkgs.callPackage ./kernels {};
kernelsString = pkgs.lib.concatMapStringsSep ":" (k: "${k.spec}");
# Python version setup.
pythonPackages = python3.pkgs;
# Default configuration.
defaultDirectory = "${pythonPackages.jupyterlab}/share/jupyter/lab";
defaultKernels = [ (kernels.iPythonWith {}) ];
defaultExtraPackages = p: [];
defaultExtraInputsFrom = p: [];
# JupyterLab with the appropriate kernel and directory setup.
jupyterlabWith = {
directory ? defaultDirectory,
kernels ? defaultKernels,
extraPackages ? defaultExtraPackages,
extraInputsFrom ? defaultExtraInputsFrom,
extraPythonPath ? [],
extraJupyterPath ? _: ""
}:
let
# PYTHONPATH setup for JupyterLab
pythonPath = pythonPackages.makePythonPath ([
pythonPackages.ipykernel
pythonPackages.jupyter_contrib_core
pythonPackages.jupyter_nbextensions_configurator
pythonPackages.tornado
] ++ (extraPythonPath pythonPackages));
# JupyterLab executable wrapped with suitable environment variables.
jupyterlab = pythonPackages.toPythonModule (
pythonPackages.jupyterlab.overridePythonAttrs (oldAttrs: {
makeWrapperArgs = [
"--set JUPYTERLAB_DIR ${directory}"
"--set JUPYTER_PATH ${extraJupyterPath pkgs}:${kernelsString kernels}"
"--set PYTHONPATH ${extraJupyterPath pkgs}:${pythonPath}"
];
})
);
# Shell with the appropriate JupyterLab, launching it at startup.
env = pkgs.mkShell {
name = "jupyterlab-shell";
inputsFrom = extraInputsFrom pkgs;
buildInputs =
[ jupyterlab generateDirectory generateLockFile pkgs.nodejs ] ++
(map (k: k.runtimePackages) kernels) ++
(extraPackages pkgs);
shellHook = ''
export JUPYTER_PATH=${kernelsString kernels}
export JUPYTERLAB=${jupyterlab}
'';
};
in
jupyterlab.override (oldAttrs: {
passthru = oldAttrs.passthru or {} // { inherit env; };
});
in
{ inherit
jupyterlabWith
kernels
mkBuildExtension
mkDirectoryWith
mkDirectoryFromLockFile
mkDockerImage;
}