Have you seen pnpm[0]? Has some similarities.
> Files inside node_modules are cloned or hard linked from a single content-addressable storage
Also (IIRC, it's been a long while) it's lockfile contains enough information to translate it directly to a Nix derivation[1].
[0]: https://pnpm.io/ [1]: https://github.com/nix-community/pnpm2nix