Poetry2nix to package python project

Hello, I’m trying to get started with poetry2nix by packaging a python package
that uses poetry.

The python package is here: GitHub - michelcrypt4d4mus/pdfalyzer: Analyze PDFs. With colors. And Yara.

I’m running nix-build against this default.nix.

{ pkgs ? import <nixpkgs> { } }:
let
  src = pkgs.fetchFromGitHub {
    owner = "michelcrypt4d4mus";
    repo = "pdfalyzer";
    rev = "v1.14.0";
    sha256 = "sha256-oGeafRerIa0QF1WeAMHxQH/NYgf1Lck2BieD8rSluRs=";
  };
in with pkgs; poetry2nix.mkPoetryApplication { projectDir = src; }

nix-build fails with this message:

error: builder for '/nix/store/s10hakr1jwlx1gdyy5dbdbpn34g6f8q0-python3.10-rich-argparse-plus-0.3.1.4.drv' failed with exit code 2;
       last 10 log lines:
       >   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
       >   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
       >   File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
       >   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
       >   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
       >   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
       >   File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
       > ModuleNotFoundError: No module named 'flit_core'
       >
       >
       For full logs, run 'nix log /nix/store/s10hakr1jwlx1gdyy5dbdbpn34g6f8q0-python3.10-rich-argparse-plus-0.3.1.4.drv'.
error: 1 dependencies of derivation '/nix/store/j2lv88zg037wj0nr3vzcbg8w1l836ni5-python3.10-pdfalyzer-1.14.1.drv' failed to build

How can I fix this issue?

It looks to me that the rich-argparse-plus module requires an override in poetry2nix.

The file that would need updating is this one if you wish to make your on PR:

Otherwise make an issue on their repository.

You can also use overrides to add flit-core as a buildInput to the rich-argparse-plus package.

See poetry2nix/edgecases.md at 863f574729fd26c98ae521ffddd30339041fc51f · nix-community/poetry2nix · GitHub

For inspiration you can check the default overrides that poetry2nix ships with: poetry2nix/default.nix at 863f574729fd26c98ae521ffddd30339041fc51f · nix-community/poetry2nix · GitHub

Thank you! I was able to get it to build with the following

{ pkgs ? import <nixpkgs> { } }:
let
  src = pkgs.fetchFromGitHub {
    owner = "michelcrypt4d4mus";
    repo = "pdfalyzer";
    rev = "v1.14.0";
    sha256 = "sha256-oGeafRerIa0QF1WeAMHxQH/NYgf1Lck2BieD8rSluRs=";
  };
in with pkgs;
poetry2nix.mkPoetryApplication {

  projectDir = src;
  overrides = poetry2nix.defaultPoetryOverrides.extend (self: super: {
    rich-argparse-plus = super.rich-argparse-plus.overridePythonAttrs
      (old: { buildInputs = (old.buildInputs or [ ]) ++ [ super.flit ]; });
    pytest-skip-slow = super.pytest-skip-slow.overridePythonAttrs
      (old: { buildInputs = (old.buildInputs or [ ]) ++ [ super.flit ]; });
    yaralyzer = super.yaralyzer.overridePythonAttrs
      (old: { buildInputs = (old.buildInputs or [ ]) ++ [ super.poetry ]; });
  });
}

and have created this pull request to upstream the changes.

Awesome! Thanks for the PR :ok_hand: