tweag / jupyenv

Declarative and reproducible Jupyter environments - powered by Nix
https://jupyenv.io/
MIT License
651 stars 135 forks source link

[Bug]: "needs to build JupyterLab" loop #421

Closed matejc closed 1 year ago

matejc commented 1 year ago

Current Behavior

Adding to system packages in NixOS, and running any jupyter* command ends with an endless loop.

❯  jupyter-notebook
[2023-02-02 18:28:23 jupyenv] needs to build JupyterLab.
.
.
.
[2023-02-02 18:28:43 jupyenv] needs to build JupyterLab.
[2023-02-02 18:28:45 jupyenv] needs to build JupyterLab.
[2023-02-02 18:28:45 jupyenv] needs to build JupyterLab.
^CTraceback (most recent call last):
  File "/nix/store/q36gakk9j5m01dynl172l7l2lliprr8l-jupyterlab-checker", line 1, in <module>
.
.
.

Expected Behavior

To not loop endlessly and starts listening on 8888 port

Steps To Reproduce

  1. Add to flake as input:
    jupyenv = {
      url = "github:tweag/jupyenv/main";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  2. In the nixosConfigurations for nixpkgs.lib.nixosSystem add under modules:
          {
            environment.systemPackages = [ (inputs.jupyenv.lib."x86_64-linux".mkJupyterlabNew {
              kernel.python.example = {
                enable = true;
              };
            }) ];
          }
  3. rebuild switch the NixOS

OS

- system: `"x86_64-linux"`
 - host os: `Linux 6.1.3, NixOS, 23.05 (Stoat)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.12.0`
 - nixpkgs: `/home/matejc/workarea/nixpkgs`

Version

37c9075875c4d1c1466465afd5e2c3ea1cc50325 (jupyenv/main)

Additional Context

I investigated a bit:

❯  cat /run/current-system/sw/bin/jupyter-notebook
...
❯  cat /nix/store/yrgikb6dd15mhc42rbs2plkm76hf4h3m-wrapper-chmod-python3-3.10.9-env/bin/.jupyter-notebook-wrapped
...
❯  cat /nix/store/f1br1w9s07rx7m47p29mz2svzbc60j4d-jupyterlab-cond-build
...
❯  /nix/store/73i016js78zicy28viiwx2284nrlx5f6-python3-3.10.9-env/bin/jupyter lab build

And come to conclusion that the last command here is the culprit.

Dig a bit further and found out it works if I isolate the environment:

❯  env --ignore-environment /run/current-system/sw/bin/jupyter-notebook

This now starts listening to the 8888 port and I can start python kernel.

Relevant log output

No response

katanallama commented 1 year ago

I experienced the same issue, a quick nix flake update in the directory where the flake is appears to resolve it.

jhhuh commented 1 year ago

I encountered the exact same symptom. In my case, jupyter-lab was in nix develop environment.

It turns out that jupyterlab-cond-build (https://github.com/tweag/jupyenv/blob/main/lib/jupyter.nix#L55) causes an infinite recursive calls to jupyter-lab. Here, the jupyter command dispatches its subcommand from the PATH, and, in our case it is jupyter-lab we installed that starts another jupyterlab-cond-build and so on.

PR #460 fixes this bug, hopefully.