Skip to content

Commit

Permalink
refactor: add notebookConfig option for the jupyterlab
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Oct 2, 2023
1 parent 5df3ab7 commit c1e0601
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/jupyter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@

mkJupyterlab = {
jupyterlabEnvArgs ? {},
notebookConfig ? {},
kernels ? k: [], # k: [ (k.python {}) k.bash ],
# extensions ? e: [], # e: [ e.jupy-ext ]
runtimePackages ? [], # runtime package available to all binaries
Expand All @@ -118,14 +119,20 @@
jupyterlabEnv = jupyterlabEnvWrapped (baseArgs // jupyterlabEnvArgs);

# create directories for storing jupyter configs
jupyterDir = pkgs.runCommand "jupyter-dir" {} ''
# make jupyter config and data directories
mkdir -p $out/config $out/data
echo "c.NotebookApp.use_redirect_file = False" > $out/config/jupyter_notebook_config.py
jupyterDir = let
mergedNotebookConfig = lib.recursiveUpdate notebookConfig {
NotebookApp.use_redirect_file = false;
KernelSpecManager.whitelist = map (x: "${pkgs.lib.removeSuffix "-jupyter-kernel" x.name}") kernelDerivations;
};
in
pkgs.runCommand "jupyter-dir" {} ''
# make jupyter config and data directories
mkdir -p $out/config $out/data
echo '${builtins.toJSON mergedNotebookConfig}' > $out/config/jupyter_lab_config.json
# make jupyter lab user settings and workspaces directories
mkdir -p $out/config/lab/{user-settings,workspaces}
'';
# make jupyter lab user settings and workspaces directories
mkdir -p $out/config/lab/{user-settings,workspaces}
'';
in
pkgs.runCommand "wrapper-${jupyterlabEnv.name}"
{
Expand Down
5 changes: 5 additions & 0 deletions modules/conf/jupyter_notebook_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"NotebookApp": {
"use_redirect_file" : false
}
}
8 changes: 8 additions & 0 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ in {
default = [];
};

notebookConfig = lib.mkOption {
type = types.attrs;
description = "jupyter notebook config which will be written to jupyter_notebook_config.py";
default = {};
apply = c: lib.recursiveUpdate (lib.importJSON ./conf/jupyter_notebook_config.json) c;
};

jupyterlabEnvArgs = lib.mkOption {
type = types.submodule {
options =
Expand Down Expand Up @@ -93,6 +100,7 @@ in {
inherit
(config.jupyterlab)
runtimePackages
notebookConfig
;
kernels =
lib.flatten
Expand Down

0 comments on commit c1e0601

Please sign in to comment.