Intro
patchShebangs rewrites scripts with shebangs to use tools from $PATH. By "resolving" these references to (absolute) nix store paths the interpreter used can be controlled precisely-- for example, the correct version of python will always be used.
This is great 👍 and very useful. Especially on NixOS where not doing so generally means scripts don't work at all.
Problem
When cross-compiling, there is a bit of a problem: which platform's tools should be used? PATH is misleading because it may contain various build-time dependencies (from buildPlatform) that are inappropriate for use on hostPlatform.
Solution?
So, before I wrote this it seemed this was a challenging problem: how to "guess" whether buildPlatform or hostPlatform tools should be used when rewriting shebangs? Nothing in the script will tell you, so it's anyone's guess how it will be used.....
Buuuut I think the answer is actually this: patchShebangs should always patch scripts to use hostPlatform tools, refusing to use tools from buildPlatform (when the two are not the same).
Should the script need to be executed for the build, then if nativeBuildInputs are used properly then the "hostPlatform" the script was patched for will be the current buildSystem. If you follow, hopefully makes sense.
Feedback on whether it's agreed that "patchShebangs should only patch to host tools" would be appreciated.
Forward
Implementing the Solution
This is a bit tricky, but I haven't thought about it too much. Thoughts/suggestions welcome!
Related
Actually, is there any reason for the outputs of a cross-built derivation to have dependencies on things from buildPackages? I expect checking for this strictly would "break" a lot off things, but perhaps that's for the best since it's unclear those outputs would be useful anyway.
Intro
patchShebangs rewrites scripts with shebangs to use tools from $PATH. By "resolving" these references to (absolute) nix store paths the interpreter used can be controlled precisely-- for example, the correct version of python will always be used.
This is great 👍 and very useful. Especially on NixOS where not doing so generally means scripts don't work at all.
Problem
When cross-compiling, there is a bit of a problem: which platform's tools should be used? PATH is misleading because it may contain various build-time dependencies (from buildPlatform) that are inappropriate for use on hostPlatform.
Solution?
So, before I wrote this it seemed this was a challenging problem: how to "guess" whether buildPlatform or hostPlatform tools should be used when rewriting shebangs? Nothing in the script will tell you, so it's anyone's guess how it will be used.....
Buuuut I think the answer is actually this: patchShebangs should always patch scripts to use hostPlatform tools, refusing to use tools from buildPlatform (when the two are not the same).
Should the script need to be executed for the build, then if nativeBuildInputs are used properly then the "hostPlatform" the script was patched for will be the current buildSystem. If you follow, hopefully makes sense.
Feedback on whether it's agreed that "patchShebangs should only patch to host tools" would be appreciated.
Forward
Implementing the Solution
This is a bit tricky, but I haven't thought about it too much. Thoughts/suggestions welcome!
Related
Actually, is there any reason for the outputs of a cross-built derivation to have dependencies on things from buildPackages? I expect checking for this strictly would "break" a lot off things, but perhaps that's for the best since it's unclear those outputs would be useful anyway.