I am trying to get a persistent jupyterhub/lab up and running on nixos. I have made progress, but stuck on two items. First, is it possible in the approach I am using to add jupyterlab extensions declaratively? I saw that its possible if I build specific shells and do my coding only inside those purpose built shells, but I would rather not take that approach. Second, while I got a python env up and running with some basic data science packages to try out, I can’t get an R environment to work. Console won’t connect to the kernel, even after multiple attempts and trying to build the env and the argv different ways, including finding and using the full path to the R bin. Pasting my code below, if anyone has pointers who may have tried this. Thanks!
Im pretty sure absolute paths to the nix store dont work. Maybe you should use ${pkgs.R}/bin/R instead of "/nix/store/pqynpqccbr41zz3pg844qiq2h87mxhwx-R-4.3.2-wrapper/bin/R"
I was able to get the R environment to load by using {env}/bin/R. So this is partially solved. One remaining challenge is loading non-python packages in the underlying jupyterhub/lab environment. Jupyterlab-git needs regular git installed, which it obviously is on the base system, but the jupyterhub/lab environment for some reason can’t see it. I must need to load it into the hub/lab environment. They are built like this:
extraPathsFrom does not seem to have the semantics I assumed, while using symlinkJoin I can build a derivation that has “both” the jupyter environment and git in the derivation’s bin folder:
pkgs.symlinkJoin { name = "myjupyterlab"; paths = [ pkgs.git (pkgs.python3.withPackages(p: with p; [ jupyterlab ])) ]; }
I cannot really test with jupyterhub service though as I always get server error 500 even with ‘dummy’ authenticator.
That doesn’t work either. I have a feeling this is a path issue with python3Packages.jupyterlab-git, as it has git in propagatedBuildInputs but it can’t find it.
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: [W 2025-03-08 12:32:25.562 ServerApp.jupyterlab_git] Fail to execute ['git', '--version']
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: Traceback (most recent call last):
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: File "/nix/store/52x0mssdlyw4diwr0bf6y3ki9h7n76lq-python3-3.12.8-env/lib/python3.12/site-packages/jupyterlab_git/git.py", line 189, in execute
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: code, output, error = await current_loop.run_in_executor(
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: File "/nix/store/qrc496n6fsqp4p5m5h8wmw5d5jwyw5mr-python3-3.12.8/lib/python3.12/concurrent/futures/thread.py", line 59, in run
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: result = self.fn(*self.args, **self.kwargs)
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: File "/nix/store/52x0mssdlyw4diwr0bf6y3ki9h7n76lq-python3-3.12.8-env/lib/python3.12/site-packages/jupyterlab_git/git.py", line 150, in call_subprocess
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: process = subprocess.Popen(
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: ^^^^^^^^^^^^^^^^^
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: File "/nix/store/qrc496n6fsqp4p5m5h8wmw5d5jwyw5mr-python3-3.12.8/lib/python3.12/subprocess.py", line 1026, in __init__
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: self._execute_child(args, executable, preexec_fn, close_fds,
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: File "/nix/store/qrc496n6fsqp4p5m5h8wmw5d5jwyw5mr-python3-3.12.8/lib/python3.12/subprocess.py", line 1955, in _execute_child
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: raise child_exception_type(errno_num, err_msg, err_filename)
Mar 08 12:32:25 itxserve jupyterhub-singleuser[592512]: FileNotFoundError: [Errno 2] No such file or directory: 'git'
jupyterlab-git is being called from inside the python3.withPackages env, but I need it to be kinda in the next level up in the regular buildEnv so it can see git
Just wanted to provide an example of a complete working R kernel configuration, as the one above is incomplete:
R = let
env = (pkgs.rWrapper.override {
packages = with pkgs.rPackages; [
IRkernel
tidyverse
purrr
];
});
in {
displayName = "R Example";
argv = [
"${env}/bin/R"
"--slave"
"-e"
"IRkernel::main()"
"--args"
"{connection_file}"
];
language = "R";
logo64 = "${pkgs.rPackages.IRkernel}/library/IRkernel/kernelspec/logo-64x64.png";
};
I also couldn’t login with my local account’s username and password with the default PAM authentication for some reason. As in my case it is exclusively for local use I set the authentication to dummy based on the jupyterhub docs Authenticators — JupyterHub documentation for authenticators, and the host to localhost to be safe even tough I don’t have port 8000 open on my firewall:
host = "127.0.0.1"; # default is 0.0.0.0
authentication = "jupyterhub.auth.DummyAuthenticator";