svanderburg / node2nix

Generate Nix expressions to build NPM packages
MIT License
527 stars 100 forks source link

Patch shebangs in dependency binaries #266

Open thomasjm opened 3 years ago

thomasjm commented 3 years ago

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.

svanderburg commented 3 years ago

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.

pmiddend commented 2 years ago

I was able to package my npm-based piece of software only with this patch. Would be great to have this merged!

thomasjm commented 1 year ago

Just wanted to check @svanderburg, is this fixed now? I'll close the PR if so.