2018-01-21 18:11:33 +00:00
|
|
|
{ lib, stdenv, python3}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
default = {
|
|
|
|
python3 = let
|
|
|
|
env = (python3.withPackages (ps: with ps; [ ipykernel ]));
|
|
|
|
in {
|
|
|
|
displayName = "Python 3";
|
|
|
|
argv = [
|
2019-09-08 23:38:31 +00:00
|
|
|
env.interpreter
|
2018-01-21 18:11:33 +00:00
|
|
|
"-m"
|
|
|
|
"ipykernel_launcher"
|
|
|
|
"-f"
|
|
|
|
"{connection_file}"
|
|
|
|
];
|
|
|
|
language = "python";
|
2021-08-19 20:02:22 +00:00
|
|
|
logo32 = "${env}/${env.sitePackages}/ipykernel/resources/logo-32x32.png";
|
|
|
|
logo64 = "${env}/${env.sitePackages}/ipykernel/resources/logo-64x64.png";
|
2018-01-21 18:11:33 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
inherit default;
|
|
|
|
|
|
|
|
# Definitions is an attribute set.
|
|
|
|
|
2024-08-16 17:07:42 +00:00
|
|
|
create = { definitions ? default }: stdenv.mkDerivation {
|
2018-01-21 18:11:33 +00:00
|
|
|
|
|
|
|
name = "jupyter-kernels";
|
|
|
|
|
|
|
|
src = "/dev/null";
|
|
|
|
|
|
|
|
unpackCmd = "mkdir jupyter_kernels";
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir kernels
|
|
|
|
|
2024-08-16 17:07:42 +00:00
|
|
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList (kernelName: unfilteredKernel:
|
2018-01-21 18:11:33 +00:00
|
|
|
let
|
2022-03-13 21:44:08 +00:00
|
|
|
allowedKernelKeys = ["argv" "displayName" "language" "interruptMode" "env" "metadata" "logo32" "logo64" "extraPaths"];
|
2024-08-16 17:07:42 +00:00
|
|
|
kernel = lib.filterAttrs (n: v: (lib.any (x: x == n) allowedKernelKeys)) unfilteredKernel;
|
2019-07-11 08:29:36 +00:00
|
|
|
config = builtins.toJSON (
|
|
|
|
kernel
|
|
|
|
// {display_name = if (kernel.displayName != "") then kernel.displayName else kernelName;}
|
2024-08-16 17:07:42 +00:00
|
|
|
// (lib.optionalAttrs (kernel ? interruptMode) { interrupt_mode = kernel.interruptMode; })
|
2019-07-11 08:29:36 +00:00
|
|
|
);
|
2022-03-13 21:44:08 +00:00
|
|
|
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;
|
2018-01-21 18:11:33 +00:00
|
|
|
in ''
|
|
|
|
mkdir 'kernels/${kernelName}';
|
|
|
|
echo '${config}' > 'kernels/${kernelName}/kernel.json';
|
2022-03-13 21:44:08 +00:00
|
|
|
${lib.concatStringsSep "\n" linkExtraPaths}
|
2018-01-21 18:11:33 +00:00
|
|
|
'') definitions)}
|
|
|
|
|
|
|
|
mkdir $out
|
|
|
|
cp -r kernels $out
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "Wrapper to create jupyter notebook kernel definitions";
|
2020-04-01 01:11:51 +00:00
|
|
|
homepage = "https://jupyter.org/";
|
2024-08-16 17:07:42 +00:00
|
|
|
maintainers = with lib.maintainers; [ aborsu ];
|
2018-01-21 18:11:33 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|