-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Support extra compatible architectures #1916
Conversation
This allows specifying additional systems that a machine is able to build for. This may apply on some armv7-capable aarch64 processors, or on systems using qemu-user with binfmt-misc to support transparent execution of foreign-arch programs. This removes the previous hard-coded assumptions about which systems are ABI-compatible with which other systems, and instead relies on the user to specify any additional platforms that they have ensured compatibility for and wish to build for locally. NixOS should probably add i686-linux on x86_64-linux systems for this setting by default.
This allows building armv[67]l-linux derivations on compatible aarch64 machines. Failure to add the architecture may result from missing hardware support, in which case we can't run 32-bit binaries and don't need to restrict them with seccomp anyway,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm lukewarm on this. Partly because it seems like kind of a niche use case, and partly because I don't really trust qemu-user
enough (though that's a gut feeling that's not well-founded). I'm open to be swayed if there are compelling use cases.
Either way needs docs, ideally with pointers to how you might use this with qemu-user
src/libstore/globals.hh
Outdated
@@ -295,6 +295,9 @@ public: | |||
"Nix store has a valid signature (that is, one signed using a key " | |||
"listed in 'trusted-public-keys'."}; | |||
|
|||
Setting<StringSet> extraPlatforms{this, StringSet{}, "build-extra-platforms", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this should default ti i686-linux
on x86_64-linux
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we have all the entries from from https://github.com/NixOS/nix/pull/1916/files#diff-81a5a969aed0f3f9d6dc4e99b92925cdL60 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure having all of them is a good idea, given how unreliable actually building them is: building armv6 stuff on an armv7 machine will often result in code that doesn't actually run on armv6 because of annoying autodetection in various build systems. Users who want to risk that can easily set this setting as appropriate.
That is my impression too. Relevant: NixOS/nixpkgs#33553. |
Oh yes, the docs. Whoops :) As for its actual use — I'm not saying this absolutely should be used with qemu-user; I've had a bit of trouble with qemu-user too. My primary motivation was to allow ARM32-capable aarch64 machines to build ARM32 stuff. Another option for this would of course be to have both 32-bit and 64-bit nix installed on the machine, but at that point working out which to use, especially in automated invocations, could get hairy. |
Oh, yeah, that's a solid use case 👍 |
another edgecase this can fix, some of the kernel options in nixos lack 32bit x86 support, and there is currently no way to tell nix about that but if the automatic 64bit supports 32bit too code is removed, we can declare the 32bit support in the config file |
Added some documentation, renamed the option, added i686-linux on x86_64-linux by default. I'm not 100% happy with the description, advice on improving it would be appreciated. I'll also squash the commits before this gets merged. |
Support extra compatible architectures (#1916)
I don't really see the use case for this option. Nix needs to know how to build something for a particular platform type. For example, on |
misdetect the target platform and generate incompatible code, so you | ||
may wish to cross-check the results of using this option against | ||
proper natively-built versions of your | ||
derivations.</para></listitem> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning suggests that extra-platforms
is a really bad idea. I mean, it allows you to completely lie to Nix about the platform type (e.g. do a x86_64-darwin
build on x86_64-linux
), thus producing a completely wrong build result, which could then end up in a binary cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you lie and dont configure things properly, it will simply fail to execute the darwin bash/gcc/bootstrap tools, and never get anywhere
I've tested this and it works on an aarch64 machine with 32-bit support. Nixpkgs does need quite a few modifications for this to work (NixOS/nixpkgs#21471 should fix this properly) correctly, but I have got it producing binaries that work fine on a 32-bit only ARM machine successfully. |
Why does Nixpkgs need modification? |
The reason nixpkgs needs modification is that a lot of packages will incorrectly detect the system (using uname AFAIK) to build for as aarch64 when we actually want to build for armv7 using armv7 tools. |
Right, that demonstrates exactly why this option is a bad idea. You could do a armv7 build and end up with a aarch64 binary, a rather significant impurity. For x86_64-linux/i686-linux we have IMHO this PR should be reverted. Or at the very least |
It doesn't, as far as I know.
Exactly the same thing can still be achieved by using an armv7 nix on the same machine, so the absence of this option doesn't eliminate this impurity risk. |
Maybe seccomp can be used to fake the uname result?
Yes, there is the same problem when running i686-linux on x86_64-linux since then it doesn't know that it should use |
Sure, if that works!
Yes, but I'm also strongly in favour of having nixpkgs tell the build systems what to build for explicitly as per NixOS/nixpkgs#21471. What I don't want is to end up having machines (probably more powerful than any "pure" 32-bit ARM machine) that can run a 32-bit user space but not allowing nix to build 32-bit arm stuff on them, just because they also support aarch64. |
That + NixOS/nixpkgs#21471 seems like a good thing. |
There is already some discussion on the uname thing at NixOS/nixpkgs#25240. So, there's no What to me sounds like the best next plan is to try exporting |
BTW so far I've found out it's easiest to boot a ARMv7 KVM virtual machine on aarch64 to sidestep this problem :-) |
I don't expect to disable all of those and live either, but I'd like to do the rest of that issue. |
(Getting a bit off-topic, but...) Well, the condition for that spew is literally:
so there is no way to simultaneously have autotools in cross-compilation mode and have those compile+run tests getting executed. |
I tried the quick hack of doing a |
I built an armv6l system on armv7l, and it seems to be working well. So far, I've only had to modify openssl and I haven't run into any other illegal instructions yet. @dezgeg Where did you set |
Seems like this In the meantime I've experimented with a dirty kernel hack to look at the Don't use yet, it still has some problems with the huge environment variables that happen in nixpkgs stdenv. |
I've been building for armv6l on armv7l using |
This is based on @cleverca22's patch (cleverca22/nix-misc). It allows building for additional architectures locally. This can be useful with binfmt-misc or compatible architectures (e.g. ARM32-capable aarch64 machines). Additionally, it enables 32-bit ARM seccomp support.
Questions: