This project functions as a template for new Python projects to be set up using Nix. By using Nix for your next Python project you will get:
- Reproducable builds and development environments
- No need for a venv to isolate the project’s python environment
- No need for pyenv or similar to manage your Python version: Nix allows for a complete project declaration that doesn’t bloat your system
- Use Poetry to manage your dependencies, but build them from generated nix derivations created by poetry2nix
You will need Nix installed with flakes enabled. Additionally I recommend nix-direnv (with flake support) to have direnv set you up automatically with the latest version of your flake. If not a fan of direnv: just execute “nix develop“ in the project root to enter your project’s environment
$ git clone https://github.com/sebastiant/nix-python-template.git
$ cd nix-python-template
$ cp .env_vars.template .env_vars # A sample environment variable that direnv will export
$ direnv allow # A first time thing to accept the contents of .envrc
$ echo $SECRET # Environment variables from .env_vars conveniently accessible from shell as well as from your Python project
$ myapp # your app is built and accessible
$ ipython # so are development dependencies
$ testrunner # a sample script using watchexec to keep tests runing is included and right there in your PATH
$ emacs & # Code away! Or even smoother: add direnv-support for your favourite editor so you can start it from anywhere