Cross-Compiling Linux Audit from MacOS (to Linux, obviously)

Hi, I want to cross-build the audit package on macos (aarch64-darwin). Currently, cross-compilation from macos to linux systems is somewhat broken but there is already a proposed fix in `pkgsCross.aarch64-multiplatform.gcc` is broken on `aarch64-darwin` · Issue #137877 · NixOS/nixpkgs · GitHub which I based my work on.

Just trying to cross-build the package obviously does not work because darwin is not listed as one of the supported build platforms. So I tried to add it which does not work out-of-the-box. The difficulty lies in the fact that the build process generates some source files at build time, using quite linux-specific stuff. So the build process builds and runs small C programs on the build platform with linux-specific requirements:

  • the linux headers are missing, so I added NIX_CFLAGS_COMPILE_FOR_BUILD="$NIX_CFLAGS_COMPILE_FOR_BUILD -I${linuxHeaders}/ as preBuild hook (which already feels a bit too hacky)
  • sys/personality.h is not found which is present in glibc’s headers so I additionally added -I${}/include to the NIX_CFLAGS_COMPILE_FOR_BUILD
  • the compilation fails at __attribute_pure__ attributes which are gcc-specific, so I changed the depsBuildBuild from to gcc

After these steps the first C program seems to compile but linking fails because ___assert_fail is undefined. I could imagine that there are more hacks possible to workaround this, too, but I am starting to ask myself if this is just not supposed to work. On the other hand, nix’s cross-compilation support is already great, so it would be nice if another package could successfully be cross-compiled. And there are other packages which require patches to be successfully built, too.

What do you think? Should I stop my journey here because this is something which just should not be supported because such linux-specific stuff should not be done on darwin? Or would it be worth to find a solution to this? If so, what would be your recommendations to keep the workarounds and hacks to a minimum?

I would not expect these things to work at all. macOS headers and linux headers are very incompatible, and the linux headers are just straight up incorrect for building binaries to run on macOS.

Okay, I just drop this adventurous journey, at least for now.

Hosted by Flying Circus.