From 750933a17ceb4a6fed892c11f5d5219dbd91ad5b Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Tue, 18 Sep 2018 18:49:58 -0400
Subject: [PATCH 1/5] haskell infra: Also pass `--with-ar` in cross builds

---
 pkgs/development/haskell-modules/generic-builder.nix | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix
index 1b33954662db..be104a82fd77 100644
--- a/pkgs/development/haskell-modules/generic-builder.nix
+++ b/pkgs/development/haskell-modules/generic-builder.nix
@@ -120,6 +120,7 @@ let
     "--with-ghc-pkg=${ghc.targetPrefix}ghc-pkg"
     "--with-gcc=${stdenv.cc.targetPrefix}cc"
     "--with-ld=${stdenv.cc.bintools.targetPrefix}ld"
+    "--with-ar=${stdenv.cc.bintools.targetPrefix}ar"
     # use the one that comes with the cross compiler.
     "--with-hsc2hs=${ghc.targetPrefix}hsc2hs"
     "--with-strip=${stdenv.cc.bintools.targetPrefix}strip"

From cc83d5933373e256e4d31599d3f4e85ee80915a6 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed, 19 Sep 2018 12:10:09 -0400
Subject: [PATCH 2/5] zlib: Fix iOS cross build

  1. CHOST is how one specifies the cross host platform with this
  non-standard configure script. We were just getting lucky with Linux
  cross.

  2. install_name_tool needs the the binutils prefix.
---
 pkgs/development/libraries/zlib/default.nix | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix
index d3fb0970cd00..d348f877f722 100644
--- a/pkgs/development/libraries/zlib/default.nix
+++ b/pkgs/development/libraries/zlib/default.nix
@@ -3,7 +3,7 @@
 , static ? false
 }:
 
-stdenv.mkDerivation rec {
+stdenv.mkDerivation (rec {
   name = "zlib-${version}";
   version = "1.2.11";
 
@@ -38,7 +38,7 @@ stdenv.mkDerivation rec {
     # what causes this difference.
   + stdenv.lib.optionalString stdenv.hostPlatform.isDarwin ''
     for file in $out/lib/*.so* $out/lib/*.dylib* ; do
-      install_name_tool -id "$file" $file
+      ${stdenv.cc.bintools.targetPrefix}install_name_tool -id "$file" $file
     done
   ''
     # Non-typical naming confuses libtool which then refuses to use zlib's DLL
@@ -78,4 +78,8 @@ stdenv.mkDerivation rec {
     license = licenses.zlib;
     platforms = platforms.all;
   };
-}
+} // stdenv.lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform) {
+  preConfigure = ''
+    export CHOST=${stdenv.hostPlatform.config}
+  '';
+})

From 45c637d8a018ac670c784a9ffc89ed3013e8d6a9 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Thu, 20 Sep 2018 21:48:06 -0400
Subject: [PATCH 3/5] haskellPackages.x509-system: Override based on the host,
 not target platform

There were many reverts back and forth, but it ultimately appears that I
am the source of this mistake. I clarified the comment so as not to
confuse myself or anyone else.
---
 pkgs/development/haskell-modules/configuration-nix.nix | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/pkgs/development/haskell-modules/configuration-nix.nix b/pkgs/development/haskell-modules/configuration-nix.nix
index d363d2e87b69..cf53f9e2b510 100644
--- a/pkgs/development/haskell-modules/configuration-nix.nix
+++ b/pkgs/development/haskell-modules/configuration-nix.nix
@@ -126,9 +126,9 @@ self: super: builtins.intersectAttrs super {
   # the system-fileio tests use canonicalizePath, which fails in the sandbox
   system-fileio = if pkgs.stdenv.isDarwin then dontCheck super.system-fileio else super.system-fileio;
 
-  # Prevents needing to add security_tool as a build tool to all of x509-system's
-  # dependencies.
-  x509-system = if pkgs.stdenv.targetPlatform.isDarwin && !pkgs.stdenv.cc.nativeLibc
+  # Prevents needing to add `security_tool` as a run-time dependency for
+  # everything using x509-system to give access to the `security` executable.
+  x509-system = if pkgs.stdenv.hostPlatform.isDarwin && !pkgs.stdenv.cc.nativeLibc
     then let inherit (pkgs.darwin) security_tool;
       in pkgs.lib.overrideDerivation (addBuildDepend super.x509-system security_tool) (drv: {
         postPatch = (drv.postPatch or "") + ''

From 452a81c991d34fc5e6c56b7fdbcdff97c693b51f Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Fri, 21 Sep 2018 12:32:17 -0400
Subject: [PATCH 4/5] libusb1: Build everywhere, since MinGW works

---
 pkgs/development/libraries/libusb1/default.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pkgs/development/libraries/libusb1/default.nix b/pkgs/development/libraries/libusb1/default.nix
index 69afd9d4c691..7ec714f02237 100644
--- a/pkgs/development/libraries/libusb1/default.nix
+++ b/pkgs/development/libraries/libusb1/default.nix
@@ -24,7 +24,7 @@ stdenv.mkDerivation rec {
   meta = {
     homepage = http://www.libusb.info;
     description = "User-space USB library";
-    platforms = stdenv.lib.platforms.unix;
+    platforms = stdenv.lib.platforms.all;
     maintainers = [ ];
   };
 }

From b97242238d7efb029c76eb8d4fe4b1228a5b49a8 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Fri, 21 Sep 2018 12:55:12 -0400
Subject: [PATCH 5/5] fetchzip: Use unzip from buildPackages

Additionally, the manual path manipulation becomes no longer needed.
---
 pkgs/build-support/fetchzip/default.nix | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/pkgs/build-support/fetchzip/default.nix b/pkgs/build-support/fetchzip/default.nix
index 4a5381d71f20..f1b9b9290d4c 100644
--- a/pkgs/build-support/fetchzip/default.nix
+++ b/pkgs/build-support/fetchzip/default.nix
@@ -14,7 +14,7 @@
 , name ? "source"
 , ... } @ args:
 
-lib.overrideDerivation (fetchurl ({
+(fetchurl ({
   inherit name;
 
   recursiveHash = true;
@@ -23,8 +23,6 @@ lib.overrideDerivation (fetchurl ({
 
   postFetch =
     ''
-      export PATH=${unzip}/bin:$PATH
-
       unpackDir="$TMPDIR/unpack"
       mkdir "$unpackDir"
       cd "$unpackDir"
@@ -48,6 +46,7 @@ lib.overrideDerivation (fetchurl ({
       mv "$unpackDir" "$out"
     '') #*/
     + extraPostFetch;
-} // removeAttrs args [ "stripRoot" "extraPostFetch" ]))
-# Hackety-hack: we actually need unzip hooks, too
-(x: {nativeBuildInputs = x.nativeBuildInputs++ [unzip];})
+} // removeAttrs args [ "stripRoot" "extraPostFetch" ])).overrideAttrs (x: {
+  # Hackety-hack: we actually need unzip hooks, too
+  nativeBuildInputs = x.nativeBuildInputs ++ [ unzip ];
+})