GitHub

Chat on Matrix

poetry2nix turns Poetry projects into Nix derivations without the need to actually write Nix expressions. It does so by parsing pyproject.toml and poetry.lock and converting them to Nix derivations on the fly.

For more information, see the original announcement post.

Maintenance status: ⚠️ Unmaintained ⚠️

The creator & long-term maintainer of poetry2nix (@adisbladis) is no longer using Poetry or Poetry2nix. This means that poetry2nix is looking for maintainers.

Poetry has a number of upcoming large changes, which poetry2nix is unlikely to gain support for:

If you are not already using Poetry & Poetry2nix, do consider uv & uv2nix.

Quickstart Non-flake

You can turn your Python application into a Nix package with a few lines by adding a default.nix next to your pyproject.toml and poetry.lock files:

# file: default.nix
let
  sources = import ./nix/sources.nix;
  pkgs = import sources.nixpkgs { };
  # Let all API attributes like "poetry2nix.mkPoetryApplication"
  # use the packages and versions (python3, poetry etc.) from our pinned nixpkgs above
  # under the hood:
  poetry2nix = import sources.poetry2nix { inherit pkgs; };
  myPythonApp = poetry2nix.mkPoetryApplication { projectDir = ./.; };
in
myPythonApp

The Nix code being executed by import sources.poetry2nix { inherit pkgs; } is ./default.nix. The resulting poetry2nix attribute set contains (only) the API attributes like mkPoetryApplication.

Hint: This example assumes that nixpkgs and poetry2nix are managed and pinned by the handy niv tool. In your terminal just run:

nix-shell -p niv
niv init
niv add nix-community/poetry2nix

You can then build your Python application with Nix by running:

nix-build default.nix

Finally, you can run your Python application from the new ./result symlinked folder:

"# replace

Read the original on github.com ↗