1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 replaceVars,
6 bashInteractive,
7 flit-core,
8 filetype,
9 ipykernel,
10 pexpect,
11 writableTmpDirAsHomeHook,
12 python,
13}:
14
15buildPythonPackage rec {
16 pname = "bash-kernel";
17 version = "0.10.0";
18 pyproject = true;
19
20 src = fetchFromGitHub {
21 owner = "takluyver";
22 repo = "bash_kernel";
23 tag = version;
24 hash = "sha256-ugFMcQx1B1nKoO9rhb6PMllRcoZi0O4B9um8dOu5DU4=";
25 };
26
27 patches = [
28 (replaceVars ./bash-path.patch {
29 bash = lib.getExe bashInteractive;
30 })
31 ];
32
33 build-system = [ flit-core ];
34
35 dependencies = [
36 filetype
37 ipykernel
38 pexpect
39 ];
40
41 nativeBuildInputs = [
42 writableTmpDirAsHomeHook
43 ];
44
45 postInstall = ''
46 ${python.pythonOnBuildForHost.interpreter} -m bash_kernel.install --prefix $out
47 '';
48
49 checkPhase = ''
50 runHook preCheck
51
52 # Create a JUPYTER_PATH with the kernelspec
53 export JUPYTER_PATH=$(mktemp -d)
54 mkdir -p $JUPYTER_PATH/kernels/bash
55 echo '{ "language": "bash", "argv": [ "${python}/bin/python", "-m", "bash_kernel", "-f", "{connection_file}" ] }' > $JUPYTER_PATH/kernels/bash/kernel.json
56
57 # Evaluate a test notebook with papermill
58 cd $(mktemp -d)
59 ${python.withPackages (ps: [ ps.papermill ])}/bin/papermill --kernel bash ${./test.ipynb} out.ipynb
60
61 runHook postCheck
62 '';
63
64 __darwinAllowLocalNetworking = true;
65
66 meta = {
67 description = "Bash Kernel for Jupyter";
68 homepage = "https://github.com/takluyver/bash_kernel";
69 changelog = "https://github.com/takluyver/bash_kernel/releases/tag/${version}";
70 license = lib.licenses.bsd3;
71 maintainers = with lib.maintainers; [ zimbatm ];
72 };
73}