Trouble packaging a frontend (Yarn with namespaces)

I’m trying to update teleport, which has moved away from distributing pre-built frontend assets - now the frontend source files reside in the same repo, and I need to build them using yarn.

The frontend code is using namespaces, and the structure looks roughly like this:

package.json
web/
├── package.json
├── packages
│   ├── build
│   │   ├── package.json
│   ├── design
│   │   ├── package.json
│   ├── shared
│   │   ├── package.json
│   ├── teleport
│   │   ├── package.json
│   └── teleterm
│       ├── package.json

I am trying to write a derivation which would install the required node_modules, and then allow me to invoke yarn build-ui-oss at the top level (which just invokes yarn build in web/packages/teleport. I have tried several variations of mkYarnPackage, mkYarnModules (which seems to be recommended for such cases?) & mkYarnWorkspace.

But no matter what I try the build scripts fail because they can not find scripts that are defined in @gravitational/build (which @gravitational/teleport depends on).

<...>
$ g-build --config webpack.prod.config.js --progress --bail --output-path=../../../webassets/teleport/app
warning Cannot find a suitable global folder. Tried these: "/usr/local, /homeless-shelter/.yarn"
/bin/sh: g-build: not found

When I peek inside what mkYarnModules produces, it looks something like:

.
├── deps
│   ├── @gravitational
│   │   ├── build
│   │   ├── design
│   │   ├── shared
│   │   └── teleport
│   └── teleport-yarn-deps
│       └── package.json
└── node_modules
    ├── 7zip-bin
    │   ├── 7x.sh
    │   ├── <...>
    ├── abab
    │   ├── <...>
    ├── <...>

I am not sure how to utilize this folder structure. When I use yarn install in a nix-shell, yarn produces “normal”, flat node_modules, and I can build the assets successfully (imperatively).

One of my attempts to write the derivation can be seen here: teleport-webassets.nix · GitHub

Will be massively thankful for any help!

In the end, I couldn’t figure out the mkYarn* family, so I went for a simpler approach of just using fetchYarnDeps and yarn install. This pattern seems to be used throughout nixpkgs for similar apps that build frontend assets using Node. The resulting PR can be found here: teleport: 11.2.3 -> 11.3.4 by justinas · Pull Request #214425 · NixOS/nixpkgs · GitHub