From 4df002c43283952f4ffc434153b3d5efa3024fa8 Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Sat, 17 Apr 2021 16:27:25 +0200 Subject: [PATCH] grub2_efi: fix cross-compilation --- pkgs/tools/misc/grub/2.0x.nix | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pkgs/tools/misc/grub/2.0x.nix b/pkgs/tools/misc/grub/2.0x.nix index ad7a74e8137..3bae26c3fe7 100644 --- a/pkgs/tools/misc/grub/2.0x.nix +++ b/pkgs/tools/misc/grub/2.0x.nix @@ -1,6 +1,6 @@ { lib, stdenv, fetchgit, flex, bison, python3, autoconf, automake, gnulib, libtool , gettext, ncurses, libusb-compat-0_1, freetype, qemu, lvm2, unifont, pkg-config -, pkgsBuildBuild +, buildPackages , nixosTests , fuse # only needed for grub-mount , runtimeShell @@ -64,7 +64,8 @@ stdenv.mkDerivation rec { echo 'echo "Compile grub2 with { kbdcompSupport = true; } to enable support for this command."' >> util/grub-kbdcomp.in ''; - nativeBuildInputs = [ bison flex python3 pkg-config autoconf automake gettext ]; + depsBuildBuild = [ buildPackages.stdenv.cc ]; + nativeBuildInputs = [ bison flex python3 pkg-config autoconf automake gettext freetype ]; buildInputs = [ ncurses libusb-compat-0_1 freetype lvm2 fuse libtool ] ++ optional doCheck qemu ++ optional zfsSupport zfs; @@ -105,9 +106,18 @@ stdenv.mkDerivation rec { configureFlags = [ "--enable-grub-mount" # dep of os-prober - "BUILD_CC=${pkgsBuildBuild.stdenv.cc}/bin/cc" - ] - ++ optional zfsSupport "--enable-libzfs" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + # grub doesn't do cross-compilation as usual and tries to use unprefixed + # tools to target the host. Provide toolchain information explicitly for + # cross builds. + # + # Ref: # https://github.com/buildroot/buildroot/blob/master/boot/grub2/grub2.mk#L108 + "TARGET_CC=${stdenv.cc.targetPrefix}cc" + "TARGET_NM=${stdenv.cc.targetPrefix}nm" + "TARGET_OBJCOPY=${stdenv.cc.targetPrefix}objcopy" + "TARGET_RANLIB=${stdenv.cc.targetPrefix}ranlib" + "TARGET_STRIP=${stdenv.cc.targetPrefix}strip" + ] ++ optional zfsSupport "--enable-libzfs" ++ optionals efiSupport [ "--with-platform=efi" "--target=${efiSystemsBuild.${stdenv.hostPlatform.system}.target}" "--program-prefix=" ] ++ optionals xenSupport [ "--with-platform=xen" "--target=${efiSystemsBuild.${stdenv.hostPlatform.system}.target}"];