summary refs log tree commit diff
path: root/pkgs/tools/misc/grub
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2021-04-17 16:27:25 +0200
committerSamuel Dionne-Riel <samuel@dionne-riel.com>2021-05-01 17:01:50 -0400
commit4df002c43283952f4ffc434153b3d5efa3024fa8 (patch)
tree8f078b554bc1c2b6f8b6e6d321170d61ad94942e /pkgs/tools/misc/grub
parent4f8cfd1c2e307576c7a88934e1ff42a8d46388f5 (diff)
downloadnixpkgs-4df002c43283952f4ffc434153b3d5efa3024fa8.tar
nixpkgs-4df002c43283952f4ffc434153b3d5efa3024fa8.tar.gz
nixpkgs-4df002c43283952f4ffc434153b3d5efa3024fa8.tar.bz2
nixpkgs-4df002c43283952f4ffc434153b3d5efa3024fa8.tar.lz
nixpkgs-4df002c43283952f4ffc434153b3d5efa3024fa8.tar.xz
nixpkgs-4df002c43283952f4ffc434153b3d5efa3024fa8.tar.zst
nixpkgs-4df002c43283952f4ffc434153b3d5efa3024fa8.zip
grub2_efi: fix cross-compilation
Diffstat (limited to 'pkgs/tools/misc/grub')
-rw-r--r--pkgs/tools/misc/grub/2.0x.nix20
1 files 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}"];