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