Skip to content

Instantly share code, notes, and snippets.

@sirkonst
Last active October 6, 2022 08:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirkonst/67d426e7c349670933a65d0176453e0c to your computer and use it in GitHub Desktop.
Save sirkonst/67d426e7c349670933a65d0176453e0c to your computer and use it in GitHub Desktop.
Nix shell environment for development python project (with virtualenv and IPython support)
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}
'';
}
@sirkonst
Copy link
Author

sirkonst commented Feb 20, 2022

Actual for 21.11 nixos release.

@sirkonst
Copy link
Author

sirkonst commented Oct 6, 2022

Also actual for 22.05 nixos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment