From d8e1751e18251c5cec502187f24c69eeef1466fe Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Wed, 24 Apr 2024 10:17:34 +0200 Subject: [PATCH] Build s390x binaries using musl libc Building using musl until NixOS/nixpkgs#306473 is resolved. Signed-off-by: Sascha Grunert --- nix/default-s390x.nix | 5 ++++- nix/derivation.nix | 25 +++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/nix/default-s390x.nix b/nix/default-s390x.nix index d1dd365b6e..3257cc69ad 100644 --- a/nix/default-s390x.nix +++ b/nix/default-s390x.nix @@ -1,7 +1,10 @@ { enableSystemd ? false }: (import ./nixpkgs.nix { crossSystem = { - config = "s390x-unknown-linux-gnu"; + # TODO: Switch back to glibc when + # https://github.com/NixOS/nixpkgs/issues/306473 + # is resolved. + config = "s390x-unknown-linux-musl"; }; overlays = [ (import ./overlay.nix) ]; }).callPackage ./derivation.nix diff --git a/nix/derivation.nix b/nix/derivation.nix index add7fc771e..078686d9db 100644 --- a/nix/derivation.nix +++ b/nix/derivation.nix @@ -1,4 +1,5 @@ -{ pkgs +{ stdenv +, pkgs , enableCriu , enableSystemd }: @@ -17,21 +18,25 @@ with pkgs; stdenv.mkDerivation { python3 which ]; - buildInputs = [ - glibc - glibc.static - libcap - libseccomp - libsystemd - yajl - ] ++ lib.optionals enableCriu [ criu ]; + buildInputs = + (if stdenv.hostPlatform.isMusl then [ + argp-standalone + ] else [ + glibc + glibc.static + ]) ++ [ + libcap + libseccomp + libsystemd + yajl + ] ++ lib.optionals enableCriu [ criu ]; configureFlags = [ "--enable-static" ] ++ lib.optional (!enableSystemd) [ "--disable-systemd" ]; prePatch = '' export CFLAGS='-static -pthread' export LDFLAGS='-s -w -static-libgcc -static' export EXTRA_LDFLAGS='-s -w -linkmode external -extldflags "-static -lm"' export CRUN_LDFLAGS='-all-static' - export LIBS='${lib.optionalString enableCriu "${criu}/lib/libcriu.a"} ${glibc.static}/lib/libc.a ${glibc.static}/lib/libpthread.a ${glibc.static}/lib/librt.a ${lib.getLib libcap}/lib/libcap.a ${lib.getLib libseccomp}/lib/libseccomp.a ${lib.optionalString enableSystemd "${lib.getLib libsystemd}/lib/libsystemd.a"} ${yajl}/lib/libyajl.a' + export LIBS='${lib.optionalString enableCriu "${criu}/lib/libcriu.a"} ${if stdenv.hostPlatform.isMusl then "${musl}/lib/libc.a ${musl}/lib/libpthread.a ${musl}/lib/librt.a" else "${glibc.static}/lib/libc.a ${glibc.static}/lib/libpthread.a ${glibc.static}/lib/librt.a"} ${lib.getLib libcap}/lib/libcap.a ${lib.getLib libseccomp}/lib/libseccomp.a ${lib.optionalString enableSystemd "${lib.getLib libsystemd}/lib/libsystemd.a"} ${yajl}/lib/libyajl.a' ''; buildPhase = '' patchShebangs .