[Nix-dev] Cross-compilation

Lluís Batlle i Rossell viric at viric.name
Fri May 17 22:56:08 CEST 2013


On Fri, May 17, 2013 at 09:23:13PM +0200, Bjørn Forsman wrote:
> I'm slowly getting into cross-compilation on NixOS and I have a question.

Brave!

> According to the wiki[1], building with crossSystem != null still
> results in a native build, it is only when using .crossDrv that the
> package is actually cross-built. This is confirmed with these commands
> (the first two hashes are equal, the last third on is different -
> because it is cross-built):
> 
>   $ nix-build -A bison default.nix
>   /nix/store/f1gn1if4ryhrv64c4c4ljr6ig4w9m0ls-bison-2.6.5
> 
>   $ nix-build -A bison sheevaplug.nix
>   /nix/store/f1gn1if4ryhrv64c4c4ljr6ig4w9m0ls-bison-2.6.5
> 
>   $ nix-build -A bison.crossDrv sheevaplug.nix
>   /nix/store/cah8d34swnmaj49hiipib986gzxbqqg4-bison-2.6.5-armv5tel-unknown-linux-gnueabi
> 
> But when building python I get a different hash for the native builds:
> 
>   $ nix-build -A python default.nix
>   /nix/store/yzj6p5f7iyh247pwxrg97y3klm6d0cni-python-2.7.3
> 
>   $ nix-build -A python sheevaplug.nix
>   /nix/store/4vi4lzj59cjws0m7b26x091a5s4z15dc-python-2.7.3

It's because I never got into making the stdenv overrides work, when the
stdenvCross is set (crossSystem != null). All is around line 121 in all-packages.nix:

      overrides = overrider pkgsOrig //
              (lib.optionalAttrs (pkgsOrig.stdenv ? overrides && crossSystem ==
              null) (pkgsOrig.stdenv.overrides pkgsOrig));

I never thought it would break builds; it simply pulls more pieces into the
build tree that should be equivalent to those if overriden.

> and the cross-built python fails:
> 
>   $ nix-build -A python.crossDrv sheevaplug.nix
>   these derivations will be built:
>     /nix/store/s8aviykc791ryysk7q9linvlnyjqn6qj-python-2.7.3-armv5tel-unknown-linux-gnueabi.drv
>   building path(s)
> `/nix/store/x8kqxk0k7i5cjv4f1khsxi4wsgj3svhi-python-2.7.3-armv5tel-unknown-linux-gnueabi'
>   building /nix/store/x8kqxk0k7i5cjv4f1khsxi4wsgj3svhi-python-2.7.3-armv5tel-unknown-linux-gnueabi
>   unpacking sources
>   unpacking source archive
> /nix/store/zlkysqgg7bd63w0bjwnjcwh6fmh9g5r0-Python-2.7.3.tar.bz2
>   /nix/store/zpxdjsj0scgkk9xhclq6cj6znr9h8h98-bzip2-1.0.6-armv5tel-unknown-linux-gnueabi/bin/bzip2:
> /nix/store/zpxdjsj0scgkk9xhclq6cj6znr9h8h98-bzip2-1.0.6-armv5tel-unknown-linux-gnueabi/bin/bzip2:
> cannot execute binary file
>   tar: Child returned status 126
>   tar: Error is not recoverable: exiting now
>   builder for `/nix/store/s8aviykc791ryysk7q9linvlnyjqn6qj-python-2.7.3-armv5tel-unknown-linux-gnueabi.drv'
> failed with exit code 2
>   error: build of
> `/nix/store/s8aviykc791ryysk7q9linvlnyjqn6qj-python-2.7.3-armv5tel-unknown-linux-gnueabi.drv'
> failed

Well, I don't think anyone tried to cross-build python. It may need adjustments.

As a first approach, add this line to the mkDerivation parameter:
    buildNativeInputs = [ bzip2 ];

It will take the native bzip2 with priority in PATH, compared to the cross-built
bzip2 (requested by buildInputs).

Regards,
Lluís.


More information about the nix-dev mailing list