node2nix
node2nix copied to clipboard
Patch shebangs in dependency binaries
I needed to do this so that a call to node-gyp-build would work in one of my dependencies.
Sometimes a dependency comes with an executable script, which ultimately gets symlinked into node_modules/.bin. The existing patchShebangs call at the beginning of prepareAndInvokeNPM doesn't always catch these, because they don't always have the executable bit set. As a result, you get a failure in the Nix build because /usr/bin/env node doesn't exist.
So, this PR uses jq to traverse the bin field of package.json, turning these files executable and patching them as necessary.
This PR also exposes the preRebuild hook for buildNodeDependencies, and by extension for the shell attribute. I think this will resolve #226.
I've implemented my own implementation that does not rely on jq or examining the package.json config. I think this should work because references in bin/ always resolve to paths installed in the same output Nix store path.
I'm still validating whether this does not introduce new problems.
I was able to package my npm-based piece of software only with this patch. Would be great to have this merged!
Just wanted to check @svanderburg, is this fixed now? I'll close the PR if so.