templates/jupyter/flake.nix

68 lines
2.3 KiB
Nix
Raw Normal View History

2023-10-13 15:57:53 +02:00
{
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.
2023-10-15 11:15:04 +02:00
tikz-among-us; # extra packages
2023-10-13 15:57:53 +02:00
};
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";
2023-10-13 17:09:55 +02:00
unpackPhase = ": 3"; # we don't have any sources
2023-10-13 15:57:53 +02:00
nativeBuildInputs = [ (python.withPackages (ps: with ps; [ jupyter jupyter-core ])) ];
2023-10-13 17:09:55 +02:00
# for some reason, ihaskell wants to create $HOME/.ihaskell
# we set $HOME to $out, and then remove the .ihaskell file
installPhase = ''
2023-10-13 15:57:53 +02:00
mkdir -p $out
HOME=$out ${pkgs.ihaskell}/bin/ihaskell install --prefix=$out
2023-10-13 17:09:55 +02:00
rm -rf $out/.ihaskell
2023-10-13 15:57:53 +02:00
'';
};
python-environment = (pkgs.python310.withPackages (ps: with ps; [
2023-10-15 11:15:04 +02:00
ipympl numpy matplotlib scipy
2023-10-13 15:57:53 +02:00
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:${pkgs.pandoc}/bin ${python-environment}/bin/jupyter-notebook
2023-10-13 15:57:53 +02:00
'';
devShells.default = pkgs.mkShell {
packages = [ python-environment latex ];
};
}
);
}