Skip to content

Commit

Permalink
jupyterlab: add notebookConfig option
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Feb 4, 2023
1 parent fc1128d commit c96f78e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,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 Down Expand Up @@ -394,7 +395,7 @@
# 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
echo '${builtins.toJSON notebookConfig}' > $out/config/jupyter_notebook_config.json
# make jupyter lab user settings and workspaces directories
mkdir -p $out/config/lab/{user-settings,workspaces}
'';
Expand Down
13 changes: 13 additions & 0 deletions modules/conf/jupyter_notebook_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"LanguageServerManager": {
"language_servers": {
"haskell-language-server": {
"version": 2,
"argv": ["haskell-language-server-wrapper", "lsp"],
"languages": ["haskell"],
"display_name": "haskell-language-server",
"mimetypes": ["text/haskell", "text/x-haskell"]
}
}
}
}
15 changes: 12 additions & 3 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ in {
description = "A list of runtime packages available to all binaries";
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;
};

extensions = {
features = lib.mkOption {
type = types.listOf types.str;
Expand All @@ -35,7 +42,7 @@ in {
type = types.functionTo types.package;
description = "Python language server";
default = ps: ps.python-lsp-server;
example = lib.literalExample ''
example = lib.literalExpression ''
if you want to use pyls-mypy or othter dependencies, you can do:
extraPackages = ps: [] ++ python-lsp-server.passthru.optional-dependencies.all;
'';
Expand All @@ -44,7 +51,7 @@ in {
type = types.package;
description = "Haskell language server";
default = config.nixpkgs.haskell-language-server;
example = lib.literalExample ''
example = lib.literalExpression ''
config.nixpkgs.haskell-language-server.override { supportedGhcVersions = [ "90" "94" ]; };
'';
};
Expand Down Expand Up @@ -140,7 +147,7 @@ in {
poetry2nix
;

# all of packages should be kept in extraPackages, instead of runtimePackages
# all of python packages should be kept in extraPackages, instead of runtimePackages
extraPackages = ps:
(lib.optionals (enabledLanguage "python" "lsp") [
(config.jupyterlab.extensions.languageServers.python ps)
Expand All @@ -150,6 +157,8 @@ in {
++ (config.jupyterlab.jupyterlabEnvArgs.extraPackages ps);
};

notebookConfig = config.jupyterlab.notebookConfig;

runtimePackages =
config.jupyterlab.runtimePackages
++ (lib.optionals (enabledLanguage "haskell" "lsp") [
Expand Down
32 changes: 32 additions & 0 deletions template/lsp.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
pkgs,
config,
...
}: {
jupyterlab = {
extensions = {
features = ["lsp" "jupytext"];
languageServers = {
python = ps: ps.python-lsp-server;
};
};
notebookConfig = {
# add your custom language server config here or other notebook config for the jupyterlab_notebook_config.json
# LanguageServerManager.language_servers.custom-language-servers
# "argv" = ["haskell-language-server" "--lsp"];
# "languages" = ["haskell"];
# "display_name" = "haskell-language-server";
# "mimetypes" = ["text/haskell" "text/x-haskell"];
# };
};
runtimePackages = [];
jupyterlabEnvArgs.extraPackages = ps: ([] ++ ps.python-lsp-server.passthru.optional-dependencies.all);
};
kernel.python.minimal = {
enable = true;
};
kernel.haskell.minimal = {
enable = true;
haskellCompiler = "ghc902";
};
}

0 comments on commit c96f78e

Please sign in to comment.