madjam002 / yarnpnp2nix

A performance focused and space efficient way of packaging NodeJS applications with Nix
MIT License
43 stars 5 forks source link

Working with workspaces containing multiple applications\services #5

Closed adrian-gierakowski closed 1 year ago

adrian-gierakowski commented 1 year ago

Hi @madjam002

I understand that you are using this plugin with some large workspaces.

Would you mind sharing how you handle building sub-projects within a workspace? Do you just build them all in one massive derivation based on top level yarn.lock? Or do you maintain individual lock files for sub-projects which allow them to be built in isolation?

Thanks!

adrian-gierakowski commented 1 year ago

Cross referencing similar topic on a similar project: https://github.com/stephank/yarn-plugin-nixify/issues/63

madjam002 commented 1 year ago

Hi @adrian-gierakowski

Yes you can have a top level yarn.lock, this is what I do, although there's no "one massive derivation". The yarn plugin generates a yarn-manifest.nix file which is basically just a version of yarn.lock that the Nix part of this library can better understand. Each package is its own derivation, whether that's your own packages in the workspace or dependencies. Because of this, if you build a package in your workspace that only has a few dependencies, only those dependencies will be built rather than every dependency of the entire workspace.

That said, I can't see any problems if you use separate yarn.lock files, you'll just need to install the yarn plugin and generate the yarn-manifest.nix for each corresponding yarn.lock and pass it to mkYarnPackagesFromManifest like so:

https://github.com/madjam002/yarnpnp2nix/blob/d3e33b12216a7450b0952c4841b57a1953a6ccf7/test/flake.nix#L19

I hope that helps.

adrian-gierakowski commented 1 year ago

@madjam002 awesome, thanks!

If each package gets its own derivation depending only on the deps they actually use then I don’t need separate lock files.

I’ll give it a spin next week!

Btw. is there support for private npm registries? I’ve added it to my fork of yarn-plugin-nixify so if not I could open a PR if I end up using your project at work.