Last active
March 2, 2024 23:22
-
-
Save shackra/971d4c743ce25bffba14efaa48d24062 to your computer and use it in GitHub Desktop.
shell.nix for Python development
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
let | |
nixpkgs-src = builtins.fetchTarball { | |
# 23.05 | |
url = "https://github.com/NixOS/nixpkgs/archive/nixos-23.11.tar.gz"; | |
}; | |
pkgs = import nixpkgs-src { | |
config = { | |
# allowUnfree may be necessary for some packages, but in general you should not need it. | |
allowUnfree = false; | |
}; | |
}; | |
# This is the Python version that will be used. | |
myPython = pkgs.python311; | |
pythonWithPkgs = myPython.withPackages (pythonPkgs: | |
with pythonPkgs; [ | |
# This list contains tools for Python development. | |
# You can also add other tools, like black. | |
# | |
# Note that even if you add Python packages here like PyTorch or Tensorflow, | |
# they will be reinstalled when running `pip -r requirements.txt` because | |
# virtualenv is used below in the shellHook. | |
ipython | |
pip | |
setuptools | |
virtualenvwrapper | |
wheel | |
python-lsp-server | |
pyls-flake8 | |
]); | |
lib-path = with pkgs; | |
lib.makeLibraryPath [ | |
libffi | |
openssl | |
gccStdenv | |
# If you want to use CUDA, you should uncomment this line. | |
# linuxPackages.nvidia_x11 | |
stdenv.cc.cc.lib | |
]; | |
shell = pkgs.mkShell { | |
buildInputs = [ | |
# my python and packages | |
pythonWithPkgs | |
# other packages needed for compiling python libs | |
pkgs.readline | |
pkgs.libffi | |
pkgs.openssl | |
pkgs.stdenv.cc.cc.lib | |
pkgs.gccStdenv | |
pkgs.curl | |
# unfortunately needed because of messing with LD_LIBRARY_PATH below | |
pkgs.git | |
pkgs.openssh | |
pkgs.rsync | |
]; | |
shellHook = '' | |
# Allow the use of wheels. | |
SOURCE_DATE_EPOCH=$(date +%s) | |
# Augment the dynamic linker path | |
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${lib-path} | |
# Setup the virtual environment if it doesn't already exist. | |
VENV=.venv | |
if test ! -d $VENV; then | |
virtualenv $VENV | |
fi | |
source ./$VENV/bin/activate | |
export PYTHONPATH=`pwd`/$VENV/${myPython.sitePackages}/:$PYTHONPATH | |
pip install -r requirements-test.txt -r requirements.txt | |
''; | |
}; | |
in shell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment