Created
December 2, 2023 14:35
-
-
Save teto/4d12998d734f982e27f48d8bb001c8ae to your computer and use it in GitHub Desktop.
jupyter flake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
description = "A very basic flake"; | |
inputs = { | |
flake-utils.url = "github:numtide/flake-utils"; | |
# hls.url = "github:haskell/haskell-language-server"; | |
# nixpkgs.url = "github:NixOS/nixpkgs"; | |
nixpkgs.url = "/home/teto/nixpkgs"; | |
# jupyenv.url = "github:tweag/jupyenv"; | |
}; | |
outputs = { self, nixpkgs, flake-utils, ... }: | |
flake-utils.lib.eachSystem [ "x86_64-linux" ] | |
(system: | |
let | |
pkgs = import nixpkgs { | |
inherit system; | |
config = { | |
allowBroken = true; | |
}; | |
overlays = | |
# nixpkgs.lib.attrValues self.inputs.jupyterWith.overlays ++ | |
[ | |
self.overlay | |
]; | |
}; | |
mkPythonKernelDef = env: { | |
displayName = "Python 3"; | |
argv = [ | |
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"; | |
}; | |
# TODO refer to ihaskell functions in the future | |
# Look up ihaskellKernelFileFunc in ihaskell /ihaskellGhcLibFunc | |
mkHaskellKernel = ghcEnv: | |
{ | |
displayName = "Haskell"; | |
argv = [ | |
# TODO check it contains ihaskell ? | |
"${ghcEnv}/bin/ihaskell" | |
"-l" | |
# the ihaskell flake does `-l $(${env}/bin/ghc --print-libdir` | |
# we guess the path via hardcoded | |
# we can't use name else we get the 'with-packages' suffix | |
"${ghcEnv}/lib/ghc-${ghcEnv.version}" | |
"kernel" | |
"{connection_file}" | |
# "--debug" | |
]; | |
language = "haskell"; | |
logo32 = null; | |
logo64 = null; | |
}; | |
in | |
{ | |
devShells.default = | |
let | |
python3PkgsFn = ps: [ | |
ps.numpy | |
ps.scipy | |
ps.matplotlib | |
ps.graphviz | |
ps.tensorflow | |
ps.scikit-learn | |
ps.numpy | |
ps.keras | |
# the kernel launches -m ipykernel_launcher so if you dont add it | |
# you get /nix/store/r4rwxai2g45i3ax51ic7k6flsvhg3yz3-python3-3.11.6-env/bin/python3.11: No module named ipykernel_launcher | |
ps.ipykernel | |
]; | |
pyEnv = pkgs.python3.withPackages(python3PkgsFn); | |
# | |
kernel-definitions = { | |
python3 = mkPythonKernelDef pyEnv; | |
haskell = mkHaskellKernel ghcEnv; | |
}; | |
# creates a folder with kernels/ subpath | |
allKernels = pkgs.jupyter-kernel.create { | |
definitions = kernel-definitions; | |
}; | |
/* for now must contain ihaskell */ | |
ghcEnv = pkgs.haskellPackages.ghcWithPackages (p: [ | |
p.aeson | |
p.ihaskell | |
p.ihaskell-blaze | |
# tensorflow | |
# tensorflow-logging | |
# tensorflow-core-ops | |
# tensorflow-mnist | |
# tensorflow-mnist-input-data | |
# devPkg.env | |
]); | |
/* jupyter console is an attrset of 2 functions | |
*/ | |
jup-console = pkgs.jupyter-console.mkConsole { | |
definitions = kernel-definitions; | |
# why ? | |
kernel = null; | |
}; | |
in | |
pkgs.mkShell { | |
/* dont use the top-level 'jupyter' as it needs to be overriden with proper kernel-definitions | |
*/ | |
# pkgs.jupyter.override({ definitions = kernel-definitions; }) | |
buildInputs = let | |
# I need an env else I hit https://github.com/NixOS/nixpkgs/issues/255923, aka | |
# the main python can't find notebook files. | |
pyEnv = pkgs.python3.withPackages(ps: [ | |
ps.notebook | |
ps.jupyter-console | |
]); | |
in | |
[ | |
allKernels | |
pyEnv | |
# -notebook | |
# ghcEnv needs to be in PATH else ihaskell can't find it | |
# ihaskell needs to be wrapped ? | |
ghcEnv | |
# jupyterEnvironment | |
# jup-console | |
# this gets jupyter's python in PATH | |
# run python-Python-data-env | |
# iPythonKernel.runtimePackages | |
]; | |
shellHook = '' | |
echo "ohayo " | |
echo "${allKernels} " | |
export JUPYTER_PATH=${allKernels} | |
export IPYTHONDIR=_ipythondir | |
export JUPYTER_CONFIG_DIR=_jupyter_cfg | |
''; | |
}; | |
}) // { | |
overlay = final: prev: { }; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment