about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOTABI Tomoya <tomoya.otabi@gmail.com>2023-09-08 17:45:59 +0900
committerGitHub <noreply@github.com>2023-09-08 17:45:59 +0900
commitde26873baa4b59994d5491f4efa90e5716395aec (patch)
tree7a457aa8e302f01aa0d5ff5f6b60be256db3c99e
parente32ca67a2f2a300c5839086481c4087f8c24bea6 (diff)
parent0342a5194b62f5c5375dbae9f065cb33722dc466 (diff)
downloadnixlib-de26873baa4b59994d5491f4efa90e5716395aec.tar
nixlib-de26873baa4b59994d5491f4efa90e5716395aec.tar.gz
nixlib-de26873baa4b59994d5491f4efa90e5716395aec.tar.bz2
nixlib-de26873baa4b59994d5491f4efa90e5716395aec.tar.lz
nixlib-de26873baa4b59994d5491f4efa90e5716395aec.tar.xz
nixlib-de26873baa4b59994d5491f4efa90e5716395aec.tar.zst
nixlib-de26873baa4b59994d5491f4efa90e5716395aec.zip
Merge pull request #245340 from codedownio/jupyter-console
jupyter-console: expose as a tool for launching kernels
-rw-r--r--pkgs/applications/editors/jupyter-kernels/clojupyter/default.nix7
-rw-r--r--pkgs/applications/editors/jupyter-kernels/iruby/default.nix47
-rw-r--r--pkgs/applications/editors/jupyter-kernels/octave/default.nix7
-rw-r--r--pkgs/applications/editors/jupyter-kernels/wolfram/default.nix8
-rw-r--r--pkgs/applications/editors/jupyter/console.nix37
-rw-r--r--pkgs/top-level/all-packages.nix2
6 files changed, 91 insertions, 17 deletions
diff --git a/pkgs/applications/editors/jupyter-kernels/clojupyter/default.nix b/pkgs/applications/editors/jupyter-kernels/clojupyter/default.nix
index 504d41768868..5acca288f963 100644
--- a/pkgs/applications/editors/jupyter-kernels/clojupyter/default.nix
+++ b/pkgs/applications/editors/jupyter-kernels/clojupyter/default.nix
@@ -8,8 +8,11 @@
 , imagemagick
 }:
 
-# To test:
-# $(nix-build --no-out-link -E 'with import <nixpkgs> {}; jupyter.override { definitions = { clojure = clojupyter.definition; }; }')/bin/jupyter-notebook
+# Jupyter console:
+# nix run --impure --expr 'with import <nixpkgs> {}; jupyter-console.withSingleKernel clojupyter.definition'
+
+# Jupyter notebook:
+# nix run --impure --expr 'with import <nixpkgs> {}; jupyter.override { definitions.clojure = clojupyter.definition; }'
 
 let
   cljdeps = import ./deps.nix { inherit pkgs; };
diff --git a/pkgs/applications/editors/jupyter-kernels/iruby/default.nix b/pkgs/applications/editors/jupyter-kernels/iruby/default.nix
index 260a614fe5c0..f456d469ca36 100644
--- a/pkgs/applications/editors/jupyter-kernels/iruby/default.nix
+++ b/pkgs/applications/editors/jupyter-kernels/iruby/default.nix
@@ -2,16 +2,41 @@
 , bundlerApp
 }:
 
-bundlerApp {
-  pname = "iruby";
-  gemdir = ./.;
-  exes = [ "iruby" ];
+# Jupyter console:
+# nix run --impure --expr 'with import <nixpkgs> {}; jupyter-console.withSingleKernel iruby.definition'
 
-  meta = with lib; {
-    description = "Ruby kernel for Jupyter";
-    homepage    = "https://github.com/SciRuby/iruby";
-    license     = licenses.mit;
-    maintainers = [ maintainers.costrouc ];
-    platforms   = platforms.unix;
+# Jupyter notebook:
+# nix run --impure --expr 'with import <nixpkgs> {}; jupyter.override { definitions.iruby = iruby.definition; }'
+
+let
+  self = bundlerApp {
+    pname = "iruby";
+    gemdir = ./.;
+    exes = [ "iruby" ];
+
+    passthru = {
+      definition = {
+        displayName = "IRuby";
+        argv = [
+          "${self}/bin/iruby"
+          "kernel"
+          "{connection_file}"
+        ];
+        language = "ruby";
+        logo32 = null;
+        logo64 = null;
+      };
+    };
+
+    meta = {
+      description = "Ruby kernel for Jupyter";
+      homepage    = "https://github.com/SciRuby/iruby";
+      license     = lib.licenses.mit;
+      maintainers = with lib.maintainers; [ costrouc thomasjm ];
+      platforms   = lib.platforms.unix;
+    };
   };
-}
+
+in
+
+self
diff --git a/pkgs/applications/editors/jupyter-kernels/octave/default.nix b/pkgs/applications/editors/jupyter-kernels/octave/default.nix
index a9770a5c1bef..88bc1b2803bb 100644
--- a/pkgs/applications/editors/jupyter-kernels/octave/default.nix
+++ b/pkgs/applications/editors/jupyter-kernels/octave/default.nix
@@ -7,8 +7,11 @@
 , python3
 }:
 
-# To test:
-# $(nix-build -E 'with import <nixpkgs> {}; jupyter.override { definitions = { octave = octave-kernel.definition; }; }')/bin/jupyter-notebook
+# Jupyter console:
+# nix run --impure --expr 'with import <nixpkgs> {}; jupyter-console.withSingleKernel octave-kernel.definition'
+
+# Jupyter notebook:
+# nix run --impure --expr 'with import <nixpkgs> {}; jupyter.override { definitions.octave = octave-kernel.definition; }'
 
 let
   kernel = callPackage ./kernel.nix {
diff --git a/pkgs/applications/editors/jupyter-kernels/wolfram/default.nix b/pkgs/applications/editors/jupyter-kernels/wolfram/default.nix
index 2d00d6e1fc2e..efa78f74bc96 100644
--- a/pkgs/applications/editors/jupyter-kernels/wolfram/default.nix
+++ b/pkgs/applications/editors/jupyter-kernels/wolfram/default.nix
@@ -2,8 +2,12 @@
 , wolfram-engine
 }:
 
-# To test:
-# $(nix-build -E 'with import ./. {}; jupyter.override { definitions = { wolfram = wolfram-for-jupyter-kernel.definition; }; }')/bin/jupyter-notebook
+# Jupyter console:
+# nix run --impure --expr 'with import <nixpkgs> {}; jupyter-console.withSingleKernel wolfram-for-jupyter-kernel.definition'
+
+# Jupyter notebook:
+# nix run --impure --expr 'with import <nixpkgs> {}; jupyter.override { definitions.wolfram = wolfram-for-jupyter-kernel.definition; }'
+
 let kernel = callPackage ./kernel.nix {};
 in {
   definition = {
diff --git a/pkgs/applications/editors/jupyter/console.nix b/pkgs/applications/editors/jupyter/console.nix
new file mode 100644
index 000000000000..06bc82a1780b
--- /dev/null
+++ b/pkgs/applications/editors/jupyter/console.nix
@@ -0,0 +1,37 @@
+{ python3
+, jupyter-kernel
+, lib
+}:
+
+let
+  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"; };
+    });
+
+in
+
+{
+  # Build a console derivation with an arbitrary set of definitions, and an optional kernel to use.
+  # If the kernel argument is not supplied, Jupyter console will pick a kernel to run from the ones
+  # available on the system.
+  inherit mkConsole;
+
+  # An ergonomic way to start a console with a single kernel.
+  withSingleKernel = definition: mkConsole {
+    definitions = lib.listToAttrs [(lib.nameValuePair definition.language definition)];
+    kernel = definition.language;
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 413c1738a557..79f9fd3b51c1 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -9663,6 +9663,8 @@ with pkgs;
     };
   };
 
+  jupyter-console = callPackage ../applications/editors/jupyter/console.nix { };
+
   jupyter-kernel = callPackage ../applications/editors/jupyter/kernel.nix { };
 
   justify = callPackage ../tools/text/justify { };