about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/editors/jupyter-kernels
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/applications/editors/jupyter-kernels')
-rw-r--r--nixpkgs/pkgs/applications/editors/jupyter-kernels/coq/default.nix58
-rw-r--r--nixpkgs/pkgs/applications/editors/jupyter-kernels/coq/kernel.nix30
-rw-r--r--nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/0001-Fix-bug-in-extract_filename.patch50
-rw-r--r--nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/0002-Don-t-pass-extra-includes-configure-this-with-flags.patch34
-rw-r--r--nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/default.nix63
-rw-r--r--nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/xeus-cling.nix87
6 files changed, 322 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/applications/editors/jupyter-kernels/coq/default.nix b/nixpkgs/pkgs/applications/editors/jupyter-kernels/coq/default.nix
new file mode 100644
index 000000000000..545c4e8ec4e8
--- /dev/null
+++ b/nixpkgs/pkgs/applications/editors/jupyter-kernels/coq/default.nix
@@ -0,0 +1,58 @@
+{ lib
+, stdenv
+, callPackage
+, runCommand
+, makeWrapper
+, coq
+, imagemagick
+, python3
+}:
+
+# Jupyter console:
+# nix run --impure --expr 'with import <nixpkgs> {}; jupyter-console.withSingleKernel coq-kernel.definition'
+
+# Jupyter console with packages:
+# nix run --impure --expr 'with import <nixpkgs> {}; jupyter-console.withSingleKernel (coq-kernel.definitionWithPackages [coqPackages.bignums])'
+
+# Jupyter notebook:
+# nix run --impure --expr 'with import <nixpkgs> {}; jupyter.override { definitions.coq = coq-kernel.definition; }'
+
+let
+  python = python3.withPackages (ps: [ ps.traitlets ps.jupyter_core ps.ipykernel (callPackage ./kernel.nix {}) ]);
+
+  logos = runCommand "coq-logos" { buildInputs = [ imagemagick ]; } ''
+    mkdir -p $out
+    convert ${coq.src}/ide/coqide/coq.png -resize 32x32 $out/logo-32x32.png
+    convert ${coq.src}/ide/coqide/coq.png -resize 64x64 $out/logo-64x64.png
+  '';
+
+in
+
+rec {
+  launcher = runCommand "coq-kernel-launcher" {
+    nativeBuildInputs = [ makeWrapper ];
+  } ''
+    mkdir -p $out/bin
+
+    makeWrapper ${python.interpreter} $out/bin/coq-kernel \
+      --add-flags "-m coq_jupyter" \
+      --suffix PATH : ${coq}/bin
+  '';
+
+  definition = definitionWithPackages [];
+
+  definitionWithPackages = packages: {
+    displayName = "Coq " + coq.version;
+    argv = [
+      "${launcher}/bin/coq-kernel"
+      "-f"
+      "{connection_file}"
+    ];
+    language = "coq";
+    logo32 = "${logos}/logo-32x32.png";
+    logo64 = "${logos}/logo-64x64.png";
+    env = {
+      COQPATH = lib.concatStringsSep ":" (map (x: "${x}/lib/coq/${coq.coq-version}/user-contrib/") packages);
+    };
+  };
+}
diff --git a/nixpkgs/pkgs/applications/editors/jupyter-kernels/coq/kernel.nix b/nixpkgs/pkgs/applications/editors/jupyter-kernels/coq/kernel.nix
new file mode 100644
index 000000000000..78bf84716fef
--- /dev/null
+++ b/nixpkgs/pkgs/applications/editors/jupyter-kernels/coq/kernel.nix
@@ -0,0 +1,30 @@
+{ lib
+, fetchFromGitHub
+, python3
+, coq
+}:
+
+python3.pkgs.buildPythonPackage rec {
+  pname = "coq-jupyter";
+  version = "1.6.0";
+
+  src = fetchFromGitHub {
+    owner = "EugeneLoy";
+    repo = "coq_jupyter";
+    rev = "v${version}";
+    sha256 = "sha256-+Pp51cxeqjg5MW4CEccNWVjNcY9iyFNATIEage9RWJ0=";
+  };
+
+  propagatedBuildInputs = (with python3.pkgs; [ ipykernel future ]) ++ [ coq ];
+
+  nativeBuildInputs = [ coq ];
+
+  doCheck = false;
+
+  meta = with lib; {
+    homepage = "https://github.com/EugeneLoy/coq_jupyter";
+    description = "Jupyter kernel for Coq";
+    license = licenses.asl20;
+    maintainers = with maintainers; [ thomasjm ];
+  };
+}
diff --git a/nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/0001-Fix-bug-in-extract_filename.patch b/nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/0001-Fix-bug-in-extract_filename.patch
new file mode 100644
index 000000000000..dac0825b01a1
--- /dev/null
+++ b/nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/0001-Fix-bug-in-extract_filename.patch
@@ -0,0 +1,50 @@
+From 8bfa594bc37630956f80496106bb1d6070035570 Mon Sep 17 00:00:00 2001
+From: thomasjm <tom@codedown.io>
+Date: Wed, 2 Aug 2023 18:26:58 -0700
+Subject: [PATCH 1/3] Fix bug in extract_filename
+
+---
+ src/main.cpp | 12 ++++++------
+ 1 file changed, 6 insertions(+), 6 deletions(-)
+
+diff --git a/src/main.cpp b/src/main.cpp
+index 2ee19be..57294b4 100644
+--- a/src/main.cpp
++++ b/src/main.cpp
+@@ -61,19 +61,19 @@ bool should_print_version(int argc, char* argv[])
+     return false;
+ }
+ 
+-std::string extract_filename(int argc, char* argv[])
++std::string extract_filename(int *argc, char* argv[])
+ {
+     std::string res = "";
+-    for (int i = 0; i < argc; ++i)
++    for (int i = 0; i < *argc; ++i)
+     {
+-        if ((std::string(argv[i]) == "-f") && (i + 1 < argc))
++        if ((std::string(argv[i]) == "-f") && (i + 1 < *argc))
+         {
+             res = argv[i + 1];
+-            for (int j = i; j < argc - 2; ++j)
++            for (int j = i; j < *argc - 2; ++j)
+             {
+                 argv[j] = argv[j + 2];
+             }
+-            argc -= 2;
++            *argc -= 2;
+             break;
+         }
+     }
+@@ -128,7 +128,7 @@ int main(int argc, char* argv[])
+ #endif
+     signal(SIGINT, stop_handler);
+ 
+-    std::string file_name = extract_filename(argc, argv);
++    std::string file_name = extract_filename(&argc, argv);
+ 
+     interpreter_ptr interpreter = build_interpreter(argc, argv);
+ 
+-- 
+2.40.1
+
diff --git a/nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/0002-Don-t-pass-extra-includes-configure-this-with-flags.patch b/nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/0002-Don-t-pass-extra-includes-configure-this-with-flags.patch
new file mode 100644
index 000000000000..c07e57dfe85d
--- /dev/null
+++ b/nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/0002-Don-t-pass-extra-includes-configure-this-with-flags.patch
@@ -0,0 +1,34 @@
+From 9e6a14bb20567071883563dafb5dfaf512df6243 Mon Sep 17 00:00:00 2001
+From: thomasjm <tom@codedown.io>
+Date: Wed, 2 Aug 2023 18:27:16 -0700
+Subject: [PATCH 2/3] Don't pass extra includes; configure this with flags
+
+---
+ src/main.cpp | 4 +---
+ 1 file changed, 1 insertion(+), 3 deletions(-)
+
+diff --git a/src/main.cpp b/src/main.cpp
+index 57294b4..0041a55 100644
+--- a/src/main.cpp
++++ b/src/main.cpp
+@@ -84,7 +84,7 @@ using interpreter_ptr = std::unique_ptr<xcpp::interpreter>;
+ 
+ interpreter_ptr build_interpreter(int argc, char** argv)
+ {
+-    int interpreter_argc = argc + 1;
++    int interpreter_argc = argc;
+     const char** interpreter_argv = new const char*[interpreter_argc];
+     interpreter_argv[0] = "xeus-cling";
+     // Copy all arguments in the new array excepting the process name.
+@@ -92,8 +92,6 @@ interpreter_ptr build_interpreter(int argc, char** argv)
+     {
+         interpreter_argv[i] = argv[i];
+     }
+-    std::string include_dir = std::string(LLVM_DIR) + std::string("/include");
+-    interpreter_argv[interpreter_argc - 1] = include_dir.c_str();
+ 
+     interpreter_ptr interp_ptr = interpreter_ptr(new xcpp::interpreter(interpreter_argc, interpreter_argv));
+     delete[] interpreter_argv;
+-- 
+2.40.1
+
diff --git a/nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/default.nix b/nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/default.nix
new file mode 100644
index 000000000000..069e70b4253f
--- /dev/null
+++ b/nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/default.nix
@@ -0,0 +1,63 @@
+{ callPackage
+, clangStdenv
+, cling
+, fetchurl
+, lib
+, llvmPackages_9
+, makeWrapper
+, runCommand
+, stdenv
+}:
+
+# Jupyter console:
+# nix run --impure --expr 'with import <nixpkgs> {}; jupyter-console.withSingleKernel cpp17-kernel'
+
+# Jupyter notebook:
+# nix run --impure --expr 'with import <nixpkgs> {}; jupyter.override { definitions = { cpp17 = cpp17-kernel; }; }'
+
+let
+  xeus-cling = callPackage ./xeus-cling.nix {};
+
+  mkDefinition = std:
+    let
+      versionSuffix =
+        if std == "c++11" then " 11"
+        else if std == "c++14" then " 14"
+        else if std == "c++17" then " 17"
+        else if std == "c++17" then " 17"
+        else if std == "c++2a" then " 2a"
+        else throw "Unexpected C++ std for cling: ${std}";
+    in
+      {
+        displayName = "C++" + versionSuffix;
+        argv = [
+          "${xeus-cling}/bin/xcpp"
+        ]
+        ++ cling.flags
+        ++ [
+          "-resource-dir" "${cling.unwrapped}"
+          "-L" "${cling.unwrapped}/lib"
+          "-l" "${cling.unwrapped}/lib/cling.so"
+          "-std=${std}"
+          # "-v"
+          "-f" "{connection_file}"
+        ];
+        language = "cpp";
+        logo32 = fetchurl {
+          url = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/ISO_C%2B%2B_Logo.svg/32px-ISO_C%2B%2B_Logo.svg.png";
+          hash = "sha256-cr0TB8/j2mkcFhfCkz9F7ZANOuTlWA2OcWtDcXyOjHw=";
+        };
+        logo64 = fetchurl {
+          url = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/ISO_C%2B%2B_Logo.svg/64px-ISO_C%2B%2B_Logo.svg.png";
+          hash = "sha256-nZtJ4bR7GmQttvqEJC9KejOxphrjjxT36L9yOIITFLk=";
+        };
+      };
+
+in
+
+{
+  cpp11-kernel = mkDefinition "c++11";
+  cpp14-kernel = mkDefinition "c++14";
+  cpp17-kernel = mkDefinition "c++17";
+  cpp2a-kernel = mkDefinition "c++2a";
+}
diff --git a/nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/xeus-cling.nix b/nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/xeus-cling.nix
new file mode 100644
index 000000000000..f223043ca3b6
--- /dev/null
+++ b/nixpkgs/pkgs/applications/editors/jupyter-kernels/xeus-cling/xeus-cling.nix
@@ -0,0 +1,87 @@
+{ lib
+, callPackage
+, clangStdenv
+, cmake
+, fetchFromGitHub
+, gcc
+, git
+, llvmPackages_9
+# Libraries
+, argparse
+, cling
+, cppzmq
+, libuuid
+, ncurses
+, openssl
+, pugixml
+, xeus
+, xeus-zmq
+, xtl
+, zeromq
+, zlib
+# Settings
+, debug ? false
+}:
+
+let
+  # Nixpkgs moved to argparse 3.x, but we need ~2.9
+  argparse_2_9 = argparse.overrideAttrs (oldAttrs: {
+    version = "2.9";
+
+    src = fetchFromGitHub {
+      owner = "p-ranav";
+      repo = "argparse";
+      rev = "v2.9";
+      sha256 = "sha256-vbf4kePi5gfg9ub4aP1cCK1jtiA65bUS9+5Ghgvxt/E=";
+    };
+  });
+
+in
+
+clangStdenv.mkDerivation rec {
+  pname = "xeus-cling";
+  version = "0.15.3";
+
+  src = fetchFromGitHub {
+    owner = "QuantStack";
+    repo = "xeus-cling";
+    rev = "${version}";
+    hash = "sha256-OfZU+z+p3/a36GntusBfwfFu3ssJW4Fu7SV3SMCoo1I=";
+  };
+
+  patches = [
+    ./0001-Fix-bug-in-extract_filename.patch
+    ./0002-Don-t-pass-extra-includes-configure-this-with-flags.patch
+  ];
+
+  nativeBuildInputs = [ cmake ];
+  buildInputs = [
+    argparse_2_9
+    cling.unwrapped
+    cppzmq
+    libuuid
+    llvmPackages_9.llvm
+    ncurses
+    openssl
+    pugixml
+    xeus
+    xeus-zmq
+    xtl
+    zeromq
+    zlib
+  ];
+
+  cmakeFlags = lib.optionals debug [
+    "-DCMAKE_BUILD_TYPE=Debug"
+  ];
+
+  dontStrip = debug;
+
+  meta = {
+    description = "Jupyter kernel for the C++ programming language";
+    homepage = "https://github.com/jupyter-xeus/xeus-cling";
+    maintainers = with lib.maintainers; [ thomasjm ];
+    platforms = lib.platforms.unix;
+    license = lib.licenses.mit;
+  };
+}