Skip to content
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

Doing cross-compiled bundles? #8

Open
umbertov opened this issue Oct 10, 2022 · 4 comments
Open

Doing cross-compiled bundles? #8

umbertov opened this issue Oct 10, 2022 · 4 comments

Comments

@umbertov
Copy link

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
Copy link
Contributor

tennox commented Mar 12, 2023

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
Copy link

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
Copy link
Member

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

@doronbehar
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@tennox @doronbehar @umbertov @hacker1024 and others