NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.18k stars 14.19k forks source link

Failure building pkgsCross.aarch64-android-prebuilt.bash #147084

Open io12 opened 2 years ago

io12 commented 2 years ago

Describe the bug

When cross compiling bash for aarch64-android-prebuilt, the build fails.

Steps To Reproduce

Steps to reproduce the behavior:

  1. nix-build '<nixpkgs>' -A pkgsCross.aarch64-android-prebuilt.bash
  2. Observe error

Expected behavior

The build should succeed.

Additional context

Output log: https://paste.rs/mnq

Notify maintainers

@dtzWill

Metadata

 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.0-9-amd64, Debian GNU/Linux, 11 (bullseye)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.4`
 - channels(user): `"nixpkgs-21.11pre333180.98747f27ecf"`
 - channels(root): `"nixpkgs-21.11pre332724.73f81a044cf"`
 - nixpkgs: `/home/user/.nix-defexpr/channels/nixpkgs`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute: [pkgsCross.aarch64-android-prebuilt.bash]
# a list of nixos modules affected by the problem
module:
io12 commented 2 years ago

I think I figured out the cause of the error. With hardening enabled, bionic uses different header files that use inline functions instead of prototypes, and this causes the getcwd() redefinition error. Also, the pkg-config package's autoconf script doesn't enable -Werror=implicit-function-declaration during ./configure, but does enable it when compiling, and this causes a build failure because pthread.h doesn't contain pthread_cond_timedwait_monotonic.

This patch fixes it:

diff --git a/pkgs/development/tools/misc/pkg-config/default.nix b/pkgs/development/tools/misc/pkg-config/default.nix
index b0b3115700f..970a39c7ce7 100644
--- a/pkgs/development/tools/misc/pkg-config/default.nix
+++ b/pkgs/development/tools/misc/pkg-config/default.nix
@@ -13,6 +13,8 @@ stdenv.mkDerivation rec {

   outputs = [ "out" "man" "doc" ];

+  hardeningDisable = [ "all" ];
+
   # Process Requires.private properly, see
   # http://bugs.freedesktop.org/show_bug.cgi?id=4738, migrated to
   # https://gitlab.freedesktop.org/pkg-config/pkg-config/issues/28
@@ -34,6 +36,7 @@ stdenv.mkDerivation rec {
          "glib_cv_uscore=no"
          "ac_cv_func_posix_getpwuid_r=yes"
          "ac_cv_func_posix_getgrgid_r=yes"
+         "CFLAGS=-Werror=implicit-function-declaration"
        ];

   enableParallelBuilding = true;
diff --git a/pkgs/shells/bash/5.1.nix b/pkgs/shells/bash/5.1.nix
index efa90b0499e..c2c8f53b9cf 100644
--- a/pkgs/shells/bash/5.1.nix
+++ b/pkgs/shells/bash/5.1.nix
@@ -32,7 +32,7 @@ stdenv.mkDerivation rec {
     sha256 = "1alv68wplnfdm6mh39hm57060xgssb9vqca4yr1cyva0c342n0fc";
   };

-  hardeningDisable = [ "format" ];
+  hardeningDisable = [ "all" ];

   outputs = [ "out" "dev" "man" "doc" "info" ];

I know this can't be merged as-is because it disables hardening on all platforms instead of just Android, but I don't know enough about Nix yet to figure out the right way to fix this.

Thanks!

exarkun commented 2 years ago

At first I thought this was fixed by #192630. The issue being fixed there is the same incompatible getcwd declaration as is described here. The fix there is a bit different. However, then I noticed this is about aarch64-android-prebuilt.bash and that package still fails to build - but with a different error:

error: infinite recursion encountered

       at /home/exarkun/Work/PrivateStorage/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:295:14:

          294|       args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)];
          295|       inherit stdenv;
             |              ^
          296|

So I don't know if #192630 really fixed the specific build error described here or not.