-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
jupyter.lib: init #278315
Open
teto
wants to merge
5
commits into
NixOS:master
Choose a base branch
from
teto:jupyter-lib
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
jupyter.lib: init #278315
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# jupyter {#sec-jupyter} | ||
|
||
Jupyter has different frontends that can be configured: jupyter-console and | ||
jupyter-notebook. The approach is the same: | ||
1. create a folder that contains all the jupyter kernels | ||
2. wrap the executables | ||
|
||
```nix | ||
let | ||
definitions = { | ||
python = jupyterLib.mkKernelFromPythonEnv (python3.withPackages(ps: [ | ||
ps.numpy ]); | ||
haskell = jupyterLib.mkKernelFromHaskellEnv (pkgs.haskellPackages.ghcWithPackages(hs: [ hs.aeson | ||
]); | ||
# ... and all other kernels you are interested in | ||
}; | ||
myKernels = jupyter-kernel.create { | ||
inherit definitions; | ||
}; | ||
in | ||
# pseudocode, real code in next sections | ||
jupyter frontend wrapped with JUPYTER_PATH=myKernels | ||
``` | ||
|
||
|
||
## How to run jupyter-console with arbitrary kernels ? {#sec-jupyter-console} | ||
|
||
```nix | ||
myJupyterConsole = jupyter-console.mkConsole { | ||
inherit definitions; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ jupyter-kernel, python3, lib, ...}: | ||
{ | ||
/* Generates a kernel definition from a haskell environment | ||
|
||
Example: | ||
let ghcEnv = pkgs.haskellPackages.ghcWithPackages (p: [ p.aeson ]); | ||
in mkKernelFromHaskellEnv ghcEnv; | ||
|
||
Type: | ||
mkKernelFromHaskellEnv :: Derivation -> AttrSet | ||
*/ | ||
mkKernelFromHaskellEnv = ghcEnv: | ||
let | ||
ghcEnv' = ghcEnv.withPackages (p: [ p.ihaskell ]); | ||
in | ||
|
||
{ | ||
displayName = "Haskell"; | ||
argv = [ | ||
"${ghcEnv'}/bin/ihaskell" | ||
"-l" | ||
# the ihaskell flake does `-l $(${env}/bin/ghc --print-libdir` | ||
# we guess the path via hardcoded | ||
# we can't use name else we get the 'with-packages' suffix | ||
"${ghcEnv}/lib/ghc-${ghcEnv.version}" | ||
"kernel" | ||
"{connection_file}" | ||
]; | ||
language = "haskell"; | ||
logo32 = null; | ||
logo64 = null; | ||
}; | ||
|
||
|
||
/* Generates a kernel definition from a python environment | ||
Example: | ||
let pyEnv = pkgs.python3.withPackages (p: [ p.numpy ]); | ||
in mkKernelFromPythonEnv pyEnv; | ||
|
||
Type: | ||
mkKernelFromPythonEnv :: Derivation -> AttrSet | ||
*/ | ||
mkKernelFromPythonEnv = env: let | ||
env' = env.override(prev: { | ||
# fastai | ||
extraLibs = prev.extraLibs ++ [ env.python.pkgs.ipykernel ]; | ||
}); | ||
|
||
in | ||
{ | ||
displayName = "Python 3"; | ||
argv = [ | ||
env'.interpreter | ||
"-m" | ||
"ipykernel_launcher" | ||
"-f" | ||
"{connection_file}" | ||
]; | ||
language = "python"; | ||
logo32 = "${env}/${env.sitePackages}/ipykernel/resources/logo-32x32.png"; | ||
logo64 = "${env}/${env.sitePackages}/ipykernel/resources/logo-64x64.png"; | ||
}; | ||
|
||
mkConsole = { | ||
definitions ? jupyter-kernel.default | ||
, kernel ? null | ||
}: | ||
(python3.buildEnv.override { | ||
extraLibs = [ python3.pkgs.jupyter-console ]; | ||
makeWrapperArgs = [ | ||
"--set JUPYTER_PATH ${jupyter-kernel.create { inherit definitions; }}" | ||
] ++ lib.optionals (kernel != null) [ | ||
"--add-flags --kernel" | ||
"--add-flags ${kernel}" | ||
]; | ||
}).overrideAttrs (oldAttrs: { | ||
# To facilitate running nix run .#jupyter-console | ||
meta = oldAttrs.meta // { mainProgram = "jupyter-console"; }; | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ pkgs }: | ||
{ | ||
jupyter-all = pkgs.jupyter.override { | ||
definitions = { | ||
clojure = pkgs.clojupyter.definition; | ||
octave = pkgs.octave-kernel.definition; | ||
# wolfram = wolfram-for-jupyter-kernel.definition; # unfree | ||
}; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'd expect to have 1 file per kernel. And perhaps not constructing raw Jupyter kernelspecs like this, because then we have to worry about making sure they're all valid. IIRC there is currently some machinery in Nixpkgs for constructing these with some type safety.
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.
ok
there is in nixos/modules/services/development/jupyter/./kernel-options.nix. It's possible to use those outside of the module but it's not trivial IMO. It can be added transparently later.