Poetry2nix overrides usage

Hi,

I am trying to upgrade a flake I had been using for some time now and that uses Poetry2nix.
When I first created that flake, poetry2nix was in nixpkgs. However, since the inputs are updating with that version, it does not work anymore because poetry2nix is now stored out of nixpkgs.

I thought it would have been a simple input change but it seems something has changed in the way it works, or I’m missing something.

This is my old flake:

{
  description = "Poetry python application";

  inputs = {
    utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, utils, ... }:
    utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };

        python = pkgs.python310;
        projectDir = ./.;
        overrides = pkgs.poetry2nix.overrides.withDefaults (final: prev: {
          # Python dependency overrides go here
          pyeda = [ "setuptools" ];
        });
      in
      {

        packages.default = pkgs.poetry2nix.mkPoetryApplication {
          inherit python projectDir overrides;
          # Non-Python runtime dependencies go here
          propogatedBuildInputs = [ ];
        };

        devShell = pkgs.mkShell {
          buildInputs = [
            (pkgs.poetry2nix.mkPoetryEnv {
              inherit python projectDir overrides;
            })
            pkgs.poetry
          ];
        };

      });
}

After searching through the documentation, I came with that new version (which also adds latex packages but this should be irrelevant here):

{
  description = "Build Shell with any dependency of the project";

  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.poetry2nix.url = "github:nix-community/poetry2nix";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

  outputs = { self, nixpkgs, flake-utils, poetry2nix, ... }:
    flake-utils.lib.eachDefaultSystem(system:
        let pkgs = import nixpkgs { inherit system; };
            tex = pkgs.texlive.combine
              {
                inherit (pkgs.texlive)
                # Lot of tex packages, irrelevant for this issue
                ;
              };
            python = pkgs.python310;
            projectDir = ./exam_all;
            overrides = poetry2nix.overrides.withDefaults (final: prev: {
              # Python dependency overrides go here
              pyeda = [ "setuptools" ];
            });

            inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryEnv;
            poetryEnv = mkPoetryEnv {
              inherit python projectDir overrides;
            };
        in
        {
          packages.default = poetry2nix.mkPoetryApplication {
            inherit python projectDir overrides;
            # Non-Python runtime dependencies go here
            propogatedBuildInputs = [ ];
          };

          devShell = pkgs.mkShell {
            buildInputs = [
              pkgs.python310Packages.pygments
              python
              tex               #
              pkgs.poetry
              pkgs.gccStdenv
              pkgs.tikzit
              pkgs.poetry
              poetryEnv
            ];
          };
        }
      );
}

The issue is with the poetry2nix.overrides.withDefaults line. I feel like I’m using it like I found it in the docs, but I always get an attribute 'overrides' missing error.

I feel like it is a really dumb error, but I can’t find why this does not work. I think my understanding of flakes is wrong.

Ok, I got it.

The trick is that Poetry2nix needs to be “built” from inside the flake:

{
  description = "Build Shell with any dependency of the project";

  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.poetry2nix.url = "github:nix-community/poetry2nix";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

  outputs = { self, nixpkgs, flake-utils, poetry2nix, ... }:
    flake-utils.lib.eachDefaultSystem(system:
        let pkgs = import nixpkgs { inherit system; };
            tex = pkgs.texlive.combine
              {
                inherit (pkgs.texlive)
                # Irrelevant things
                ;
              };
            python = pkgs.python310;
            # The trick is here
            p2nix = poetry2nix.lib.mkPoetry2Nix { inherit pkgs;};
            projectDir = ./exam_all;
            overrides = p2nix.overrides.withDefaults (final: prev: {
              # Python dependency overrides go here
              pyeda = [ "setuptools" ];
            });

            poetryEnv = p2nix.mkPoetryEnv {
              inherit python projectDir overrides;
            };
        in
        {
          packages.default = poetry2nix.mkPoetryApplication {
            inherit python projectDir overrides;
            # Non-Python runtime dependencies go here
            propogatedBuildInputs = [ ];
          };

          devShell = pkgs.mkShell {
            buildInputs = [
              pkgs.python310Packages.pygments
              python
              tex               #
              pkgs.poetry
              pkgs.gccStdenv
              pkgs.tikzit
              pkgs.poetry
              poetryEnv
            ];
          };
        }
      );
}