One of the first things I did with Nix flakes and then Devenv.sh was standardize the Node environment for my AWS CDK deployments. A related issue that I let slide at the time was Python dependencies for when a project has Lambda functions with Python runtimes.
My comfort level with Python isn’t very high, and the variety of Python dependency tooling (pip, Poetry, pyenv, venv) leaves me bewildered on a good day. The Lambda functions that I ship aren’t complicated and don’t need many dependencies, although they need to be compatible with the given runtime. A further complexity specific to Lambda functions is that AWS expects the function and its dependencies to be zipped up together.
My preferred way to handle that pre-devenv was to use pip with the -t
flag, which lets me choose the installation directory. This will install the requested package and its dependencies in that directory, which is perfect for my packaging needs. Devenv has excellent support for Python, and getting Python 3.12 is easy:
devenv.nix:
1 | languages.python = { |
devenv.yaml:
1 | inputs: |
Trouble is, that configuration leave me with working python (good) but no pip (not so good). After some unhelpful googling I started playing around with Poetry, but it felt like overkill for what I was looking to accomplish. Ultimately I decided to try venv
:
1 | languages.python = { |
Without venv, this is what my python environment for this project looked like:
1 | (nix:devenv-shell-env) (devenv) $ which python |
With venv, it looks like this:
1 | (nix:devenv-shell-env) (devenv) $ which python |
The good news is here that I have pip now, so the immediate problem is solved. I did find myself a little curious about what’s happening in the root .devenv
directory:
1 | -rwxr-xr-x 1 user group 271 Nov 12 22:35 pip |
That’s about what I expected. A symlink back to the same immutable python binary, and the usual pip module (module?) in the project directory. This gets around problems I’d had earlier with enabling pip, which tried to put it in the immutable /nix/ store, which didn’t work. This may have been the obvious solution for someone experienced with Python, but I’m not.