Packaging python library that uses itself

I am trying to build a derivation of langkit.

I have the following derivation

{ python3Packages
, fetchFromGitHub
, gnat
, gprbuild-boot
, gnatcoll-core
, gnatcoll-gmp
, gnatcoll-iconv
, adasat
, prettier
, vss
}:



python3Packages.buildPythonPackage rec {
  pname = "langkit";

  version = "25.0.0";

  src = fetchFromGitHub {
    name = "langkit";
    owner = "AdaCore";
    repo = "langkit";
    rev = "v${version}";
    sha256 = "GhYjrPpjxpIZLsKhiiAscpQNGAnDTeyr7oobSSrpzAc=";
  };

  dependencies = with python3Packages; [
    mako
    pyyaml
    funcy
    docutils
    e3-core
    pbr
  ];

  nativeBuildInputs = [
    gprbuild-boot
    gnat
  ];

  propagatedBuildInputs = [
    gnatcoll-core
    gnatcoll-iconv
    gnatcoll-gmp
    adasat
    prettier
    vss
  ];

  build-systems = with python3Packages;[
    setuptools
    setuptools-scm
  ];

  patchPhase = ''
    substituteInPlace setup.py --replace \
      distutils.core \
      setuptools
  '';

  buildPhase = '' 
    python setup.py install --prefix=${placeholder "out"}  

    python manage.py make --no-mypy --library-types=static
  '';

  doCheck = false;

}

problem happens when python manage.py make --no-mypy --library-types=static
is called I get the following error.

I noticed it is trying to use langkit right after the install to build two other libraries. Is their a way to use langkit within the derivation?

Amend the PYTHONPATH with whatever it put into $out to make langkit available before the call to manage.py. Or split it into two derivations and pass langkit as a buildInput as usual.

I tried adding the PYTHONPATH to the installPhase:

installPhase = ''
    PYTHONPATH=$out/${python3Packages.python.sitePackages}:$PYTHONPATH
    echo $PYTHONPATH
    python manage.py make --no-mypy --library-types=static
  '';

which echo display

/nix/store/1nnw1i882fr6nvwkkylll6b1901w9h36-python3.12-langkit-25.0.0/lib/python3.12/site-packages: ...

I still get the same error as before