If I cross-compile a program, the hash will be different from the hash one would get from a non-cross compiled binary. While this is great to ensure reproducibility, it is not great for end users that do not care if the software was compiled natively or cross-compiled. For instance, if in a given channel, programA
is natively compiled, and programB
is not, the user cannot simply write environment.systemPackages = [ programA programB]
. Worse, the closure size will basically be twice as big since the user will get libraries that are cross-compiled and libraries that are natively compiled.
So my question is: is it possible (theoretically and/or practically) to fake a natively compiled binary while cross-compiling it? I can imagine a quite rude way of proceeding, like get the hash somehash
of the natively compiled binary, and manually link /nix/store/somehash-programB
to the path of the cross-compiled binary, but there are two drawbacks:
- Iām not sure how to do that in a āsafeā way, i.e. without corrupting the nix storeā¦ and Iām not 100% sure it will work, notably for libraries
- this seems like quite dirty, maybe there is a more organized way to do it?
- the program will still be linked to the cross-compiled libs I guess. Would it be possible then to recursively do the same trick on all cross-compiled libs (seems really dirty), or, maybe, to replace all links by automatically applying the same trick as
system.replaceRuntimeDependencies
to use the native libraries?
One application I have in mind would be to create a Hydra server on x86_64, that can transparently compile for aarch64 say, while having greater speed than binfmt.