From 7a617036083c0e6eacfc086b9c7915e0d881c000 Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Fri, 9 Feb 2024 21:53:43 -0500 Subject: [PATCH] initial commit --- .envrc | 1 + .gitignore | 17 +++++++++++++ Makefile | 2 ++ README.md | 9 +++++++ shell.nix | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README.md create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..1d953f4 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..18253b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# Go Path +.bin + +# Jupyter Data +.data + +# Virtual Environment +.venv + +# Jupyter Checkpoints +.ipynb_checkpoints + +# Direnv Data +.direnv + +# Notebook Path +notebooks/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..33e84d5 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +run_jupyter: + jupyter notebook --ip 127.0.0.1 --port 8888 --no-browser --allow-root --notebook-dir=./notebooks diff --git a/README.md b/README.md new file mode 100644 index 0000000..87be5fb --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Nix Jupyter Notebooks + +The following is a quick way to utilize Nix (`shell.nix`) and `direnv` to automatically spin up a Jupyter environment with both a Python3 and GoNB Kernel. + +## Running + +``` +make run_jupyter +``` diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..596078c --- /dev/null +++ b/shell.nix @@ -0,0 +1,72 @@ +with import { }; + +pkgs.mkShell rec { + venvDir = "./.venv"; + buildInputs = [ + + # Install Python & Packages + (python3.withPackages (ps: with python3Packages; [ + jupyter + ipython + ipykernel + + setuptools + virtualenv + pip + pyqt5 + + pandas + numpy + matplotlib + scipy + ])) + + # Install Go (GoNB) + go + + ]; + + shellHook = '' + # Export Environment Paths + export GOBIN=$(pwd)/.bin + export PATH=$PATH:$(pwd)/.bin + export JUPYTER_DATA_DIR=$(pwd)/.data + + # Upsert Notebook Directory + mkdir -p ./notebooks + + # Install GoNB + go install github.com/janpfeifer/gonb@latest + go install golang.org/x/tools/cmd/goimports@latest + go install golang.org/x/tools/gopls@latest + + # # fixes libstdc++ issues and libgl.so issues + # LD_LIBRARY_PATH=${stdenv.cc.cc.lib}/lib/:/run/opengl-driver/lib/ + # + # # Fix XCB Issues + # QT_PLUGIN_PATH=${qt5.qtbase}/${qt5.qtbase.qtPluginPrefix} + # SOURCE_DATE_EPOCH=$(date +%s) + # QT_XCB_GL_INTEGRATION="none" + + # Upsert Virtual Environment + if [ -d "${venvDir}" ]; then + echo "Skipping venv creation, '${venvDir}' already exists" + else + echo "Creating new venv environment in path: '${venvDir}'" + ${python3.interpreter} -m venv "${venvDir}" + fi + + # Update Python Path + PYTHONPATH=$PWD/${venvDir}/${python3.sitePackages}/:$PYTHONPATH + + # Activate Virtual Environment + source "${venvDir}/bin/activate" + + # Update PIP + python -m pip install --upgrade pip + python -m ipykernel install --user --name=${venvDir} + + # Install GoNB + gonb --install + ''; +}