diff --git a/flake.nix b/flake.nix index 0199b8cb..3ac143c9 100644 --- a/flake.nix +++ b/flake.nix @@ -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 @@ -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} ''; diff --git a/modules/conf/jupyter_notebook_config.json b/modules/conf/jupyter_notebook_config.json new file mode 100644 index 00000000..c1243385 --- /dev/null +++ b/modules/conf/jupyter_notebook_config.json @@ -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"] + } + } + } +} diff --git a/modules/default.nix b/modules/default.nix index 3cd40c77..510446c6 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -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; @@ -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; ''; @@ -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" ]; }; ''; }; @@ -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) @@ -150,6 +157,8 @@ in { ++ (config.jupyterlab.jupyterlabEnvArgs.extraPackages ps); }; + notebookConfig = config.jupyterlab.notebookConfig; + runtimePackages = config.jupyterlab.runtimePackages ++ (lib.optionals (enabledLanguage "haskell" "lsp") [ diff --git a/template/lsp.nix b/template/lsp.nix new file mode 100644 index 00000000..222238cb --- /dev/null +++ b/template/lsp.nix @@ -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"; + }; +}