Pnpm and nix for Node.js modules

I started a discussion about using Nix as the storage backend of pnpm.io over at Would it be possible to integrate pnpm with nixpkgs? · Discussion #3588 · pnpm/pnpm · GitHub.

I’m thinking that individual modules could be stored as opaque output-hashed paths, and then combined into node_modules directories, also stored as output-hashed paths, and each installation would be a GC root.

Pnpm would keep track of the correct hashes to use based on node version etc, and building would be done outside of nix-build.

Node.js needs modules to not be symlinks, so the combined dir would need copies of all the files, but the nix store would hardlink everything.

The node_modules directory itself can be a symlink though, so installation would be super fast if you know the hash and it’s available, just symlink it.

  • Why pnpm? It already does some heavy lifting for storing things in a separate repo and combining them, and I thought they’d be receptive to the idea. Another approach would be to hack it into npm.
  • Why not building with nix-build? Many modules fetch stuff during build, it would be a lot of work to fix them all. I might be wrong.

I’d appreciate adding to the conversation at the link above, but here is nice too :slight_smile: