Skip to content

Instantly share code, notes, and snippets.

@bj0
Created October 4, 2021 18:02
Show Gist options
  • Save bj0/aa1ed75920381144781baa669d0ed4c9 to your computer and use it in GitHub Desktop.
Save bj0/aa1ed75920381144781baa669d0ed4c9 to your computer and use it in GitHub Desktop.
Launch a coconut jupyter console using nix
# coconut/default.nix
{ stdenv
, python3
, name ? "nixpkgs"
, packages ? p: []
, pkgs
, pkg ? "coconut"
}:
let
kernelEnv = python3.withPackages ( p: [ p."${pkg}" ]);
kernelFile = {
argv = [
"${kernelEnv.interpreter}"
"-m"
"coconut.icoconut"
"-f"
"{connection_file}"
];
display_name = "Coconut " + name;
language = "coconut";
logo64 = "logo-64x64.svg";
};
icoconut = stdenv.mkDerivation {
name = "icoconut-kernel";
phases = "installPhase";
src = ./coconut.png;
buildInputs = [];
installPhase = ''
mkdir -p $out/kernels/coconut_${name}
cp $src $out/kernels/coconut_${name}/logo-64x64.png
echo '${builtins.toJSON kernelFile}' > $out/kernels/coconut_${name}/kernel.json
'';
};
in
{
spec = icoconut;
runtimePackages = packages pkgs;
}
{ pkgs ? import (fetchTarball https://github.com/nixos/nixpkgs/archive/nixpkgs-unstable.tar.gz) {} }:
let
mach-nix = import (builtins.fetchGit {
url = "https://github.com/DavHau/mach-nix";
ref = "refs/tags/3.3.0";
}) {
# python = "python38";
pypiDataRev = "e747f31df341f0b8fe9bef114043bdc51acbbcaf";
pypiDataSha256 = "0knpr745w8xklklbb915z1084xymy0w1vi9hz9ss56hii70v4wrg";
};
jupyter = import (builtins.fetchGit {
url = https://github.com/tweag/jupyterWith;
}) {};
# make a python with updated coconut
mnPython = mach-nix.mkPython {
requirements = ''
coconut>=1.5.0
'';
ignoreCollisions = true;
};
# create kernel
icoconut = pkgs.callPackage ./coconut {
name = "coconut";
python3 = mnPython.python;
};
# create jupyter environemnt
jupyterEnvironment = jupyter.jupyterlabWith {
kernels = [ icoconut ];
# add console
extraPackages = p: [ p.python3Packages.jupyter_console ];
};
in
jupyterEnvironment.env.overrideAttrs (oldAttrs: {
shellHook = oldAttrs.shellHook + ''
jupyter console --kernel coconut_coconut
'';
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment