NixOS / bundlers

MIT License
93 stars 12 forks source link

Doing cross-compiled bundles? #8

Open umbertov opened 1 year ago

umbertov commented 1 year ago

Is it possible to bundle e.g. a .deb package for aarch64 system when compiling from an x86 system?

I'm testing with a very basic cmake c++ hello world, but it seems to me that, even if nix-build or nix build -f default.nix do produce aarch64 binaries (i checked with the file command), if i try doing nix bundle -f default.nix --bundler github:NixOS/bundlers#toDEB, i end up with a .deb file for amd64.

tennox commented 1 year ago

You checkout https://nixos.wiki/wiki/Cross_Compiling - probably something like:

nix-build '<nixpkgs>' -A pkgsCross.aarch64-multiplatform.curl

if you want to build curl

I think it's unrelated to bundling

doronbehar commented 1 year ago

I end up with a .deb file for amd64.

I too experience this issue!

I bundled a cross compiled package from a flake:

$ nix build -L .\?submodules=1\#pythonEnv-armv7l-hf-multiplatform
$ file result/bin/python
result/bin/python: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /nix/store/s9alhnp7zb4pbjlp1ap730drmr3w50lb-glibc-armv7l-unknown-linux-gnueabihf-2.35-224/lib/ld-linux-armhf.so.3, for GNU/Linux 3.10.0, not stripped

I build the bundle with:

$ nix bundle --bundler bundlers#toDEB .\?submodules=1\#pythonEnv-armv7l-hf-multiplatform

And when I try to install the.deb` file on the target machine, I get:

# dpkg -i *deb
dpkg: error processing archive python3-armv7l-unknown-linux-gnueabihf_1.0_amd64.deb (--install):
 package architecture (amd64) does not match system (armhf)

Also the _amd64.deb suffix indicates this error in detecting the target architecture of the .deb file.

hacker1024 commented 1 year ago

Yep, the issue is that the .deb file targets amd64 in its metadata, even if the derivation has arm64 binaries.

doronbehar commented 1 year ago

I managed to generate a .deb file for cross compiled binaries without fpm, which NixOS/bundlers uses via it's nix-utils flake dependency.

Here's a link to my implementation:

https://github.com/doronbehar/scipy/blob/7b55b0189f4ee22aba365be3ceac55fa8c3e50b3/flake.nix#L147-L203

Note that in order to use it you have to know your target architecture's name in Debian's terminology - there is not a ready to use Nix table for that in Nixpkgs' lib.systems or something like that. I cross compiled my package for armv7l-hf-multiplatform (Nix terminology) - armhf (Debian terminology).