nix devenv setup

It is at long last age of the desktop linux machine. Thanks microsoft.

Using some of the momentum of setting up linux (nix specifically) on my old desktop, I also got my python dependency management set up wrangled.

Rather than referring to the old blogpost (substack) I borrowed it from continuously, I figured I'd post the abridged notes here for my future reference, and hypothetically yours.

Install Devenv

devenv init

Configure

Edit devenv.nix:


{ pkgs, ... }:

{
  packages = [
    # pkgs.git
  ];

  languages.python.enable = true;
  languages.python.venv.enable = true;
  languages.python.poetry.enable = true;
  languages.python.poetry.install.enable = true;
}

Edit devenv.yaml:


inputs:
  nixpkgs:
    url: github:NixOS/nixpkgs/nixpkgs-unstable
  nixpkgs-python:
    url: github:cachix/nixpkgs-python

Install dependencies

direnv allow

There seems to be a problem where poetry is not actually enabled or installed, so run

nix-shell -p poetry
poetry init

to kick things off, should work on subsequent attempts.

If poetry complains about your package setup, disable it in pyproject.toml with

[tool.poetry]
# ...
package-mode = false

Using it

Add libraries to pyproject.toml with

poetry add <package>