aboutsummaryrefslogtreecommitdiff
path: root/docs/qemu-vs-cross.adoc
blob: 7010ac01efd2a2f732a12833083f9917d38aafb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
= Cross build vs. Qemu build

When building packages or NixOS on any other machine (most likely amd64) you
have two options how to build. You can either build natively like you would be
running on the target platform using Qemu. Or you can use cross build. This
document tires to gives you some comparison so you can decide on your own which
you want to use. In general use what works for you.

Compilation speed:: The cross build is much faster compared to Qemu. It is
simple as that.

Build success:: There is a lot of packages that are broken for cross build in
Nixpkgs and thus sometimes you might have more luck with native builds. At the
same time there is a lot of packages that won't compile natively on armv7 for
multiple reasons (the most common is that test cases do not expect 32bit
system). The rule of thumb is that with aarch64 native build is more stable
while cross build might be more stable for armv7.

Device rebuilds:: The one huge disadvantage for the cross builds is that they
produce different result compared to native builds in Nix. The effect is that
`nixos-rebuild` on the device can't reuse cross builds while it can reuse native
builds.


== Native (Qemu) build Nix setup

To get native build work you need the Nix with ability to run aarch64 and/or
armv7 binaries. That is in general option `extra-platforms` with value
`aarch64-linux` for Turris Mox and `armv7l-linux` for Turris Omnia. To actually
allow access to the emulator you need something like `extra-sandbox-paths` with
value such as `/usr/bin/qemu-aarch64` (for Turris Mox) or `/usr/bin/qemu-arm`
(for Turris Omnia). This way you can build aarch64 or armv7l package on other
platforms. You might also want to add some ARM specific substituters.

The configuration file for Nix should thus contain something like:

----
extra-platforms = aarch64-linux armv7l-linux
extra-sandbox-paths = /usr/bin/qemu-aarch64 /usr/bin/qemu-arm
extra-substituters = https://arm.cachix.org https://thefloweringash-armv7.cachix.org
extra-trusted-public-keys = arm.cachix.org-1:K3XjAeWPgWkFtSS9ge5LJSLw3xgnNqyOaG7MDecmTQ8= thefloweringash-armv7.cachix.org-1:v+5yzBD2odFKeXbmC+OPWVqx4WVoIVO6UXgnSAWFtso=
----

If you are running on the NixOS then you can use configuration:

----
boot.binfmt.emulatedSystems = [ "aarch64-linux" "armv7l-linux" ];
----