depot/pkgs/applications/editors/jupyter/kernel.nix
Luke Granger-Brown 57725ef3ec Squashed 'third_party/nixpkgs/' content from commit 76612b17c0ce
git-subtree-dir: third_party/nixpkgs
git-subtree-split: 76612b17c0ce71689921ca12d9ffdc9c23ce40b2
2024-11-10 23:59:47 +00:00

70 lines
2.1 KiB
Nix

{ lib, stdenv, python3}:
let
default = {
python3 = let
env = (python3.withPackages (ps: with ps; [ 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";
};
};
in
{
inherit default;
# Definitions is an attribute set.
create = { definitions ? default }: stdenv.mkDerivation {
name = "jupyter-kernels";
src = "/dev/null";
unpackCmd = "mkdir jupyter_kernels";
installPhase = ''
mkdir kernels
${lib.concatStringsSep "\n" (lib.mapAttrsToList (kernelName: unfilteredKernel:
let
allowedKernelKeys = ["argv" "displayName" "language" "interruptMode" "env" "metadata" "logo32" "logo64" "extraPaths"];
kernel = lib.filterAttrs (n: v: (lib.any (x: x == n) allowedKernelKeys)) unfilteredKernel;
config = builtins.toJSON (
kernel
// {display_name = if (kernel.displayName != "") then kernel.displayName else kernelName;}
// (lib.optionalAttrs (kernel ? interruptMode) { interrupt_mode = kernel.interruptMode; })
);
extraPaths = kernel.extraPaths or {}
// lib.optionalAttrs (kernel.logo32 != null) { "logo-32x32.png" = kernel.logo32; }
// lib.optionalAttrs (kernel.logo64 != null) { "logo-64x64.png" = kernel.logo64; }
;
linkExtraPaths = lib.mapAttrsToList (name: value: "ln -s ${value} 'kernels/${kernelName}/${name}';") extraPaths;
in ''
mkdir 'kernels/${kernelName}';
echo '${config}' > 'kernels/${kernelName}/kernel.json';
${lib.concatStringsSep "\n" linkExtraPaths}
'') definitions)}
mkdir $out
cp -r kernels $out
'';
meta = {
description = "Wrapper to create jupyter notebook kernel definitions";
homepage = "https://jupyter.org/";
maintainers = with lib.maintainers; [ aborsu ];
};
};
}