-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[discussion] patchShebangs and cross: what tools to use? #33956
Comments
It's inevitable that you need two (or more) variants of
where the two exact same commands (well, modulo filename) need to give a different result.
|
Agreed on your example-- I've seen things like this and found them required to cross-compile various packages. Even so--it seems that all of the scripts in the output derivations should be "shifted" in the sense that: build <- host, host <- target, target <-? (presumably stays the same) That is, since we're supposedly generating outputs to run on "host" then there's no reason for any of the outputs to contain references to build packages. Regarding your example--I know right now there certainly /are/ lots of references to build packages but that seems like a failure of our input categorization: If we want scripts we can run on buildPlatform they really need to be built by a stdenv where hostPlatform matches our current buildPlatform. In a way I'm asking what exactly is the purpose of cross-compilation: is it to produce outputs for further cross-compilation? Or is it to produce outputs meant for hostPlatform? Right now (as in your example, among many others) we're doing a blend of both in what appears to be a somewhat ad-hoc manner. This is problematic if you actually want to use the resulting outputs on the hostPlatform -- both because your closure will likely be gigantic and because references to build packages may exist everywhere. The only outputs suitable for hostPlatform are things like bootstrapTools which is very very careful about what it does, and maybe fully-static builds of things (haskell perhaps?). Is this an expected "result" of cross-compiling? If not, then we need to work on improving things. If so, I'm silly and I'm sorry for my misunderstanding :). |
I needed an extended version of |
awesome, I'll take a look! Thanks! |
But all of these are not a failure on nixpkgs side - that's just how the upstream project works.
For the kernel example, you can't get rid of this without massively patching the kernel build system. I would say it's a per-output property: |
Could we add We could also add
Regarding the |
It is that and that alone. A long term goal is to kind of allow different outputs to effectively live in different bootstrapping stages. One part of this is giving them different |
As to the concrete problem with [On a side note, I want to write an RFC whose implementation is simply reverting 469fd89. That would make force the PATH handling everywhere i wanted above.] |
I don't get this. Again, the kernel build system does things like probing the capabilities of the cross compiler, dynamically generates header files, compiles internal helper programs like |
@dezgeg Agreed. To be clear, I was not advocating for building headers separately in general. On a scale from "bad, but easy on upstream" to "good, fighting upstream", we have
The cost from 1 to 2, for example is the For 3 the big idea is we arrange the dependencies to match what we'd have if we actually did build the headers separately, but the headers and binaries are in fact separate outputs of the same derivation as today. It's a compromise to try to get at the advantages of 4 while keeping the feasibility of 2. (Aside) NixOS/nix#1080, btw, is a similar sort of trick. If we
We'd make any tbd- and header-preserving mass rebuild a non-mass rebuild, as if we built headers and binaries separately and also convinced LD to not care if the dynamic libraries were where we said they were. |
This hopefully makes patchShebangs respect cross compilation. It introduces the concept of the HOST_PATH. Nothing is ever executed on it but instead used as a way to get the proper path using ‘command -v’. Needs more testing. /cc @Ericson2314 @dtzWill Fixes NixOS#33956 Fixes NixOS#21138 (Modified backport of f069423. See previous commit to understand the differences between this and the original.)
Was this commit added to master again? Confused why this issue is suddenly now closed. |
Yes and no. Yes, the original one went into master, and no, the revert is in as well. |
Ah makes sense. GitHub isn't so clever, of course. Thanks |
This hopefully makes patchShebangs respect cross compilation. It introduces the concept of the HOST_PATH. Nothing is ever executed on it but instead used as a way to get the proper path using ‘command -v’. Needs more testing. /cc @Ericson2314 @dtzWill Fixes NixOS#33956 Fixes NixOS#21138
This hopefully makes patchShebangs respect cross compilation. It introduces the concept of the HOST_PATH. Nothing is ever executed on it but instead used as a way to get the proper path using ‘command -v’. Needs more testing. /cc @Ericson2314 @dtzWill Fixes NixOS#33956 Fixes NixOS#21138
Addressed in #43833 |
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.
The text was updated successfully, but these errors were encountered: