initial commit

This commit is contained in:
Evan Reichard 2024-02-09 21:53:43 -05:00
commit 8a338ad196
5 changed files with 98 additions and 0 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use nix

14
.gitignore vendored Normal file
View File

@ -0,0 +1,14 @@
# Go Path
.bin
# Jupyter Data
.data
# Virtual Environment
.venv
# Direnv Data
.direnv
# Notebook Path
notebooks/

2
Makefile Normal file
View File

@ -0,0 +1,2 @@
run_jupyter:
jupyter notebook --ip 127.0.0.1 --port 8888 --no-browser --allow-root --notebook-dir=./notebooks

9
README.md Normal file
View File

@ -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
```

72
shell.nix Normal file
View File

@ -0,0 +1,72 @@
with import <nixpkgs> { };
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
'';
}