Last active
October 6, 2022 08:19
-
-
Save sirkonst/67d426e7c349670933a65d0176453e0c to your computer and use it in GitHub Desktop.
Nix shell environment for development python project (with virtualenv and IPython support)
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
with import <nixpkgs> { }; | |
let | |
pythonPackages = python37Packages; | |
pythonVenvDir = ".local/${pythonPackages.python.name}"; | |
envPackages = [ | |
gettext | |
gitMinimal | |
]; | |
preInstallPypiPackages = [ | |
"blue" | |
"mypy" | |
"pylama" | |
"tox" | |
"ipykernel" | |
]; | |
in mkShell { | |
name = "pythonProjectDevEnv"; | |
venvDir = pythonVenvDir; | |
buildInputs = with pythonPackages; [ | |
python | |
venvShellHook | |
] ++ envPackages; | |
postVenvCreation = let | |
toPypiInstall = lib.concatStringsSep " " preInstallPypiPackages; | |
in '' | |
unset SOURCE_DATE_EPOCH # allow pip to install wheels | |
PIP_DISABLE_PIP_VERSION_CHECK=1 pip install ${toPypiInstall} | |
''; | |
postShellHook = '' | |
# fix for cython and ipython | |
export LD_LIBRARY_PATH=${lib.makeLibraryPath [stdenv.cc.cc]} | |
# allow pip to install wheels | |
unset SOURCE_DATE_EPOCH | |
export PIP_DISABLE_PIP_VERSION_CHECK=1 | |
# upgrade venv if python package has been updated | |
python -m venv --upgrade ${pythonVenvDir} | |
''; | |
} |
Also actual for 22.05 nixos.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actual for 21.11 nixos release.