about summary refs log tree commit diff
path: root/pkgs/applications/editors/jupyter/console.nix
blob: 06bc82a1780b4c672eb98cae0e143cfbac8f8441 (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
{ python3
, jupyter-kernel
, lib
}:

let
  mkConsole = {
    definitions ? jupyter-kernel.default
    , kernel ? null
  }:
    (python3.buildEnv.override {
      extraLibs = [ python3.pkgs.jupyter-console ];
      makeWrapperArgs = [
        "--set JUPYTER_PATH ${jupyter-kernel.create { inherit definitions; }}"
      ] ++ lib.optionals (kernel != null) [
        "--add-flags --kernel"
        "--add-flags ${kernel}"
      ];
    }).overrideAttrs (oldAttrs: {
      # To facilitate running nix run .#jupyter-console
      meta = oldAttrs.meta // { mainProgram = "jupyter-console"; };
    });

in

{
  # Build a console derivation with an arbitrary set of definitions, and an optional kernel to use.
  # If the kernel argument is not supplied, Jupyter console will pick a kernel to run from the ones
  # available on the system.
  inherit mkConsole;

  # An ergonomic way to start a console with a single kernel.
  withSingleKernel = definition: mkConsole {
    definitions = lib.listToAttrs [(lib.nameValuePair definition.language definition)];
    kernel = definition.language;
  };
}