Jupyter flake

This commit is contained in:
xenia 2023-10-13 15:57:53 +02:00
parent 95b23c70b1
commit ae6b9aa1ac
7 changed files with 1305 additions and 0 deletions

View File

@ -17,5 +17,10 @@
description = "Minimal flake for Haskell with nix build system and devshell";
welcomeText = "mjau λλλ";
};
templates.jupyter = {
path = ./haskell;
description = "A jupyter flake, with a custom haskell kernel and proper pdflatex LaTeX export supoprt";
welcomeText = "mjau 🐍🐍🐍";
};
};
}

1
jupyter/.envrc Normal file
View File

@ -0,0 +1 @@
use flake

59
jupyter/flake.lock Normal file
View File

@ -0,0 +1,59 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1697009197,
"narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

63
jupyter/flake.nix Normal file
View File

@ -0,0 +1,63 @@
{
description = "A jupyter flake, with a custom haskell kernel and proper pdflatex LaTeX export supoprt";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (sys:
let pkgs = import nixpkgs { system = sys; };
python = pkgs.python310;
latex = pkgs.texlive.combine {
inherit (pkgs.texlive)
scheme-basic # Base
tcolorbox pgf environ etoolbox pdfcol parskip caption float upquote eurosym ucs fancyvrb grffile adjustbox hyperref titling booktabs enumitem ulem soul rsfs jknapltx cm-super # Other packages needed by jupyter.
tikz-among-us;
};
jupyter-config = python.pkgs.buildPythonPackage rec {
name = "jupyter-config";
format = "other";
src = ./jupyter-config ;
installPhase = ''
find . -type f -exec sed -i 's|<pdflatex>|${latex}/bin/pdflatex|g' {} +
mkdir -p $out/etc/jupyter/
cp -r . $out/etc/jupyter/
'';
};
jupyter-ihaskell = python.pkgs.buildPythonPackage rec {
name = "jupyter-ihaskell";
format = "other";
unpackPhase = ": 3";
nativeBuildInputs = [ (python.withPackages (ps: with ps; [ jupyter jupyter-core ])) ];
# for some reason, ihaskell wants to create $HOME/.ihaskell 3:
buildPhase = ''
mkdir -p $out
HOME=$out ${pkgs.ihaskell}/bin/ihaskell install --prefix=$out
'';
};
python-environment = (pkgs.python310.withPackages (ps: with ps; [
jupyter-core jupyter
jupyter-config jupyter-ihaskell
]));
in rec {
packages.latex = latex;
packages.python-environment = python-environment;
packages.default = pkgs.writeScriptBin "start-notebook" ''
env PATH=$PATH:${latex}/bin ${python-environment}/bin/jupyter-notebook
'';
devShells.default = pkgs.mkShell {
packages = [ python-environment latex ];
};
}
);
}

View File

@ -0,0 +1,19 @@
/* Modify Jupyter Styles */
#top-panel-wrapper,
#jp-top-bar {
background-color: #aecad4 !important;
}
#menu-panel-wrapper,
#jp-MainMenu,
#menu-panel {
background-color: #aecad4 !important;
}
.jp-NotebookPanel-toolbar {
background-color: #aecad4 !important;
}
.lm-MenuBar-content {
color: #02484d;
}

File diff suppressed because it is too large Load Diff

76
jupyter/mjausay.ipynb Normal file
View File

@ -0,0 +1,76 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "482010f0-6af3-4f7b-a34a-3d1319a6f34e",
"metadata": {},
"outputs": [],
"source": [
"data Creature = Cat | Agda | Squid\n",
"instance Show Creature where\n",
" show Cat = \"🐈\"\n",
" show Agda = \"🐓\"\n",
" show Squid = \"🐙\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "622a85aa-ba4a-4b33-98da-ecbd8a1864e7",
"metadata": {},
"outputs": [],
"source": [
"(💬) :: Creature -> String -> String\n",
"creature 💬 mjau = show creature ++ \" 💬 \" ++ mjau"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "191044ab-6288-4d5e-bdaa-89b31a41c0f7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"🐈 💬 mjam"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"putStr $ Cat 💬 \"mjam\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e447529-f4ea-4e77-a9e4-d18326da2030",
"metadata": {},
"outputs": [],
"source": [
"let 9 + 10 = 21 in print (9 "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Haskell",
"language": "haskell",
"name": "haskell"
},
"language_info": {
"codemirror_mode": "ihaskell",
"file_extension": ".hs",
"mimetype": "text/x-haskell",
"name": "haskell",
"pygments_lexer": "Haskell",
"version": "9.4.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}