about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--lib/platforms.nix2
-rw-r--r--nixos/modules/installer/cd-dvd/sd-image-aarch64.nix63
-rw-r--r--nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix4
-rw-r--r--nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix2
-rw-r--r--pkgs/build-support/cc-wrapper/default.nix1
-rw-r--r--pkgs/build-support/setup-hooks/update-autotools-gnu-config-scripts.sh12
-rw-r--r--pkgs/development/interpreters/spidermonkey/17.nix2
-rw-r--r--pkgs/development/interpreters/spidermonkey/aarch64-double-conversion.patch13
-rw-r--r--pkgs/development/libraries/glibc/common.nix2
-rw-r--r--pkgs/development/libraries/gnu-config/default.nix39
-rw-r--r--pkgs/development/libraries/gnu-efi/aarch64-fix-discarded-qualifier.patch13
-rw-r--r--pkgs/development/libraries/gnu-efi/default.nix4
-rw-r--r--pkgs/development/libraries/libsigsegv/aarch64.patch12
-rw-r--r--pkgs/development/libraries/libsigsegv/default.nix6
-rw-r--r--pkgs/development/libraries/libunwind/default.nix9
-rw-r--r--pkgs/misc/uboot/default.nix8
-rw-r--r--pkgs/os-specific/linux/busybox/busybox-in-store.patch9
-rw-r--r--pkgs/os-specific/linux/firmware/raspberrypi/default.nix2
-rw-r--r--pkgs/os-specific/linux/fuse/default.nix7
-rw-r--r--pkgs/os-specific/linux/kernel/common-config.nix2
-rw-r--r--pkgs/os-specific/linux/kernel/manual-config.nix2
-rw-r--r--pkgs/stdenv/adapters.nix1
-rw-r--r--pkgs/stdenv/default.nix1
-rw-r--r--pkgs/stdenv/generic/default.nix2
-rw-r--r--pkgs/stdenv/linux/bootstrap-files/aarch64.nix11
-rw-r--r--pkgs/stdenv/linux/default.nix15
-rw-r--r--pkgs/stdenv/linux/make-bootstrap-tools-cross.nix16
-rw-r--r--pkgs/stdenv/linux/make-bootstrap-tools.nix5
-rw-r--r--pkgs/top-level/all-packages.nix9
-rw-r--r--pkgs/top-level/platforms.nix58
30 files changed, 305 insertions, 27 deletions
diff --git a/lib/platforms.nix b/lib/platforms.nix
index b068d080e752..0cd9485d4ccb 100644
--- a/lib/platforms.nix
+++ b/lib/platforms.nix
@@ -15,7 +15,7 @@ rec {
   freebsd = ["i686-freebsd" "x86_64-freebsd"];
   gnu = linux; /* ++ hurd ++ kfreebsd ++ ... */
   illumos = ["x86_64-solaris"];
-  linux = ["i686-linux" "x86_64-linux" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "mips64el-linux"];
+  linux = ["i686-linux" "x86_64-linux" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "aarch64-linux" "mips64el-linux"];
   netbsd = ["i686-netbsd" "x86_64-netbsd"];
   openbsd = ["i686-openbsd" "x86_64-openbsd"];
   unix = linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos;
diff --git a/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix b/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix
new file mode 100644
index 000000000000..8cf349fbd078
--- /dev/null
+++ b/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix
@@ -0,0 +1,63 @@
+# To build, use:
+# nix-build nixos -I nixos-config=nixos/modules/installer/cd-dvd/sd-image-aarch64.nix -A config.system.build.sdImage
+{ config, lib, pkgs, ... }:
+
+let
+  extlinux-conf-builder =
+    import ../../system/boot/loader/generic-extlinux-compatible/extlinux-conf-builder.nix {
+      inherit pkgs;
+    };
+in
+{
+  imports = [
+    ../../profiles/minimal.nix
+    ../../profiles/installation-device.nix
+    ./sd-image.nix
+  ];
+
+  assertions = lib.singleton {
+    assertion = pkgs.stdenv.system == "aarch64-linux";
+    message = "sd-image-aarch64.nix can be only built natively on Aarch64 / ARM64; " +
+      "it cannot be cross compiled";
+  };
+
+  # Needed by RPi firmware
+  nixpkgs.config.allowUnfree = true;
+
+  boot.loader.grub.enable = false;
+  boot.loader.generic-extlinux-compatible.enable = true;
+
+  boot.kernelPackages = pkgs.linuxPackages_latest;
+  boot.kernelParams = ["console=ttyS0,115200n8" "console=tty0"];
+  boot.consoleLogLevel = 7;
+
+  # FIXME: this probably should be in installation-device.nix
+  users.extraUsers.root.initialHashedPassword = "";
+
+  sdImage = {
+    populateBootCommands = let
+      # Contains a couple of fixes for booting a Linux kernel, will hopefully appear upstream soon.
+      patchedUboot = pkgs.ubootRaspberryPi3_64bit.overrideAttrs (oldAttrs: {
+        src = pkgs.fetchFromGitHub {
+          owner = "dezgeg";
+          repo = "u-boot";
+          rev = "baab53ec244fe44def01948a0f10e67342d401e6";
+          sha256 = "0r5j2pc42ws3w3im0a9c6bh01czz5kapqrqp0ik9ra823cw73lxr";
+        };
+      });
+
+      configTxt = pkgs.writeText "config.txt" ''
+        kernel=u-boot-rpi3.bin
+        arm_control=0x200
+        enable_uart=1
+      '';
+      in ''
+        for f in bootcode.bin fixup.dat start.elf; do
+          cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/$f boot/
+        done
+        cp ${patchedUboot}/u-boot.bin boot/u-boot-rpi3.bin
+        cp ${configTxt} boot/config.txt
+        ${extlinux-conf-builder} -t 3 -c ${config.system.build.toplevel} -d ./boot
+      '';
+  };
+}
diff --git a/nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix b/nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix
index 456ef7c9f541..76f5d4bf6472 100644
--- a/nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix
+++ b/nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix
@@ -1,3 +1,5 @@
+# To build, use:
+# nix-build nixos -I nixos-config=nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix -A config.system.build.sdImage
 { config, lib, pkgs, ... }:
 
 let
@@ -46,7 +48,7 @@ in
           cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/$f boot/
         done
         cp ${pkgs.ubootRaspberryPi2}/u-boot.bin boot/u-boot-rpi2.bin
-        cp ${pkgs.ubootRaspberryPi3}/u-boot.bin boot/u-boot-rpi3.bin
+        cp ${pkgs.ubootRaspberryPi3_32bit}/u-boot.bin boot/u-boot-rpi3.bin
         cp ${configTxt} boot/config.txt
         ${extlinux-conf-builder} -t 3 -c ${config.system.build.toplevel} -d ./boot
       '';
diff --git a/nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix b/nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix
index e7163f10a3c3..c7915b578d8a 100644
--- a/nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix
+++ b/nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix
@@ -1,3 +1,5 @@
+# To build, use:
+# nix-build nixos -I nixos-config=nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix -A config.system.build.sdImage
 { config, lib, pkgs, ... }:
 
 let
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index 95e0b360937a..95c6bee3cc77 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -272,6 +272,7 @@ stdenv.mkDerivation {
        if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
        # ARM with a wildcard, which can be "" or "-armhf".
        if stdenv.isArm then "ld-linux*.so.3" else
+       if stdenv.system == "aarch64-linux" then "ld-linux-aarch64.so.1" else
        if stdenv.system == "powerpc-linux" then "ld.so.1" else
        if stdenv.system == "mips64el-linux" then "ld.so.1" else
        if stdenv.system == "x86_64-darwin" then "/usr/lib/dyld" else
diff --git a/pkgs/build-support/setup-hooks/update-autotools-gnu-config-scripts.sh b/pkgs/build-support/setup-hooks/update-autotools-gnu-config-scripts.sh
new file mode 100644
index 000000000000..5e33ace42b37
--- /dev/null
+++ b/pkgs/build-support/setup-hooks/update-autotools-gnu-config-scripts.sh
@@ -0,0 +1,12 @@
+preConfigurePhases+=" updateAutotoolsGnuConfigScriptsPhase"
+
+updateAutotoolsGnuConfigScriptsPhase() {
+    if [ -n "$dontUpdateAutotoolsGnuConfigScripts" ]; then return; fi
+
+    for script in config.sub config.guess; do
+        for f in $(find . -name "$script"); do
+            echo "Updating Autotools / GNU config script to a newer upstream version: $f"
+            cp -f "@gnu_config@/$script" "$f"
+        done
+    done
+}
diff --git a/pkgs/development/interpreters/spidermonkey/17.nix b/pkgs/development/interpreters/spidermonkey/17.nix
index a2ecfb2ef97a..1b6eb98b49da 100644
--- a/pkgs/development/interpreters/spidermonkey/17.nix
+++ b/pkgs/development/interpreters/spidermonkey/17.nix
@@ -20,6 +20,8 @@ stdenv.mkDerivation rec {
   postPatch = ''
     # Fixes an issue with version detection under perl 5.22.x
     sed -i 's/(defined\((@TEMPLATE_FILE)\))/\1/' config/milestone.pl
+  '' + stdenv.lib.optionalString stdenv.isAarch64 ''
+    patch -p1 -d ../.. < ${./aarch64-double-conversion.patch}
   '';
 
   preConfigure = ''
diff --git a/pkgs/development/interpreters/spidermonkey/aarch64-double-conversion.patch b/pkgs/development/interpreters/spidermonkey/aarch64-double-conversion.patch
new file mode 100644
index 000000000000..bf41ce0a8a21
--- /dev/null
+++ b/pkgs/development/interpreters/spidermonkey/aarch64-double-conversion.patch
@@ -0,0 +1,13 @@
+diff -ru mozjs17.0.0-orig/mfbt/double-conversion/utils.h mozjs17.0.0/mfbt/double-conversion/utils.h
+--- mozjs17.0.0-orig/mfbt/double-conversion/utils.h	2013-02-11 17:33:28.000000000 -0500
++++ mozjs17.0.0/mfbt/double-conversion/utils.h	2016-12-03 20:39:07.915042988 -0500
+@@ -58,7 +58,8 @@
+     defined(__mips__) || defined(__powerpc__) || \
+     defined(__sparc__) || defined(__sparc) || defined(__s390__) || \
+     defined(__SH4__) || defined(__alpha__) || \
+-    defined(_MIPS_ARCH_MIPS32R2)
++    defined(_MIPS_ARCH_MIPS32R2) || \
++    defined(__AARCH64EL__)
+ #define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
+ #elif defined(_M_IX86) || defined(__i386__) || defined(__i386)
+ #if defined(_WIN32)
diff --git a/pkgs/development/libraries/glibc/common.nix b/pkgs/development/libraries/glibc/common.nix
index 4e03293fdf96..32c1b3647372 100644
--- a/pkgs/development/libraries/glibc/common.nix
+++ b/pkgs/development/libraries/glibc/common.nix
@@ -93,7 +93,7 @@ stdenv.mkDerivation ({
       "--enable-kernel=2.6.32"
     ] ++ lib.optionals (cross != null) [
       (if cross.withTLS then "--with-tls" else "--without-tls")
-      (if cross.float == "soft" then "--without-fp" else "--with-fp")
+      (if cross ? float && cross.float == "soft" then "--without-fp" else "--with-fp")
     ] ++ lib.optionals (cross != null
           && cross.platform ? kernelMajor
           && cross.platform.kernelMajor == "2.6") [
diff --git a/pkgs/development/libraries/gnu-config/default.nix b/pkgs/development/libraries/gnu-config/default.nix
new file mode 100644
index 000000000000..b46523071c7c
--- /dev/null
+++ b/pkgs/development/libraries/gnu-config/default.nix
@@ -0,0 +1,39 @@
+{ stdenv, fetchurl }:
+
+let
+  rev = "6a82322dd05cdc57b4cd9f7effdf1e2fd6f7482b";
+
+  # Don't use fetchgit as this is needed during Aarch64 bootstrapping
+  configGuess = fetchurl {
+    url = "http://git.savannah.gnu.org/cgit/config.git/plain/config.guess?id=${rev}";
+    sha256 = "1yj9yi94h7z4z6jzickddv64ksz1aq5kj0c7krgzjn8xf8p3avmh";
+  };
+  configSub = fetchurl {
+    url = "http://git.savannah.gnu.org/cgit/config.git/plain/config.sub?id=${rev}";
+    sha256 = "1qsqdpla6icbzskkk7v3zxrpzlpqlc94ny9hyy5wh5lm5rwwfvb7";
+  };
+in
+stdenv.mkDerivation rec {
+  name = "gnu-config-${version}";
+  version = "2016-12-31";
+
+  buildCommand = ''
+    mkdir -p $out
+    cp ${configGuess} $out/config.guess
+    cp ${configSub} $out/config.sub
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Attempt to guess a canonical system name";
+    homepage = http://savannah.gnu.org/projects/config;
+    license = licenses.gpl3;
+    # In addition to GPLv3:
+    #   As a special exception to the GNU General Public License, if you
+    #   distribute this file as part of a program that contains a
+    #   configuration script generated by Autoconf, you may include it under
+    #   the same distribution terms that you use for the rest of that
+    #   program.
+    maintainers = [ maintainers.dezgeg ];
+    platforms = platforms.all;
+  };
+}
diff --git a/pkgs/development/libraries/gnu-efi/aarch64-fix-discarded-qualifier.patch b/pkgs/development/libraries/gnu-efi/aarch64-fix-discarded-qualifier.patch
new file mode 100644
index 000000000000..2295a4bb8a37
--- /dev/null
+++ b/pkgs/development/libraries/gnu-efi/aarch64-fix-discarded-qualifier.patch
@@ -0,0 +1,13 @@
+diff -ru gnu-efi-3.0.4-orig/lib/aarch64/initplat.c gnu-efi-3.0.4/lib/aarch64/initplat.c
+--- gnu-efi-3.0.4-orig/lib/aarch64/initplat.c	2016-03-17 09:53:14.000000000 -0400
++++ gnu-efi-3.0.4/lib/aarch64/initplat.c	2016-12-03 17:53:57.166575974 -0500
+@@ -41,7 +41,8 @@
+ 
+ void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n)
+ {
+-    unsigned char *p = dest, *q = src;
++    unsigned char *p = dest;
++    const unsigned char *q = src;
+ 
+     while (n--)
+         *p++ = *q++;
diff --git a/pkgs/development/libraries/gnu-efi/default.nix b/pkgs/development/libraries/gnu-efi/default.nix
index d679d88e91d1..aa644a3a4a83 100644
--- a/pkgs/development/libraries/gnu-efi/default.nix
+++ b/pkgs/development/libraries/gnu-efi/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, pciutils }:
+{ stdenv, fetchurl, pciutils }: with stdenv.lib;
 
 stdenv.mkDerivation rec {
   name = "gnu-efi-${version}";
@@ -9,6 +9,8 @@ stdenv.mkDerivation rec {
     sha256 = "1bzq5czw5dxlvpgs9ij2iz7q6krwhja87vc982r6vffcqcl0982i";
   };
 
+  patches = optional stdenv.isAarch64 ./aarch64-fix-discarded-qualifier.patch;
+
   buildInputs = [ pciutils ];
 
   hardeningDisable = [ "stackprotector" ];
diff --git a/pkgs/development/libraries/libsigsegv/aarch64.patch b/pkgs/development/libraries/libsigsegv/aarch64.patch
new file mode 100644
index 000000000000..7bb48a230cee
--- /dev/null
+++ b/pkgs/development/libraries/libsigsegv/aarch64.patch
@@ -0,0 +1,12 @@
+diff --git a/configure b/configure
+index 6c4e868..0298e19 100755
+--- a/configure
++++ b/configure
+@@ -14501,6 +14501,7 @@ else
+ 
+     case "$host_cpu" in
+             a29k | \
++      aarch64* | \
+       alpha* | \
+       arc | \
+       arm* | strongarm* | xscale* | \
diff --git a/pkgs/development/libraries/libsigsegv/default.nix b/pkgs/development/libraries/libsigsegv/default.nix
index be3cbe39a302..3353fbf9e8d9 100644
--- a/pkgs/development/libraries/libsigsegv/default.nix
+++ b/pkgs/development/libraries/libsigsegv/default.nix
@@ -8,6 +8,12 @@ stdenv.mkDerivation rec {
     sha256 = "16hrs8k3nmc7a8jam5j1fpspd6sdpkamskvsdpcw6m29vnis8q44";
   };
 
+  # Based on https://github.com/davidgfnet/buildroot-Os/blob/69fe6065b9dd1cb4dcc0a4b554e42cc2e5bd0d60/package/libsigsegv/libsigsegv-0002-fix-aarch64-build.patch
+  # but applied directly to configure since we can't use autoreconf while bootstrapping.
+  patches = if stdenv.isAarch64 || stdenv.cross.arch or "" == "aarch64"
+    then [ ./aarch64.patch ]
+    else null; # TODO: change to lib.optional on next mass rebuild
+
   # https://github.com/NixOS/nixpkgs/issues/6028
   doCheck = false;
 
diff --git a/pkgs/development/libraries/libunwind/default.nix b/pkgs/development/libraries/libunwind/default.nix
index 6ed29a8abc3f..419a14551ba4 100644
--- a/pkgs/development/libraries/libunwind/default.nix
+++ b/pkgs/development/libraries/libunwind/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, fetchpatch, xz }:
+{ stdenv, fetchurl, fetchpatch, autoreconfHook, xz }:
 
 stdenv.mkDerivation rec {
   name = "libunwind-1.1";
@@ -8,13 +8,18 @@ stdenv.mkDerivation rec {
     sha256 = "16nhx2pahh9d62mvszc88q226q5lwjankij276fxwrm8wb50zzlx";
   };
 
+  buildInputs = stdenv.lib.optional stdenv.isAarch64 autoreconfHook;
+
   patches = [ ./libunwind-1.1-lzma.patch ./cve-2015-3239.patch
               # https://lists.nongnu.org/archive/html/libunwind-devel/2014-04/msg00000.html
               (fetchpatch {
                 url = "https://raw.githubusercontent.com/dropbox/pyston/1b2e676417b0f5f17526ece0ed840aa88c744145/libunwind_patches/0001-Change-the-RBP-validation-heuristic-to-allow-size-0-.patch";
                 sha256 = "1a0fsgfxmgd218nscswx7pgyb7rcn2gh6566252xhfvzhgn5i4ha";
               })
-            ];
+            ] ++ stdenv.lib.optional stdenv.isAarch64 (fetchpatch {
+              url = "https://raw.githubusercontent.com/archlinuxarm/PKGBUILDs/77709d1c6d5c39e23c1535b1bd584be1455f2551/extra/libunwind/libunwind-aarch64.patch";
+              sha256 = "1mpjs8izq9wxiaf5rl4gzaxrkz0s51f9qz5qc5dj72pr84mw50w8";
+            });
 
   postPatch = ''
     sed -i -e '/LIBLZMA/s:-lzma:-llzma:' configure
diff --git a/pkgs/misc/uboot/default.nix b/pkgs/misc/uboot/default.nix
index 597866a80ab4..6179f05d42b0 100644
--- a/pkgs/misc/uboot/default.nix
+++ b/pkgs/misc/uboot/default.nix
@@ -100,12 +100,18 @@ in rec {
     filesToInstall = ["u-boot.bin"];
   };
 
-  ubootRaspberryPi3 = buildUBoot rec {
+  ubootRaspberryPi3_32bit = buildUBoot rec {
     defconfig = "rpi_3_32b_defconfig";
     targetPlatforms = ["armv7l-linux"];
     filesToInstall = ["u-boot.bin"];
   };
 
+  ubootRaspberryPi3_64bit = buildUBoot rec {
+    defconfig = "rpi_3_defconfig";
+    targetPlatforms = ["aarch64-linux"];
+    filesToInstall = ["u-boot.bin"];
+  };
+
   ubootWandboard = buildUBoot rec {
     defconfig = "wandboard_defconfig";
     targetPlatforms = ["armv7l-linux"];
diff --git a/pkgs/os-specific/linux/busybox/busybox-in-store.patch b/pkgs/os-specific/linux/busybox/busybox-in-store.patch
index d3111efbdc48..0de7348c44fe 100644
--- a/pkgs/os-specific/linux/busybox/busybox-in-store.patch
+++ b/pkgs/os-specific/linux/busybox/busybox-in-store.patch
@@ -12,3 +12,12 @@ stdenv bootstrap.
  		exit(busybox_main(argv));
  #  endif
  #  if NUM_APPLETS > 0
+@@ -981,7 +981,7 @@ int main(int argc UNUSED_PARAM, char **argv)
+ 
+ 	lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv));
+ # if !ENABLE_BUSYBOX
+-	if (argv[1] && is_prefixed_with(bb_basename(argv[0]), "busybox"))
++	if (argv[1] && strstr(bb_basename(argv[0]), "busybox") != 0)
+ 		argv++;
+ # endif
+ 	applet_name = argv[0];
diff --git a/pkgs/os-specific/linux/firmware/raspberrypi/default.nix b/pkgs/os-specific/linux/firmware/raspberrypi/default.nix
index 1c1b11f1ef4b..03281d2ee3a4 100644
--- a/pkgs/os-specific/linux/firmware/raspberrypi/default.nix
+++ b/pkgs/os-specific/linux/firmware/raspberrypi/default.nix
@@ -31,7 +31,7 @@ stdenv.mkDerivation rec {
     description = "Firmware for the Raspberry Pi board";
     homepage = https://github.com/raspberrypi;
     license = licenses.unfree;
-    platforms = [ "armv6l-linux" "armv7l-linux" ];
+    platforms = [ "armv6l-linux" "armv7l-linux" "aarch64-linux" ];
     maintainers = with maintainers; [ viric tavyc ];
   };
 }
diff --git a/pkgs/os-specific/linux/fuse/default.nix b/pkgs/os-specific/linux/fuse/default.nix
index 34b6aa1378cd..3024c488a13e 100644
--- a/pkgs/os-specific/linux/fuse/default.nix
+++ b/pkgs/os-specific/linux/fuse/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, utillinux
+{ stdenv, fetchFromGitHub, fetchpatch, utillinux
 , autoconf, automake, libtool, gettext }:
 
 stdenv.mkDerivation rec {
@@ -14,6 +14,11 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ utillinux autoconf automake libtool gettext ];
 
+  patches = stdenv.lib.optional stdenv.isAarch64 (fetchpatch {
+    url = "https://github.com/libfuse/libfuse/commit/914871b20a901e3e1e981c92bc42b1c93b7ab81b.patch";
+    sha256 = "1w4j6f1awjrycycpvmlv0x5v9gprllh4dnbjxl4dyl2jgbkaw6pa";
+  });
+
   preConfigure =
     ''
       export MOUNT_FUSE_PATH=$out/sbin
diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix
index 44e4ebe17485..40c49509fd05 100644
--- a/pkgs/os-specific/linux/kernel/common-config.nix
+++ b/pkgs/os-specific/linux/kernel/common-config.nix
@@ -45,7 +45,7 @@ with stdenv.lib;
 
   # Bump the maximum number of CPUs to support systems like EC2 x1.*
   # instances and Xeon Phi.
-  ${optionalString (stdenv.system == "x86_64-linux") ''
+  ${optionalString (stdenv.system == "x86_64-linux" || stdenv.system == "aarch64-linux") ''
     NR_CPUS 384
   ''}
 
diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix
index 5f890b9b9fe6..83020ad35a2b 100644
--- a/pkgs/os-specific/linux/kernel/manual-config.nix
+++ b/pkgs/os-specific/linux/kernel/manual-config.nix
@@ -120,7 +120,7 @@ let
 
       # Some image types need special install targets (e.g. uImage is installed with make uinstall)
       installTargets = [ (if platform.kernelTarget == "uImage" then "uinstall" else
-                          if platform.kernelTarget == "zImage" then "zinstall" else
+                          if platform.kernelTarget == "zImage" || platform.kernelTarget == "Image.gz" then "zinstall" else
                           "install") ];
 
       postInstall = ''
diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix
index 7e0eaeddd2c4..90a55188f09e 100644
--- a/pkgs/stdenv/adapters.nix
+++ b/pkgs/stdenv/adapters.nix
@@ -92,6 +92,7 @@ rec {
               # without proper `file` command, libtool sometimes fails
               # to recognize 64-bit DLLs
             ++ stdenv.lib.optional (cross.config  == "x86_64-w64-mingw32") pkgs.file
+            ++ stdenv.lib.optional (cross.config  == "aarch64-linux-gnu") pkgs.updateAutotoolsGnuConfigScriptsHook
             ;
 
           # Cross-linking dynamic libraries, every buildInput should
diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix
index 78dbde13b89d..098caca0d890 100644
--- a/pkgs/stdenv/default.nix
+++ b/pkgs/stdenv/default.nix
@@ -44,6 +44,7 @@ in
     "armv5tel-linux" = stagesLinux;
     "armv6l-linux" = stagesLinux;
     "armv7l-linux" = stagesLinux;
+    "aarch64-linux" = stagesLinux;
     "mips64el-linux" = stagesLinux;
     "powerpc-linux" = /* stagesLinux */ stagesNative;
     "x86_64-darwin" = stagesDarwin;
diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix
index 269d7ef893a1..2010e35f58a3 100644
--- a/pkgs/stdenv/generic/default.nix
+++ b/pkgs/stdenv/generic/default.nix
@@ -311,6 +311,7 @@ let
              || system == "armv5tel-linux"
              || system == "armv6l-linux"
              || system == "armv7l-linux"
+             || system == "aarch64-linux"
              || system == "mips64el-linux";
       isGNU = system == "i686-gnu"; # GNU/Hurd
       isGlibc = isGNU # useful for `stdenvNative'
@@ -348,6 +349,7 @@ let
       isArm = system == "armv5tel-linux"
            || system == "armv6l-linux"
            || system == "armv7l-linux";
+      isAarch64 = system == "aarch64-linux";
       isBigEndian = system == "powerpc-linux";
 
       # Whether we should run paxctl to pax-mark binaries.
diff --git a/pkgs/stdenv/linux/bootstrap-files/aarch64.nix b/pkgs/stdenv/linux/bootstrap-files/aarch64.nix
new file mode 100644
index 000000000000..7f1acc83433b
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap-files/aarch64.nix
@@ -0,0 +1,11 @@
+{
+  busybox = import <nix/fetchurl.nix> {
+    url = http://nixos-arm.dezgeg.me/bootstrap-aarch64-for-merge/busybox;
+    sha256 = "12qcml1l67skpjhfjwy7gr10nc86gqcwjmz9ggp7knss8gq8pv7f";
+    executable = true;
+  };
+  bootstrapTools = import <nix/fetchurl.nix> {
+    url = http://nixos-arm.dezgeg.me/bootstrap-aarch64-for-merge/bootstrap-tools.tar.xz;
+    sha256 = "10sqgh0dchp1906h06jznxh8gfflnzbpfy27hng2mmc1l0c7irjr";
+  };
+}
diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix
index 611628b35aba..fe685a1e77ce 100644
--- a/pkgs/stdenv/linux/default.nix
+++ b/pkgs/stdenv/linux/default.nix
@@ -12,6 +12,7 @@
     "armv5tel-linux" = import ./bootstrap-files/armv5tel.nix;
     "armv6l-linux" = import ./bootstrap-files/armv6l.nix;
     "armv7l-linux" = import ./bootstrap-files/armv7l.nix;
+    "aarch64-linux" = import ./bootstrap-files/aarch64.nix;
     "mips64el-linux" = import ./bootstrap-files/loongson2f.nix;
   }.${localSystem.system}
     or (abort "unsupported platform for the pure Linux stdenv")
@@ -213,7 +214,9 @@ in
         isl = isl_0_14;
       };
     };
-    extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ];
+    extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ] ++
+      # Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64.
+      lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook;
   })
 
 
@@ -240,7 +243,9 @@ in
         shell = self.bash + "/bin/bash";
       };
     };
-    extraBuildInputs = [ prevStage.patchelf prevStage.xz ];
+    extraBuildInputs = [ prevStage.patchelf prevStage.xz ] ++
+      # Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64.
+      lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook;
   })
 
   # Construct the final stdenv.  It uses the Glibc and GCC, and adds
@@ -268,7 +273,9 @@ in
       initialPath =
         ((import ../common-path.nix) {pkgs = prevStage;});
 
-      extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ];
+      extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ] ++
+        # Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64.
+        lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook;
 
       cc = prevStage.gcc;
 
@@ -287,7 +294,7 @@ in
         [ gzip bzip2 xz bash binutils coreutils diffutils findutils gawk
           glibc gnumake gnused gnutar gnugrep gnupatch patchelf attr acl
           paxctl zlib pcre linuxHeaders ed gcc gcc.cc libsigsegv
-        ];
+        ] ++ lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook;
         */
 
       overrides = self: super: {
diff --git a/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix b/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix
index b5dfcb73a122..dda1f7e0b337 100644
--- a/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix
+++ b/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix
@@ -50,10 +50,23 @@ let
     };
   };
 
+  aarch64-multiplatform-crossSystem = {
+    crossSystem = rec {
+      config = "aarch64-linux-gnu";
+      bigEndian = false;
+      arch = "aarch64";
+      withTLS = true;
+      libc = "glibc";
+      platform = pkgsNoParams.platforms.aarch64-multiplatform;
+      inherit (platform) gcc;
+    };
+  };
+
   selectedCrossSystem =
     if toolsArch == "armv5tel" then sheevaplugCrossSystem else
     if toolsArch == "armv6l" then raspberrypiCrossSystem else
-    if toolsArch == "armv7l" then armv7l-hf-multiplatform-crossSystem else null;
+    if toolsArch == "armv7l" then armv7l-hf-multiplatform-crossSystem else
+    if toolsArch == "aarch64" then aarch64-multiplatform-crossSystem else null;
 
   pkgs = pkgsFun ({inherit system;} // selectedCrossSystem);
 
@@ -264,4 +277,5 @@ rec {
     armv5tel = buildFor "armv5tel";
     armv6l = buildFor "armv6l";
     armv7l = buildFor "armv7l";
+    aarch64 = buildFor "aarch64";
 }
diff --git a/pkgs/stdenv/linux/make-bootstrap-tools.nix b/pkgs/stdenv/linux/make-bootstrap-tools.nix
index d31253075c9d..2e7b24af131d 100644
--- a/pkgs/stdenv/linux/make-bootstrap-tools.nix
+++ b/pkgs/stdenv/linux/make-bootstrap-tools.nix
@@ -170,8 +170,9 @@ rec {
   };
 
   bootstrapFiles = {
-    busybox = "${build}/on-server/busybox";
-    bootstrapTools = "${build}/on-server/bootstrap-tools.tar.xz";
+    # Make them their own store paths to test that busybox still works when the binary is named /nix/store/HASH-busybox
+    busybox = runCommand "busybox" {} "cp ${build}/on-server/busybox $out";
+    bootstrapTools = runCommand "bootstrap-tools.tar.xz" {} "cp ${build}/on-server/bootstrap-tools.tar.xz $out";
   };
 
   bootstrapTools = import ./bootstrap-tools { inherit system bootstrapFiles; };
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 26ff5b718f39..53ce759578de 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -79,6 +79,10 @@ with pkgs;
       }
     '');
 
+  updateAutotoolsGnuConfigScriptsHook = makeSetupHook
+    { substitutions = { gnu_config = gnu-config;}; }
+    ../build-support/setup-hooks/update-autotools-gnu-config-scripts.sh;
+
   buildEnv = callPackage ../build-support/buildenv { }; # not actually a package
 
   buildFHSUserEnv = callPackage ../build-support/build-fhs-userenv { };
@@ -7459,6 +7463,8 @@ with pkgs;
 
   gnet = callPackage ../development/libraries/gnet { };
 
+  gnu-config = callPackage ../development/libraries/gnu-config { };
+
   gnu-efi = callPackage ../development/libraries/gnu-efi { };
 
   gnutls = gnutls34;
@@ -11799,7 +11805,8 @@ with pkgs;
     ubootPcduino3Nano
     ubootRaspberryPi
     ubootRaspberryPi2
-    ubootRaspberryPi3
+    ubootRaspberryPi3_32bit
+    ubootRaspberryPi3_64bit
     ubootWandboard
     ;
 
diff --git a/pkgs/top-level/platforms.nix b/pkgs/top-level/platforms.nix
index 671aaea4491a..41cd0fff52ba 100644
--- a/pkgs/top-level/platforms.nix
+++ b/pkgs/top-level/platforms.nix
@@ -443,12 +443,54 @@ rec {
     };
   };
 
-  selectPlatformBySystem = system:
-    if system == "armv6l-linux" then raspberrypi
-    else if system == "armv7l-linux" then armv7l-hf-multiplatform
-    else if system == "armv5tel-linux" then sheevaplug
-    else if system == "mips64el-linux" then fuloong2f_n32
-    else if system == "x86_64-linux" then pc64
-    else if system == "i686-linux" then pc32
-    else pcBase;
+  aarch64-multiplatform = {
+    name = "aarch64-multiplatform";
+    kernelMajor = "2.6"; # Using "2.6" enables 2.6 kernel syscalls in glibc.
+    kernelHeadersBaseConfig = "defconfig";
+    kernelBaseConfig = "defconfig";
+    kernelArch = "arm64";
+    kernelDTB = true;
+    kernelAutoModules = false;
+    kernelExtraConfig = ''
+      # Raspberry Pi 3 stuff. Not needed for kernels >= 4.10.
+      ARCH_BCM2835 y
+      BCM2835_MBOX y
+      BCM2835_WDT y
+      BRCMFMAC m
+      DMA_BCM2835 m
+      DRM_VC4 m
+      I2C_BCM2835 m
+      PWM_BCM2835 m
+      RASPBERRYPI_FIRMWARE y
+      RASPBERRYPI_POWER y
+      SERIAL_8250_BCM2835AUX y
+      SERIAL_8250_EXTENDED y
+      SERIAL_8250_SHARE_IRQ y
+      SND_BCM2835_SOC_I2S m
+      SPI_BCM2835AUX m
+      SPI_BCM2835 m
+
+      # Cavium ThunderX stuff.
+      PCI_HOST_THUNDER_ECAM y
+      THUNDER_NIC_RGX y
+      THUNDER_NIC_BGX y
+      THUNDER_NIC_PF y
+      THUNDER_NIC_VF y
+    '';
+    uboot = null;
+    kernelTarget = "Image";
+    gcc = {
+      arch = "armv8-a";
+    };
+  };
+
+  selectPlatformBySystem = system: {
+      "i686-linux" = pc32;
+      "x86_64-linux" = pc64;
+      "armv5tel-linux" = sheevaplug;
+      "armv6l-linux" = raspberrypi;
+      "armv7l-linux" = armv7l-hf-multiplatform;
+      "aarch64-linux" = aarch64-multiplatform;
+      "mips64el-linux" = fuloong2f_n32;
+    }.${system} or pcBase;
 }