nix-community/dream2nix

NPM workspace and monorepo support

Opened this issue · 0 comments

I attempted to use dream2nix on an npm workspace managed monorepo and ran into an issue on how to manage local package dependencies. I used the nodejs-project as a base which works fine in a workspace if there are no dependencies.

I am guessing I need to build the dependency package as a derivation and make it available as the root package build but can't see any examples or documentation on the best way to accomplish this.

I've set up an example repository here: https://github.com/nathanscully/dream2nix-npm-monorepo

Structure

- flake.nix
- package.json
- /apps
    - /myapp 
      - default.nix
      - app.ts
      - package.json <-- has a workspace dependency on  "packages/adder"
    - /myapp-nodep
      - default.nix
      - app.ts
      - package.json
- /packages
  - /adder 
    - index.ts
    - package.json
  

I can run the 'nodep' version ok:

nix run .#myapp-nodep  
> Hello, World!

But on the 'dep' version:

nix run .#myapp 
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@d2n%2fadder - Not found
npm ERR! 404 
npm ERR! 404  '@d2n/adder@*' is not in this registry.
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

So it looks like its trying to fetch the workspace package from NPM.

Any advice or tips on how to package this up properly?