codedownio / julia2nix

Generate Nix expressions for building a Julia depot with a set of packages
53 stars 6 forks source link

Jupyter support? #21

Closed harris-chris closed 3 years ago

harris-chris commented 3 years ago

Hello - it seems like this is an issue that's possibly been solved already, but I can't get this to work with Jupyter. If I add IJulia to my Project.toml, run julia2nix, then start Julia (with the appropriate build, so as per the instructions), then

julia> using IJulia
julia> notebook()
install Jupyter via conda, y/n? [y]: y
[ Info: Downloading miniconda installer ...
[ Info: Installing miniconda ...
PREFIX=/home/chris/.julia/conda/3
Unpacking payload ...
/home/chris/.julia/conda/3/installer.sh: line 412: /home/chris/.julia/conda/3/conda.exe: No such file or directory
/home/chris/.julia/conda/3/installer.sh: line 414: /home/chris/.julia/conda/3/conda.exe: No such file or directory
ERROR: failed process: Process(`/home/chris/.julia/conda/3/installer.sh -b -f -p /home/chris/.julia/conda/3`, ProcessExited(1)) [1]

It seems like I may need to add Jupyter as a build input to my default.nix or one of the other nix files, so that Conda doesn't try to build it in my home directory, but I'm not proficient enough to figure out exactly where.

Thanks!

thomasjm commented 3 years ago

Hmm, I haven't tried it but how about something like this?

diff --git a/templates/default.nix b/templates/default.nix
index c4fb31c..9c23200 100644
--- a/templates/default.nix
+++ b/templates/default.nix
@@ -14,6 +14,8 @@ let
   # add it here.
   extraLibs = [];

+  python = python3.withPackages (ps: [ ps.jupyter ps.notebook ]);
+
   # Wrapped Julia with libraries and environment variables.
   # Note: setting The PYTHON environment variable is recommended to prevent packages
   # from trying to obtain their own with Conda.
@@ -21,7 +23,7 @@ let
     mkdir -p $out/bin
     makeWrapper ${baseJulia}/bin/julia $out/bin/julia \
                 --suffix LD_LIBRARY_PATH : "${lib.makeLibraryPath extraLibs}" \
-                --set PYTHON ${python3}/bin/python
+                --set PYTHON ${python}/bin/python
   '';

 in
harris-chris commented 3 years ago

Thanks, Thomas. That doesn't seem to work as-is. The crucial bit seems to be in https://github.com/JuliaLang/IJulia.jl/blob/master/src/jupyter.jl - the find_jupyter_subcommand function seems to have a series of fallbacks on where to look for Jupyter. It's late evening here but I'll have a look at it tomorrow and see if I can figure it out.

thomasjm commented 3 years ago

Oh, it looks like it's looking for it on the PATH -- how about this addition:

diff --git a/templates/default.nix b/templates/default.nix
index c4fb31c..cb39e41 100644
--- a/templates/default.nix
+++ b/templates/default.nix
@@ -14,6 +14,8 @@ let
   # add it here.
   extraLibs = [];

+  python = python3.withPackages (ps: [ ps.jupyter ps.notebook ]);
+
   # Wrapped Julia with libraries and environment variables.
   # Note: setting The PYTHON environment variable is recommended to prevent packages
   # from trying to obtain their own with Conda.
@@ -21,7 +23,8 @@ let
     mkdir -p $out/bin
     makeWrapper ${baseJulia}/bin/julia $out/bin/julia \
                 --suffix LD_LIBRARY_PATH : "${lib.makeLibraryPath extraLibs}" \
-                --set PYTHON ${python3}/bin/python
+                --suffix PATH : "${python}/bin" \
+                --set PYTHON ${python}/bin/python
   '';

 in
harris-chris commented 3 years ago

Thanks - that actually works great and is kind of a game-changer for me with Julia and Nix (previously I have been running it in a docker container).