ralismark / nix-appimage

Convert a nixos derivation into a self-contained binary
MIT License
156 stars 19 forks source link

Support for aarch64/raspberry-pi #14

Closed matthiasdotsh closed 1 month ago

matthiasdotsh commented 2 months ago

Thank you very much for this fantastic package. I discovered it yesterday, and I successfully packaged my own derivation as an AppImage—it worked flawlessly! Very impressive!

Now, I'm wondering if it's possible to use this tool to build AppImages for aarch64 to run on a Raspberry Pi.

So far, I have not been able to cross-compile a "Hello" AppImage, nor have I managed to build it natively on the Raspberry Pi as an AppImage.

Cross-compilation:

# on x86 nixos machine
$ nix bundle --bundler github:ralismark/nix-appimage 'nixpkgs#pkgsCross.aarch64-multiplatform.hello'

# On raspberry pi
$ ./hello-aarch64-unknown-linux-gnu-2.12.1-x86_64.AppImage
./hello-aarch64-unknown-linux-gnu-2.12.1-x86_64.AppImage: cannot exec /nix/store/4i7fkxnppy0d2zlp4c36yvc1a1jmsa4a-hello-aarch64-unknown-linux-gnu-2.12.1/bin/hello: Exec format error

Native build on raspberry pi

# On raspberry pi
$ nix bundle --bundler github:ralismark/nix-appimage 'nixpkgs#hello'
[4/2/15 built, 104 copied (703.4 MiB), 133.1 MiB DL] building file-static-aarch64-unknown-
error: builder for '/nix/store/1dswxq3pgkq5n273650kmbb8an6a5h4q-automake-static-aarch64-unknown-linux-musl-1.16.5.drv' failed with exit code 2;
       last 25 log lines:
       > checking for aarch64-unknown-linux-musl-gfortran... no
       > checking for g77... no
       > checking for gfortran... no
       > checking for aarch64-unknown-linux-musl-gcj... no
       > checking for gcj... no
       > checking that generated files are newer than configure... done
       > configure: creating ./config.status
       > config.status: creating Makefile
       > config.status: creating pre-inst-env
       > configure: WARNING: unrecognized options: --enable-static, --disable-shared, --disable-shared
       > building
       > build flags: -j4 -l4 SHELL=/nix/store/191yw2v0ys0qx3l8wlq5mh6ck968naf2-bash-5.1-p16/bin/bash
       >   GEN      bin/automake
       >   GEN      bin/aclocal
       >   GEN      t/ax/shell-no-trail-bslash
       >   GEN      t/ax/cc-no-c-o
       >   GEN      runtest
       >   GEN      doc/aclocal.1
       >   GEN      doc/automake.1
       >   GEN      lib/Automake/Config.pm
       >   GEN      t/ax/test-defs.sh
       >   GEN      doc/aclocal-1.16.1
       > help2man: can't get `--help' info from aclocal-1.16
       > Try `--no-discard-stderr' if option outputs to stderr
       > make: *** [Makefile:3741: doc/aclocal-1.16.1] Error 127
       For full logs, run 'nix log /nix/store/1dswxq3pgkq5n273650kmbb8an6a5h4q-automake-static-aarch64-unknown-linux-musl-1.16.5.drv'.
error: 1 dependencies of derivation '/nix/store/32c6p64zrc9k8j50dp4pcfd2p4mfwds9-hook.drv' failed to build
error (ignored): error: cannot unlink '"/tmp/nix-build-libtool-static-aarch64-unknown-linux-musl-2.4.7.drv-0/build"': Directory not empty
error: 1 dependencies of derivation '/nix/store/9vyfy92abrfpxhbmw1hhylw4k883wfac-squashfuse-aarch64-unknown-linux-musl.drv' failed to build
error: 1 dependencies of derivation '/nix/store/wbm1q1d5sqpwf0n0n80lz8ym3vixk1l6-runtime-aarch64-unknown-linux-musl.drv' failed to build
error: 1 dependencies of derivation '/nix/store/z3dqyw6q072labk0bg9jakp1qqq6b1gd-hello-2.12.1-aarch64.AppImage.drv' failed to build

Compiling 'Hello' on a Raspberry Pi or cross-compiling it on an x86 machine without bundling it as an AppImage works perfectly fine.

Would you expect this to work in principle, or could you perhaps tell me what I might be doing wrong?

ralismark commented 2 months ago

I think this was an issue with the version of nixpkgs this project was pinned to. I've bumped it as part of a bigger refactor, so it should work now. Let me know if it's still broken!

Regarding cross-compiling bundling, it's a limitation of nix bundle (and flakes in general) that they don't support specifying how to cross-compile.

Azathothas commented 1 month ago

I can confirm it works on aarch64 (host is also aarch64). We have been using it over at https://github.com/Azathothas/Toolpacks [+] mpv: https://github.com/Azathothas/Toolpacks/blob/main/.github/scripts/aarch64_Linux/bins/mpv.sh [+] ladybird: https://github.com/Azathothas/Toolpacks/blob/main/.github/scripts/aarch64_Linux/bins/ladybird.sh and many more.

ralismark commented 1 month ago

Thanks for confirming!