How to apply a patch to a Composer vendor file when using overlays for php.buildComposerProject2 derivations

Hey all,

I’m trying to apply a patch to a buildComposerProject2 vendor file.
This is my current overlay:

self: super: {
  phpactor = super.phpactor.overrideAttrs (old: {
    patches = old.patches or [] ++ [
      ./symlink.patch
    ];
  });
}

And this is my patch file:

Issue: https://github.com/phpactor/phpactor/issues/2727
Pull: https://github.com/phpactor/class-to-file/pull/33

--- a/vendor/phpactor/class-to-file/lib/Adapter/Composer/ComposerFileToClass.php
+++ b/vendor/phpactor/class-to-file/lib/Adapter/Composer/ComposerFileToClass.php
@@ -77,11 +77,11 @@
             $pathPrefixes = (array) $pathPrefixes;
 
             // remove any relativeness from the paths
-            //
-            // TODO: realpath will return void if the path does not exist
-            //       we should not depend on the file path existing.
+            // we should not depend on the file path existing.
             $pathPrefixes = array_map(function ($pathPrefix) {
-                return Path::canonicalize($pathPrefix);
+                $canonicalizedPath = Path::canonicalize($pathPrefix);
+                $realPath = realpath($canonicalizedPath);
+                return $realPath ?: $canonicalizedPath;
             }, $pathPrefixes);
 
             foreach ($pathPrefixes as $pathPrefix) {

Running a home-manager switch will result in the following error:

building '/nix/store/3f75zrm9rljq98w61sl08j0v9hsn0d28-phpactor-2024.06.30.0.drv'...
Running phase: unpackPhase
unpacking source archive /nix/store/y03kw5w6byhgqh1a3pgjwbahdff5h11v-source
source root is source
Running phase: patchPhase
applying patch /nix/store/w3k0hqa4736nmqnmsbgkna53dakf9f59-symlink.patch
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- a/vendor/phpactor/class-to-file/lib/Adapter/Composer/ComposerFileToClass.php
|+++ b/vendor/phpactor/class-to-file/lib/Adapter/Composer/ComposerFileToClass.php
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored

This sounds like the patch is applied before running composer install and having the vendor/ in place.
The whole php.buildComposerProject2 is a bit too complex for me to understand, and Nixpkgs Reference Manual doesn’t cover my use case yet.

Is there any source on how to apply patches to the vendor folder? Or can someone provide a hint or suggestion? Any help is welcome. Please let me know if I can provide further info.