Can't build PyPi package as poetry2nix dependency

Friends, I encountered an issue when building mkPoetryApplication.

I have a small base16 color library that I have submitted to PyPi

It is compiled using poetry.

I’d like to use it for scripts that I add declaratively to my NixOS configuration.
Now I’m writing a script using poetry2nix, but when I try to build the application, I get an error at the stage of building this package:

nix log /nix/store/gjjmxb6h3f6d47cc59z4hh3is1xivy15-python3.10-base16-colorlib-0.2.0.drv

# ....
Processing /tmp/nix-build-python3.10-base16-colorlib-0.2.0.drv-0/base16_colorlib-0.2.0
  Running command Preparing metadata (pyproject.toml)
  Preparing metadata (pyproject.toml) ... done
ERROR: Exception:

Here's a python traceback
It basically comes from pip

  File "/nix/store/j73ikmqhvn2sjb536bpk9khrn2cgijy3-python3.10-pip-23.2.1/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/", line 77, in _build_backend
    obj = import_module(mod_path)
  File "/nix/store/pzf6dnxg8gf04xazzjdwarm7s03cbrgz-python3-3.10.12/lib/python3.10/importlib/", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'poetry'

I know that the package can be installed on my local computer.

python3 -m venv venv
pip install base16-colorlib
pip freeze --> base16-colorlib==0.2.0

This is what flake.nix looks like now for the script and this library:

  description = "i3lock-color-py preconf run script";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";

  outputs = { self, nixpkgs, ... }:
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
    packages.${system}.default = with pkgs; poetry2nix.mkPoetryApplication {
      projectDir = self;
      propagatedBuildInputs = [
    devShells.${system}.default = pkgs.mkShellNoCC {
      shellHook = ''
        echo "█░█░█ █▀▀ █░░ █▀▀ █▀█ █▀▄▀█ █▀▀"
        echo "▀▄▀▄▀ ██▄ █▄▄ █▄▄ █▄█ █░▀░█ ██▄"
        echo "-- -- -- -- -- -- -- -- -- -- -"
      packages = with pkgs; [
        (poetry2nix.mkPoetryEnv { projectDir = self; })

This is what pyproject.toml looks like

name = "i3lock-color-pytonic"
version = "0.1.0"
description = "Pre-configured script to run i3lock-color with the ability to change the color scheme and some parameters"
authors = ["MOIS3Y <>"]
license = "GPL-3.0-or-later"
repository = ""
keywords = ["i3lock", "i3lock-color", "lockscreen"]
include = [""]
readme = ""
packages = [{include = "i3lock_color"}]

python = "^3.10"
base16-colorlib = "^0.2.0"
click = "^8.1.7"
PyYAML = "^6.0.1"

flake8 = "^6.1.0"

i3lock-run = "i3lock_color.main:main"

requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

As you can see, there is nothing special, if you remove base16_colorlib everything comes together and works.
Of course, I could do without the library, but I don’t want to duplicate the code.
I also really want to understand why it is not working, as I find poetry2nix a very useful tool.

I completely forgot to say that earlier they helped me package this as part of the system packages using packageOverrides
And it worked.
In general, I understand how self: super works, but I don’t know where it can be applied in the case of p2nix

Good news if someone suddenly encounters this problem:
I solved it by adding:

preferWheels = true;


    packages.${system}.default = with pkgs; poetry2nix.mkPoetryApplication {
      projectDir = self;
      preferWheels = true;  # <--- fix ussue
      propagatedBuildInputs = [

This is the documented line:


Looks like I need to find out more information about wheels

In any case, if you have a similar problem during assembly, this is worth paying attention to.
If someone can explain to me the reason why nix does not collect packages the way pip does, I will be very grateful.