New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/jupyter: init service #33673
nixos/jupyter: init service #33673
Conversation
Related issue: #10713 |
example = "users"; | ||
}; | ||
|
||
password = mkOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to keep this out of the store. Maybe you can point to a path and read that during runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a compromise on that, that I think should be agreeable to all.
type = types.package; | ||
default = (pkgs.python36.withPackages ( | ||
pythonPackages: with pythonPackages; [ | ||
notebook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ipykernel
should be sufficient as the notebook
should already be offered by this service
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, good catch
"python3" = { | ||
name = "Python 3 for Machine Learning"; | ||
env = (pkgs.python36.withPackages (pythonPackages: with pythonPackages; [ | ||
notebook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
I think the logic of creating a |
@FRidh I agree, but it was a bit more work. |
@FRidh @globin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is good to have a separate derivation for the kernel config, and having a new top level item for Jupyter. However, instead of making it a derivation that needs to be overriden, I suggest making jupyter
a function:
kernelDefinitions: { the, other, args }: derivation
, lib | ||
, pkgs | ||
, python3 | ||
, python3Packages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python3
or python3Packages
@@ -0,0 +1,21 @@ | |||
{ stdenv | |||
, lib | |||
, pkgs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no pkgs
python3Packages.buildPythonApplication rec { | ||
inherit (python3Packages.notebook) pname version name src LC_ALL buildInputs propagatedBuildInputs checkPhase doCheck meta; | ||
|
||
makeWrapperArgs = ["--set JUPYTER_PATH ${jupyterPath}"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let
...
in with python3.pkgs; toPythonModule (notebook.override {
makeWrapperArgs = ["--set JUPYTER_PATH ${jupyterPath}"];
});
toPythonModule (buildPythonPackage {...})
is basically the same as buildPythonApplication
. In this case I would go for the former, because the current approach requires keeping up with required attributes.
@@ -0,0 +1,66 @@ | |||
{pkgs, python3, lib, kernelDefinitions ? null }: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No pkgs
@@ -0,0 +1,66 @@ | |||
{pkgs, python3, lib, kernelDefinitions ? null }: | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let
defaultKernelDefinitions = {
...
};
in {python3, lib, kernelDefinitions ? defaultKernelDefinitions }:
let | ||
kernels = if kernelDefinitions != null | ||
then kernelDefinitions | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is then defaultKernelDefinitions
"{connection_file}" | ||
]; | ||
language = "python"; | ||
logo32 = "${env}/lib/python3.6/site-packages/ipykernel/resources/logo-32x32.png"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
env.sitePackages
@FRidh I'm not convinced making the top package jupyter a function is such a great idea.
Even if I give a default argument, the function still needs to be called. It seems to me that override is a standard way of providing customizability to packages and will avoid a lot of pain while imo not reducing understandability or ease of use. As always I'm ready to discuss this further. And thank you for your helpfull corrections. |
@FRidh ping? |
@@ -0,0 +1,16 @@ | |||
{ pkgs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkgs
is not used, adding jupyterKernels
is better
|
||
in | ||
|
||
kernelDefinitions: ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ kernelDefinitions ? defaultKernelDefinitions
}:
in { | ||
displayName = "Python 3"; | ||
argv = [ | ||
"${env}/bin/python" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${env.interpreter}
@@ -0,0 +1,88 @@ | |||
{pkgs, lib}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think pkgs
is used
in | ||
{ | ||
defaultKernelDefinition = defaultKernelDefinition; | ||
create = { kernelDefinitions ? defaultKernelDefinition }: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FRidh I'm not certain this is better.
Now I'm exporting a set instead of exporting a function so I can re-use the default value in all the packages that might use it.
@@ -0,0 +1,16 @@ | |||
{ python3 | |||
, jupyterKernels | |||
, kernelDefinitions ? jupyterKernels.defaultKernelDefinition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is neat.
|
||
|
||
kernels = (pkgs.jupyterKernels.create { | ||
kernelDefinitions = if cfg.kernels != null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've basically had to move the null check here now.
I though of passing the pkgs.jupyterKernels.defaultKernelConfig
as the default value for jupyter.kernels
, but the it complains that it contains a reference to a derivation. (I can understand that having to build a derivation to create the doc is not the greatest).
@FRidh opinion? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compiles and runs basic examples
Mind providing an example of how to get Jupyter installed with these changes? |
Here is my configuration (the password is "test", change it): services.jupyter = {
enable = true;
port = 8123;
notebookDir = "/var/www/jupyter";
password = "'sha1:1b961dc713fb:88483270a63e57d18d43cf337e629539de1436ba'";
}; |
env = (pkgs.python3.withPackages (pythonPackages: with pythonPackages; [ | ||
ipykernel | ||
pandas | ||
scikitlearn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these Jupyter dependencies or just nice to have packages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ipykernel is needed, the others are just basic packages used for data science.
I was thinking of getting something inline with the jupyter dockerimages.
Base python, base data-science, data-science + spark
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the default as minimal as possible.
I plan to draft a sort of RFC issue for Nixpkgs where we could coordinate data science infrastructure work. I would like to provide an overview or stuff related to the Jupyter ecosystem, Python data science ecosystem and Haskell data science ecosystem; perhaps other stuff too, but scoping this is a little tricky, so I think that is an okay start.
I plan to make a script to query nix search (which can return JSONs now) for a package list. datahaskell.org provides a nice overview of interesting Haskell stuff but I would still need to find a decent Python list.
|
@ixxie for python, using the packages used by the jupyter docker images would be a good start https://github.com/jupyter/docker-stacks/tree/master/datascience-notebook |
@aborsu thanks for the tip Sorry everybody about that offtopic-ish post; I didn't realize I could reply to an email in my mail client and it would post to GitHub! |
I have been using this for the last few weeks and it works nicely 👍 |
I got this working on my machine, except setting |
I have set |
@phile314-fh - looks like you did it manually. With @cleverca22's help I managed to resolve this by adding:
and
to @aborsu - its probably easiest if you add it yourself to the PR? |
Hello, sorry, I've been a bit busy. |
@aborsu I think I will soon use this as a template to create a Jupyterlab service and it occurred to me that if that would go in
Alternatively we can have:
or is this a bit awkward? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really have the time to review this any further, so please ask also other maintainers if they can help it forward / get it in.
env = (pkgs.python3.withPackages (pythonPackages: with pythonPackages; [ | ||
ipykernel | ||
pandas | ||
scikitlearn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the default as minimal as possible.
|
||
wantedBy = [ "multi-user.target" ]; | ||
|
||
path = [ pkgs.bash ]; # needed for sh in cell magic to work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered patching notebook
to hardcode bash
?
|
||
let | ||
|
||
jupyterPath = (jupyterKernels.create { kernelDefinitions = kernelDefinitions; }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inherit / space
argv = mkOption { | ||
type = types.listOf types.str; | ||
example = [ | ||
"{customEnv}/bin/python" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${customEnv.interpreter}
logo32 = mkOption { | ||
type = types.nullOr types.path; | ||
default = null; | ||
example = "{env}/lib/python3.6/site-packages/ipykernel/resources/logo-32x32.png"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${env.sitePackages}
in | ||
|
||
with python3.pkgs; toPythonModule ( | ||
notebook.overrideAttrs(oldAttrs: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overridePythonAttrs
@@ -0,0 +1,76 @@ | |||
{ lib, pkgs, stdenv}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no pkgs
, but python3
meta = { | ||
description = "Wrapper to create jupyter notebook kernel definitions"; | ||
homepage = http://jupyter.org/; | ||
# NIXOS license as this is a nixos meta package. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need
|
||
src = "/dev/null"; | ||
|
||
unpackCmd ="mkdir jupyter_kernels"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space
|
||
unpackCmd ="mkdir jupyter_kernels"; | ||
|
||
installPhase = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space
@dotlambda perhaps you have time to have a look? |
Not until Sunday or even next week, sadly. |
I was wondering if you could provide a sequence of recent PRs some context and have a Nixpkgs data science workgroup so I made a data science workgroup page on the wiki and #nixos-data on freenode. |
@ixxie Please fix the things FRidh mentioned. I'll then take a look. However, I've never worked with Jupyter on NixOS so I might need some time to read through it. |
@dotlambda well this is @aborsu's PR really and I believe he is on it; if he doesn't have time eventually I can take over, but this is great work and I would hate to steal the credit ;) I am working on the Jupyterlab module (no PR for that yet). |
Really looking forward to this. Keep up the good work @aborsu :D |
I've made some minor changes and pushed to master 4d3ce5c. |
I'll try to give some feedback on the feature, has anyone tried it with an haskell kernel already ? |
In #51030 I add jupyter support for sage. I've added it so that |
Motivation for this change
I believe that having a configurable service for jupyter with a template to write new kernels is a wanted feature.
cfr
https://www.reddit.com/r/NixOS/comments/7oujo4/getting_all_the_jupyter_kernels/
#10713
Things done
build-use-sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)This pull requests brings a jupyter service to nixos.
It contains a default bare python3 kernel and a literal example on how to define multiple kernels.