nixpkgs/pkgs/applications/editors/jupyter/kernel.nix

71 lines
2.1 KiB
Nix
Raw Normal View History

{ 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
"-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.
2019-08-13 21:52:01 +00:00
create = { definitions ? default }: with lib; stdenv.mkDerivation {
name = "jupyter-kernels";
src = "/dev/null";
unpackCmd = "mkdir jupyter_kernels";
installPhase = ''
mkdir kernels
${concatStringsSep "\n" (mapAttrsToList (kernelName: unfilteredKernel:
let
2022-03-13 21:44:08 +00:00
allowedKernelKeys = ["argv" "displayName" "language" "interruptMode" "env" "metadata" "logo32" "logo64" "extraPaths"];
kernel = filterAttrs (n: v: (any (x: x == n) allowedKernelKeys)) unfilteredKernel;
config = builtins.toJSON (
kernel
// {display_name = if (kernel.displayName != "") then kernel.displayName else kernelName;}
// (optionalAttrs (kernel ? interruptMode) { interrupt_mode = kernel.interruptMode; })
);
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;
in ''
mkdir 'kernels/${kernelName}';
echo '${config}' > 'kernels/${kernelName}/kernel.json';
2022-03-13 21:44:08 +00:00
${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 maintainers; [ aborsu ];
};
};
}