From 8ca8293dbc5982684d0ce87babf3daf7729e549a Mon Sep 17 00:00:00 2001
From: John Ericson <Ericson2314@Yahoo.com>
Date: Fri, 10 Feb 2017 23:48:28 -0500
Subject: [PATCH 01/69] libxml2: Don't use stdenv.cross

---
 pkgs/development/libraries/libxml2/default.nix | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/pkgs/development/libraries/libxml2/default.nix b/pkgs/development/libraries/libxml2/default.nix
index fb397ace7941..10dd4ee5dbe4 100644
--- a/pkgs/development/libraries/libxml2/default.nix
+++ b/pkgs/development/libraries/libxml2/default.nix
@@ -1,7 +1,9 @@
 { stdenv, lib, fetchurl, fetchpatch
 , zlib, xz, python2, findXMLCatalogs, libiconv
-, pythonSupport ? (! stdenv ? cross)
-, icuSupport ? false, icu ? null }:
+, buildPlatform, hostPlatform
+, pythonSupport ? buildPlatform == hostPlatform
+, icuSupport ? false, icu ? null
+}:
 
 let
   python = python2;
@@ -45,7 +47,7 @@ in stdenv.mkDerivation rec {
 
   doCheck = !stdenv.isDarwin;
 
-  crossAttrs = lib.optionalAttrs (stdenv.cross.libc == "msvcrt") {
+  crossAttrs = lib.optionalAttrs (hostPlatform.libc == "msvcrt") {
     # creating the DLL is broken ATM
     dontDisableStatic = true;
     configureFlags = configureFlags ++ [ "--disable-shared" ];

From 099b83f90d8996fcae2a03e5c85f13a8a3341d72 Mon Sep 17 00:00:00 2001
From: John Ericson <Ericson2314@Yahoo.com>
Date: Sat, 11 Feb 2017 01:51:13 -0500
Subject: [PATCH 02/69] libxslt: Don't use stdenv.cross

---
 pkgs/development/libraries/libxslt/default.nix | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pkgs/development/libraries/libxslt/default.nix b/pkgs/development/libraries/libxslt/default.nix
index 4647eecf87d4..a9e98d41e75e 100644
--- a/pkgs/development/libraries/libxslt/default.nix
+++ b/pkgs/development/libraries/libxslt/default.nix
@@ -1,6 +1,7 @@
 { stdenv, fetchurl, fetchpatch, libxml2, findXMLCatalogs, python2
+, buildPlatform, hostPlatform
 , cryptoSupport ? false
-, pythonSupport ? (! stdenv ? cross)
+, pythonSupport ? buildPlatform == hostPlatform
 }:
 
 assert pythonSupport -> python2 != null;

From a11426c52376d0d6b82d24519a333a3c1f7dec71 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Mon, 26 Jun 2017 18:38:34 -0400
Subject: [PATCH 03/69] ImageMagick: Don't use stdenv.cross

I'm guessing the salient aspect here is not cross compiling itself, but
just whether the host platform is MinGW, so I simplified the logic
accordingly
---
 pkgs/applications/graphics/ImageMagick/7.0.nix     | 7 ++++---
 pkgs/applications/graphics/ImageMagick/default.nix | 9 +++++----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/pkgs/applications/graphics/ImageMagick/7.0.nix b/pkgs/applications/graphics/ImageMagick/7.0.nix
index bcad077b38c9..5eaf488fff53 100644
--- a/pkgs/applications/graphics/ImageMagick/7.0.nix
+++ b/pkgs/applications/graphics/ImageMagick/7.0.nix
@@ -2,6 +2,7 @@
 , bzip2, zlib, libX11, libXext, libXt, fontconfig, freetype, ghostscript, libjpeg
 , lcms2, openexr, libpng, librsvg, libtiff, libxml2, openjpeg, libwebp
 , ApplicationServices
+, buildPlatform, hostPlatform
 }:
 
 let
@@ -47,7 +48,7 @@ stdenv.mkDerivation rec {
       [ "--with-gs-font-dir=${ghostscript}/share/ghostscript/fonts"
         "--with-gslib"
       ]
-    ++ lib.optionals (stdenv.cross.libc or null == "msvcrt")
+    ++ lib.optionals hostPlatform.isMinGW
       [ "--enable-static" "--disable-shared" ] # due to libxml2 being without DLLs ATM
     ;
 
@@ -57,13 +58,13 @@ stdenv.mkDerivation rec {
     [ zlib fontconfig freetype ghostscript
       libpng libtiff libxml2
     ]
-    ++ lib.optionals (stdenv.cross.libc or null != "msvcrt")
+    ++ lib.optionals (!hostPlatform.isMinGW)
       [ openexr librsvg openjpeg ]
     ++ lib.optional stdenv.isDarwin ApplicationServices;
 
   propagatedBuildInputs =
     [ bzip2 freetype libjpeg lcms2 ]
-    ++ lib.optionals (stdenv.cross.libc or null != "msvcrt")
+    ++ lib.optionals (!hostPlatform.isMinGW)
       [ libX11 libXext libXt libwebp ]
     ;
 
diff --git a/pkgs/applications/graphics/ImageMagick/default.nix b/pkgs/applications/graphics/ImageMagick/default.nix
index 8f4d44932f59..39812b2cfc47 100644
--- a/pkgs/applications/graphics/ImageMagick/default.nix
+++ b/pkgs/applications/graphics/ImageMagick/default.nix
@@ -2,6 +2,7 @@
 , bzip2, zlib, libX11, libXext, libXt, fontconfig, freetype, ghostscript, libjpeg
 , lcms2, openexr, libpng, librsvg, libtiff, libxml2, openjpeg, libwebp
 , ApplicationServices
+, buildPlatform, hostPlatform
 }:
 
 let
@@ -18,7 +19,7 @@ let
   }
     # Freeze version on mingw so we don't need to port the patch too often.
     # FIXME: This version has multiple security vulnerabilities
-    // lib.optionalAttrs (stdenv.cross.libc or null == "msvcrt") {
+    // lib.optionalAttrs (hostPlatform.isMinGW) {
         version = "6.9.2-0";
         sha256 = "17ir8bw1j7g7srqmsz3rx780sgnc21zfn0kwyj78iazrywldx8h7";
         patches = [(fetchpatch {
@@ -59,7 +60,7 @@ stdenv.mkDerivation rec {
       [ "--with-gs-font-dir=${ghostscript}/share/ghostscript/fonts"
         "--with-gslib"
       ]
-    ++ lib.optionals (stdenv.cross.libc or null == "msvcrt")
+    ++ lib.optionals (hostPlatform.isMinGW)
       [ "--enable-static" "--disable-shared" ] # due to libxml2 being without DLLs ATM
     ;
 
@@ -69,13 +70,13 @@ stdenv.mkDerivation rec {
     [ zlib fontconfig freetype ghostscript
       libpng libtiff libxml2
     ]
-    ++ lib.optionals (stdenv.cross.libc or null != "msvcrt")
+    ++ lib.optionals (!hostPlatform.isMinGW)
       [ openexr librsvg openjpeg ]
     ++ lib.optional stdenv.isDarwin ApplicationServices;
 
   propagatedBuildInputs =
     [ bzip2 freetype libjpeg lcms2 ]
-    ++ lib.optionals (stdenv.cross.libc or null != "msvcrt")
+    ++ lib.optionals (!hostPlatform.isMinGW)
       [ libX11 libXext libXt libwebp ]
     ;
 

From c4443d70df83bc9591cdf892a3f2b7c7d98fffbb Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Mon, 26 Jun 2017 18:41:09 -0400
Subject: [PATCH 04/69] fbida: cc-wrapper can be relied on to export these env
 vars

---
 pkgs/applications/graphics/fbida/default.nix | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/pkgs/applications/graphics/fbida/default.nix b/pkgs/applications/graphics/fbida/default.nix
index 5f0605bbf87c..d06c3eb5ec13 100644
--- a/pkgs/applications/graphics/fbida/default.nix
+++ b/pkgs/applications/graphics/fbida/default.nix
@@ -21,10 +21,6 @@ stdenv.mkDerivation rec {
     sed -e 's@ cpp\>@ gcc -E -@' -i GNUmakefile
     '';
 
-  crossAttrs = {
-    makeFlags = makeFlags ++ [ "CC=${stdenv.cross.config}-gcc" "STRIP=" ];
-  };
-
   meta = with stdenv.lib; {
     description = "Image viewing and manipulation programs";
     homepage = https://www.kraxel.org/blog/linux/fbida/;

From ca94de8c4c87f1cace032ccaa8e922e2db9405bb Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Mon, 26 Jun 2017 18:42:55 -0400
Subject: [PATCH 05/69] offrss: cc-wrapper can be relied on to export this env
 var

---
 pkgs/applications/networking/offrss/default.nix | 1 -
 1 file changed, 1 deletion(-)

diff --git a/pkgs/applications/networking/offrss/default.nix b/pkgs/applications/networking/offrss/default.nix
index fd1406127ad8..1cae91dbf861 100644
--- a/pkgs/applications/networking/offrss/default.nix
+++ b/pkgs/applications/networking/offrss/default.nix
@@ -13,7 +13,6 @@ stdenv.mkDerivation {
     preConfigure = ''
       sed 's/^PDF/#PDF/' -i Makefile
     '';
-    makeFlags = "CC=${stdenv.cross.config}-gcc";
   };
 
   buildInputs = [ curl libmrss podofo ]

From ffa535a0cc321a502d49240c859f2a761f0455d9 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Mon, 26 Jun 2017 18:45:40 -0400
Subject: [PATCH 06/69] fossil: Don't use stdenv.cross

---
 pkgs/applications/version-management/fossil/default.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pkgs/applications/version-management/fossil/default.nix b/pkgs/applications/version-management/fossil/default.nix
index 14a492f6cc2b..69c763acd836 100644
--- a/pkgs/applications/version-management/fossil/default.nix
+++ b/pkgs/applications/version-management/fossil/default.nix
@@ -37,7 +37,7 @@ stdenv.mkDerivation rec {
 
   crossAttrs = {
     doCheck = false;
-    makeFlagsArray = [ "TCC=${stdenv.cross.config}-gcc" ];
+    makeFlags = [ "TCC=$CC" ];
   };
 
   meta = {

From 9c163cebdd5924b223745ec59928f456cd4587fc Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Mon, 26 Jun 2017 18:47:43 -0400
Subject: [PATCH 07/69] omxplayer: Don't use stdenv.cross

---
 pkgs/applications/video/omxplayer/default.nix | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/pkgs/applications/video/omxplayer/default.nix b/pkgs/applications/video/omxplayer/default.nix
index 01a85f3d9528..29345f7548d5 100644
--- a/pkgs/applications/video/omxplayer/default.nix
+++ b/pkgs/applications/video/omxplayer/default.nix
@@ -1,4 +1,7 @@
-{ stdenv, fetchurl, raspberrypifw, pcre, boost, freetype, zlib }:
+{ stdenv, fetchurl
+, raspberrypifw, pcre, boost, freetype, zlib
+, hostPlatform
+}:
 
 let
   ffmpeg = stdenv.mkDerivation rec {
@@ -46,10 +49,10 @@ let
     crossAttrs = {
       configurePlatforms = [];
       configureFlags = configureFlags ++ [
-        "--cross-prefix=${stdenv.cross.config}-"
+        "--cross-prefix=${stdenv.cc.prefix}"
         "--enable-cross-compile"
         "--target_os=linux"
-        "--arch=${stdenv.cross.arch}"
+        "--arch=${hostPlatform.arch}"
         ];
     };
 

From deb8fae4c0b65f0b70642518a221db54058d2cac Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Mon, 26 Jun 2017 18:58:21 -0400
Subject: [PATCH 08/69] make-initrd: Don't use stdenv.cross

---
 pkgs/build-support/kernel/make-initrd.nix | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/pkgs/build-support/kernel/make-initrd.nix b/pkgs/build-support/kernel/make-initrd.nix
index 092ab4586b38..70727f9b49dc 100644
--- a/pkgs/build-support/kernel/make-initrd.nix
+++ b/pkgs/build-support/kernel/make-initrd.nix
@@ -12,7 +12,9 @@
 # `contents = {object = ...; symlink = /init;}' is a typical
 # argument.
 
-{ stdenv, perl, cpio, contents, ubootChooser, compressor, prepend }:
+{ stdenv, perl, cpio, contents, ubootChooser, compressor, prepend
+, hostPlatform
+}:
 
 let
   inputsFun = ubootName : [ perl cpio ]
@@ -22,9 +24,9 @@ in
 stdenv.mkDerivation {
   name = "initrd";
   builder = ./make-initrd.sh;
-  nativeBuildInputs = inputsFun stdenv.platform.uboot;
+  nativeBuildInputs = inputsFun hostPlatform.platform.uboot;
 
-  makeUInitrd = makeUInitrdFun stdenv.platform.uboot;
+  makeUInitrd = makeUInitrdFun hostPlatform.platform.uboot;
 
   # !!! should use XML.
   objects = map (x: x.object) contents;
@@ -36,9 +38,5 @@ stdenv.mkDerivation {
     map (x: [("closure-" + baseNameOf x.symlink) x.object]) contents;
   pathsFromGraph = ./paths-from-graph.pl;
 
-  crossAttrs = {
-    nativeBuildInputs = inputsFun stdenv.cross.platform.uboot;
-    makeUInitrd = makeUInitrdFun stdenv.cross.platform.uboot;
-  };
   inherit compressor prepend;
 }

From c3c5793ab29d3fe8b3c0faff2ad644cfe91618b9 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Mon, 26 Jun 2017 19:06:36 -0400
Subject: [PATCH 09/69] guile: Don't use stdenv.cross

---
 pkgs/development/interpreters/guile/2.0.nix     | 6 ++++--
 pkgs/development/interpreters/guile/default.nix | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/pkgs/development/interpreters/guile/2.0.nix b/pkgs/development/interpreters/guile/2.0.nix
index 04f31dda26a0..5746300fca09 100644
--- a/pkgs/development/interpreters/guile/2.0.nix
+++ b/pkgs/development/interpreters/guile/2.0.nix
@@ -1,5 +1,7 @@
 { fetchurl, stdenv, libtool, readline, gmp, pkgconfig, boehmgc, libunistring
-, libffi, gawk, makeWrapper, fetchpatch, coverageAnalysis ? null, gnu ? null }:
+, libffi, gawk, makeWrapper, fetchpatch, coverageAnalysis ? null, gnu ? null
+, hostPlatform
+}:
 
 # Do either a coverage analysis build or a standard build.
 (if coverageAnalysis != null
@@ -84,7 +86,7 @@
   setupHook = ./setup-hook-2.0.sh;
 
   crossAttrs.preConfigure =
-    stdenv.lib.optionalString (stdenv.cross.config == "i586-pc-gnu")
+    stdenv.lib.optionalString (hostPlatform.isHurd)
        # On GNU, libgc depends on libpthread, but the cross linker doesn't
        # know where to find libpthread, which leads to erroneous test failures
        # in `configure', where `-pthread' and `-lpthread' aren't explicitly
diff --git a/pkgs/development/interpreters/guile/default.nix b/pkgs/development/interpreters/guile/default.nix
index 8a2deeddff60..19217476b140 100644
--- a/pkgs/development/interpreters/guile/default.nix
+++ b/pkgs/development/interpreters/guile/default.nix
@@ -1,5 +1,7 @@
 { fetchurl, stdenv, libtool, readline, gmp, pkgconfig, boehmgc, libunistring
-, libffi, gawk, makeWrapper, fetchpatch, coverageAnalysis ? null, gnu ? null }:
+, libffi, gawk, makeWrapper, fetchpatch, coverageAnalysis ? null, gnu ? null
+, hostPlatform
+}:
 
 # Do either a coverage analysis build or a standard build.
 (if coverageAnalysis != null
@@ -80,7 +82,7 @@
   setupHook = ./setup-hook-2.2.sh;
 
   crossAttrs.preConfigure =
-    stdenv.lib.optionalString (stdenv.cross.config == "i586-pc-gnu")
+    stdenv.lib.optionalString (hostPlatform.isHurd)
        # On GNU, libgc depends on libpthread, but the cross linker doesn't
        # know where to find libpthread, which leads to erroneous test failures
        # in `configure', where `-pthread' and `-lpthread' aren't explicitly

From 5d1e51a199917fa945cb59567597e354c6e4f56d Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Mon, 26 Jun 2017 19:11:17 -0400
Subject: [PATCH 10/69] lua 5: Don't use stdenv.cross, and use less make flags

cc-wrapper will define environment variables matching those now
---
 pkgs/development/interpreters/lua-5/5.2.nix | 12 ++++--------
 pkgs/development/interpreters/lua-5/5.3.nix | 12 ++++--------
 2 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/pkgs/development/interpreters/lua-5/5.2.nix b/pkgs/development/interpreters/lua-5/5.2.nix
index d14230c158e1..3bd921860841 100644
--- a/pkgs/development/interpreters/lua-5/5.2.nix
+++ b/pkgs/development/interpreters/lua-5/5.2.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchurl, readline, compat ? false }:
+{ stdenv, fetchurl, readline, compat ? false
+, hostPlatform
+}:
 
 let
   dsoPatch = fetchurl {
@@ -55,21 +57,15 @@ stdenv.mkDerivation rec {
   '';
 
   crossAttrs = let
-    isMingw = stdenv.cross.libc == "msvcrt";
-    isDarwin = stdenv.cross.libc == "libSystem";
+    inherit (hostPlatform) isDarwin isMingw;
   in {
     configurePhase = ''
       makeFlagsArray=(
         INSTALL_TOP=$out
         INSTALL_MAN=$out/share/man/man1
-        CC=${stdenv.cross.config}-gcc
-        STRIP=:
-        RANLIB=${stdenv.cross.config}-ranlib
         V=${luaversion}
         R=${version}
         ${if isMingw then "mingw" else stdenv.lib.optionalString isDarwin ''
-        AR="${stdenv.cross.config}-ar rcu"
-        macosx
         ''}
       )
     '' + stdenv.lib.optionalString isMingw ''
diff --git a/pkgs/development/interpreters/lua-5/5.3.nix b/pkgs/development/interpreters/lua-5/5.3.nix
index a22e162b8e18..8290bd05c590 100644
--- a/pkgs/development/interpreters/lua-5/5.3.nix
+++ b/pkgs/development/interpreters/lua-5/5.3.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchurl, readline, compat ? false }:
+{ stdenv, fetchurl, readline, compat ? false
+, hostPlatform
+}:
 
 stdenv.mkDerivation rec {
   name = "lua-${version}";
@@ -54,21 +56,15 @@ stdenv.mkDerivation rec {
   '';
 
   crossAttrs = let
-    isMingw = stdenv.cross.libc == "msvcrt";
-    isDarwin = stdenv.cross.libc == "libSystem";
+    inherit (hostPlatform) isDarwin isMingw;
   in {
     configurePhase = ''
       makeFlagsArray=(
         INSTALL_TOP=$out
         INSTALL_MAN=$out/share/man/man1
-        CC=${stdenv.cross.config}-gcc
-        STRIP=:
-        RANLIB=${stdenv.cross.config}-ranlib
         V=${luaversion}
         R=${version}
         ${if isMingw then "mingw" else stdenv.lib.optionalString isDarwin ''
-        AR="${stdenv.cross.config}-ar rcu"
-        macosx
         ''}
       )
     '' + stdenv.lib.optionalString isMingw ''

From 80a857f8d7b797cfd661e2686c0f2e66d41255b5 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Mon, 26 Jun 2017 19:14:45 -0400
Subject: [PATCH 11/69] SDL: Don't use stdenv.cross

---
 pkgs/development/libraries/SDL/default.nix | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pkgs/development/libraries/SDL/default.nix b/pkgs/development/libraries/SDL/default.nix
index 8330dada4d35..eb470519b4ec 100644
--- a/pkgs/development/libraries/SDL/default.nix
+++ b/pkgs/development/libraries/SDL/default.nix
@@ -4,6 +4,7 @@
 , x11Support ? true, libXext, libICE, libXrandr
 , pulseaudioSupport ? true, libpulseaudio
 , OpenGL, CoreAudio, CoreServices, AudioUnit, Kernel, Cocoa
+, hostPlatform
 }:
 
 # OSS is no longer supported, for it's much crappier than ALSA and
@@ -37,7 +38,7 @@ stdenv.mkDerivation rec {
     optional stdenv.isDarwin Cocoa;
 
   buildInputs = let
-    notMingw = !(stdenv ? cross) || stdenv.cross.libc != "msvcrt";
+    notMingw = !hostPlatform.isMinGW;
   in optional notMingw audiofile
   ++ optionals stdenv.isDarwin [ OpenGL CoreAudio CoreServices AudioUnit Kernel ];
 

From 67b5f39c7288073909302bc6ce2e7df094874c24 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed, 28 Jun 2017 11:18:11 -0400
Subject: [PATCH 12/69] scummvm: Don't use stdenv.cross

---
 pkgs/games/scummvm/default.nix | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/pkgs/games/scummvm/default.nix b/pkgs/games/scummvm/default.nix
index 29ba75f9aa24..e965fc459ad8 100644
--- a/pkgs/games/scummvm/default.nix
+++ b/pkgs/games/scummvm/default.nix
@@ -1,4 +1,7 @@
-{ stdenv, fetchurl, SDL, zlib, libmpeg2, libmad, libogg, libvorbis, flac, alsaLib, mesa }:
+{ stdenv
+, fetchurl, SDL, zlib, libmpeg2, libmad, libogg, libvorbis, flac, alsaLib, mesa
+, hostPlatform
+}:
 
 stdenv.mkDerivation rec {
   name = "scummvm-1.9.0";
@@ -16,7 +19,7 @@ stdenv.mkDerivation rec {
     preConfigure = ''
       # Remove the --build flag set by the gcc cross wrapper setup
       # hook
-      export configureFlags="--host=${stdenv.cross.config}"
+      export configureFlags="--host=${hostPlatform.config}"
     '';
     postConfigure = ''
       # They use 'install -s', that calls the native strip instead of the cross

From fcef0add76de4728b11cf9acba840a7e7d06abbb Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed, 28 Jun 2017 11:23:32 -0400
Subject: [PATCH 13/69] boost: Don't use stdenv.cross, and utilize new platform
 metadata

---
 pkgs/development/libraries/boost/generic.nix | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/pkgs/development/libraries/boost/generic.nix b/pkgs/development/libraries/boost/generic.nix
index 174e9fe47769..14d0c251c96f 100644
--- a/pkgs/development/libraries/boost/generic.nix
+++ b/pkgs/development/libraries/boost/generic.nix
@@ -1,10 +1,11 @@
 { stdenv, fetchurl, icu, expat, zlib, bzip2, python, fixDarwinDylibNames, libiconv
+, hostPlatform
 , toolset ? if stdenv.cc.isClang then "clang" else null
 , enableRelease ? true
 , enableDebug ? false
 , enableSingleThreaded ? false
 , enableMultiThreaded ? true
-, enableShared ? !(stdenv.cross.libc or null == "msvcrt") # problems for now
+, enableShared ? !(hostPlatform.libc == "msvcrt") # problems for now
 , enableStatic ? !enableShared
 , enablePIC ? false
 , enableExceptions ? false
@@ -76,11 +77,11 @@ let
     "--user-config=user-config.jam"
     "toolset=gcc-cross"
     "--without-python"
-  ] ++ optionals (stdenv.cross.libc == "msvcrt") [
+  ] ++ optionals (hostPlatform.libc == "msvcrt") [
     "target-os=windows"
     "threadapi=win32"
     "binary-format=pe"
-    "address-model=${if hasPrefix "x86_64-" stdenv.cross.config then "64" else "32"}"
+    "address-model=${toString hostPlatform.parsed.cpu.bits}"
     "architecture=x86"
   ];
   crossB2Args = concatStringsSep " " (genericB2Flags ++ crossB2Flags);
@@ -110,8 +111,8 @@ let
       find include \( -name '*.hpp' -or -name '*.h' -or -name '*.ipp' \) \
         -exec sed '1i#line 1 "{}"' -i '{}' \;
     )
-  '' + optionalString (stdenv.cross.libc or null == "msvcrt") ''
-    ${stdenv.cross.config}-ranlib "$out/lib/"*.a
+  '' + optionalString (hostPlatform.libc == "msvcrt") ''
+    ${stdenv.cc.prefix}ranlib "$out/lib/"*.a
   '';
 
 in
@@ -177,7 +178,7 @@ stdenv.mkDerivation {
     buildPhase = builder crossB2Args;
     installPhase = installer crossB2Args;
     postFixup = fixup;
-  } // optionalAttrs (stdenv.cross.libc == "msvcrt") {
+  } // optionalAttrs (hostPlatform.libc == "msvcrt") {
     patches = fetchurl {
       url = "https://svn.boost.org/trac/boost/raw-attachment/ticket/7262/"
           + "boost-mingw.patch";

From 38dbd4b1610362c67e6a17d0e103f459ff471002 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed, 28 Jun 2017 11:34:23 -0400
Subject: [PATCH 14/69] ffmpeg: Don't use stdenv.cross

---
 .../libraries/ffmpeg-full/default.nix         | 26 ++++---------------
 pkgs/development/libraries/ffmpeg/generic.nix | 26 ++++---------------
 2 files changed, 10 insertions(+), 42 deletions(-)

diff --git a/pkgs/development/libraries/ffmpeg-full/default.nix b/pkgs/development/libraries/ffmpeg-full/default.nix
index 3f847bc752f0..6246026e9ea7 100644
--- a/pkgs/development/libraries/ffmpeg-full/default.nix
+++ b/pkgs/development/libraries/ffmpeg-full/default.nix
@@ -1,4 +1,5 @@
 { stdenv, fetchurl, pkgconfig, perl, texinfo, yasm
+, hostPlatform
 /*
  *  Licensing options (yes some are listed twice, filters and such are not listed)
  */
@@ -428,30 +429,13 @@ stdenv.mkDerivation rec {
 
   /* Cross-compilation is untested, consider this an outline, more work
      needs to be done to portions of the build to get it to work correctly */
-  crossAttrs = let
-    os = ''
-      if [ "${stdenv.cross.config}" = "*cygwin*" ] ; then
-        # Probably should look for mingw too
-        echo "cygwin"
-      elif [ "${stdenv.cross.config}" = "*darwin*" ] ; then
-        echo "darwin"
-      elif [ "${stdenv.cross.config}" = "*freebsd*" ] ; then
-        echo "freebsd"
-      elif [ "${stdenv.cross.config}" = "*linux*" ] ; then
-        echo "linux"
-      elif [ "${stdenv.cross.config}" = "*netbsd*" ] ; then
-        echo "netbsd"
-      elif [ "${stdenv.cross.config}" = "*openbsd*" ] ; then
-        echo "openbsd"
-      fi
-    '';
-  in {
+  crossAttrs = {
     configurePlatforms = [];
     configureFlags = configureFlags ++ [
-      "--cross-prefix=${stdenv.cross.config}-"
+      "--cross-prefix=${stdenv.cc.prefix}"
       "--enable-cross-compile"
-      "--target_os=${os}"
-      "--arch=${stdenv.cross.arch}"
+      "--target_os=${hostPlatform.parsed.kernel.name}"
+      "--arch=${hostPlatform.arch}"
     ];
   };
 
diff --git a/pkgs/development/libraries/ffmpeg/generic.nix b/pkgs/development/libraries/ffmpeg/generic.nix
index 762a4c9503fb..a34b378552a0 100644
--- a/pkgs/development/libraries/ffmpeg/generic.nix
+++ b/pkgs/development/libraries/ffmpeg/generic.nix
@@ -2,6 +2,7 @@
 , alsaLib, bzip2, fontconfig, freetype, gnutls, libiconv, lame, libass, libogg
 , libtheora, libva, libvorbis, libvpx, lzma, libpulseaudio, soxr
 , x264, x265, xvidcore, zlib, libopus
+, hostPlatform
 , openglSupport ? false, mesa ? null
 # Build options
 , runtimeCpuDetectBuild ? true # Detect CPU capabilities at runtime
@@ -169,30 +170,13 @@ stdenv.mkDerivation rec {
 
   /* Cross-compilation is untested, consider this an outline, more work
      needs to be done to portions of the build to get it to work correctly */
-  crossAttrs = let
-    os = ''
-      if [ "${stdenv.cross.config}" = "*cygwin*" ] ; then
-        # Probably should look for mingw too
-        echo "cygwin"
-      elif [ "${stdenv.cross.config}" = "*darwin*" ] ; then
-        echo "darwin"
-      elif [ "${stdenv.cross.config}" = "*freebsd*" ] ; then
-        echo "freebsd"
-      elif [ "${stdenv.cross.config}" = "*linux*" ] ; then
-        echo "linux"
-      elif [ "${stdenv.cross.config}" = "*netbsd*" ] ; then
-        echo "netbsd"
-      elif [ "${stdenv.cross.config}" = "*openbsd*" ] ; then
-        echo "openbsd"
-      fi
-    '';
-  in {
+  crossAttrs = {
     configurePlatforms = [];
     configureFlags = configureFlags ++ [
-      "--cross-prefix=${stdenv.cross.config}-"
+      "--cross-prefix=${stdenv.cc.prefix}"
       "--enable-cross-compile"
-      "--target_os=${os}"
-      "--arch=${stdenv.cross.arch}"
+      "--target_os=${hostPlatform.parsed.kernel}"
+      "--arch=${hostPlatform.arch}"
     ];
   };
 

From 5c99b2f341572b025bf1c975e8604d55ecd9955d Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed, 28 Jun 2017 11:40:32 -0400
Subject: [PATCH 15/69] libvpx: Don't use stdenv.cross

---
 pkgs/development/libraries/libvpx/default.nix | 30 +++++++++----------
 pkgs/development/libraries/libvpx/git.nix     | 30 +++++++++----------
 2 files changed, 28 insertions(+), 32 deletions(-)

diff --git a/pkgs/development/libraries/libvpx/default.nix b/pkgs/development/libraries/libvpx/default.nix
index 09fc3a2a9da9..4b50fe090e38 100644
--- a/pkgs/development/libraries/libvpx/default.nix
+++ b/pkgs/development/libraries/libvpx/default.nix
@@ -1,4 +1,5 @@
-{stdenv, fetchFromGitHub, perl, yasm
+{ stdenv, fetchFromGitHub, perl, yasm
+, hostPlatform
 , vp8DecoderSupport ? true # VP8 decoder
 , vp8EncoderSupport ? true # VP8 encoder
 , vp9DecoderSupport ? true # VP9 decoder
@@ -144,10 +145,7 @@ stdenv.mkDerivation rec {
 
   postInstall = ''moveToOutput bin "$bin" '';
 
-  crossAttrs = let
-    isCygwin = stdenv.cross.libc == "msvcrt";
-    isDarwin = stdenv.cross.libc == "libSystem";
-  in {
+  crossAttrs = {
     configurePlatforms = [];
     configureFlags = configureFlags ++ [
       #"--extra-cflags="
@@ -159,17 +157,17 @@ stdenv.mkDerivation rec {
       # libvpx darwin targets include darwin version (ie. ARCH-darwinXX-gcc, XX being the darwin version)
       # See all_platforms: https://github.com/webmproject/libvpx/blob/master/configure
       # Darwin versions: 10.4=8, 10.5=9, 10.6=10, 10.7=11, 10.8=12, 10.9=13, 10.10=14
-      "--force-target=${stdenv.cross.config}${(
-              if isDarwin then (
-                if      stdenv.cross.osxMinVersion == "10.10" then "14"
-                else if stdenv.cross.osxMinVersion == "10.9"  then "13"
-                else if stdenv.cross.osxMinVersion == "10.8"  then "12"
-                else if stdenv.cross.osxMinVersion == "10.7"  then "11"
-                else if stdenv.cross.osxMinVersion == "10.6"  then "10"
-                else if stdenv.cross.osxMinVersion == "10.5"  then "9"
-                else "8")
-              else "")}-gcc"
-      (if isCygwin then "--enable-static-msvcrt" else "")
+      "--force-target=${hostPlatform.config}${
+              if hostPlatform.isDarwin then
+                if      hostPlatform.osxMinVersion == "10.10" then "14"
+                else if hostPlatform.osxMinVersion == "10.9"  then "13"
+                else if hostPlatform.osxMinVersion == "10.8"  then "12"
+                else if hostPlatform.osxMinVersion == "10.7"  then "11"
+                else if hostPlatform.osxMinVersion == "10.6"  then "10"
+                else if hostPlatform.osxMinVersion == "10.5"  then "9"
+                else "8"
+              else ""}-gcc"
+      (if hostPlatform.isCygwin then "--enable-static-msvcrt" else "")
     ];
   };
 
diff --git a/pkgs/development/libraries/libvpx/git.nix b/pkgs/development/libraries/libvpx/git.nix
index ceda1c263893..824449a347af 100644
--- a/pkgs/development/libraries/libvpx/git.nix
+++ b/pkgs/development/libraries/libvpx/git.nix
@@ -1,4 +1,5 @@
-{stdenv, fetchgit, perl, yasm
+{ stdenv, fetchgit, perl, yasm
+, hostPlatform
 , vp8DecoderSupport ? true # VP8 decoder
 , vp8EncoderSupport ? true # VP8 encoder
 , vp9DecoderSupport ? true # VP9 decoder
@@ -152,10 +153,7 @@ stdenv.mkDerivation rec {
 
   postInstall = ''moveToOutput bin "$bin" '';
 
-  crossAttrs = let
-    isCygwin = stdenv.cross.libc == "msvcrt";
-    isDarwin = stdenv.cross.libc == "libSystem";
-  in {
+  crossAttrs = {
     configurePlatforms = [];
     configureFlags = configureFlags ++ [
       #"--extra-cflags="
@@ -166,17 +164,17 @@ stdenv.mkDerivation rec {
       # libvpx darwin targets include darwin version (ie. ARCH-darwinXX-gcc, XX being the darwin version)
       # See all_platforms: https://github.com/webmproject/libvpx/blob/master/configure
       # Darwin versions: 10.4=8, 10.5=9, 10.6=10, 10.7=11, 10.8=12, 10.9=13, 10.10=14
-      "--force-target=${stdenv.cross.config}${(
-              if isDarwin then (
-                if      stdenv.cross.osxMinVersion == "10.10" then "14"
-                else if stdenv.cross.osxMinVersion == "10.9"  then "13"
-                else if stdenv.cross.osxMinVersion == "10.8"  then "12"
-                else if stdenv.cross.osxMinVersion == "10.7"  then "11"
-                else if stdenv.cross.osxMinVersion == "10.6"  then "10"
-                else if stdenv.cross.osxMinVersion == "10.5"  then "9"
-                else "8")
-              else "")}-gcc"
-      (if isCygwin then "--enable-static-msvcrt" else "")
+      "--force-target=${hostPlatform.config}${
+              if hostPlatform.isDarwin then
+                if      hostPlatform.osxMinVersion == "10.10" then "14"
+                else if hostPlatform.osxMinVersion == "10.9"  then "13"
+                else if hostPlatform.osxMinVersion == "10.8"  then "12"
+                else if hostPlatform.osxMinVersion == "10.7"  then "11"
+                else if hostPlatform.osxMinVersion == "10.6"  then "10"
+                else if hostPlatform.osxMinVersion == "10.5"  then "9"
+                else "8"
+              else ""}-gcc"
+      (if hostPlatform.isCygwin then "--enable-static-msvcrt" else "")
     ];
   };
 

From a40ceb2782a0f2554f854628a3bd5d8d941677d4 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed, 28 Jun 2017 11:48:13 -0400
Subject: [PATCH 16/69] glew: Rely on cc-wrapper can to export these env vars

---
 pkgs/development/libraries/glew/1.10.nix    | 14 ++++++--------
 pkgs/development/libraries/glew/default.nix | 14 ++++++--------
 2 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/pkgs/development/libraries/glew/1.10.nix b/pkgs/development/libraries/glew/1.10.nix
index 9d5ded5be15e..8500a54f970c 100644
--- a/pkgs/development/libraries/glew/1.10.nix
+++ b/pkgs/development/libraries/glew/1.10.nix
@@ -1,5 +1,7 @@
 { stdenv, fetchurl, mesa_glu, x11, libXmu, libXi
-, AGL ? null }:
+, buildPlatform, hostPlatform
+, AGL ? null
+}:
 
 with stdenv.lib;
 
@@ -36,13 +38,9 @@ stdenv.mkDerivation rec {
     cp -r README.txt LICENSE.txt doc $out/share/doc/glew
   '';
 
-  crossAttrs.makeFlags = [
-    "CC=${stdenv.cross.config}-gcc"
-    "LD=${stdenv.cross.config}-gcc"
-    "AR=${stdenv.cross.config}-ar"
-    "STRIP="
-  ] ++ optional (stdenv.cross.libc == "msvcrt") "SYSTEM=mingw"
-    ++ optional (stdenv.cross.libc == "libSystem") "SYSTEM=darwin";
+  makeFlags = if hostPlatform == buildPlatform then null else [
+    "SYSTEM=${if hostPlatform.isMinGW then "mingw" else hostPlatform.parsed.kernel}"
+  ];
 
   meta = with stdenv.lib; {
     description = "An OpenGL extension loading library for C(++)";
diff --git a/pkgs/development/libraries/glew/default.nix b/pkgs/development/libraries/glew/default.nix
index 02c87cf709a7..f8df5d5baf0d 100644
--- a/pkgs/development/libraries/glew/default.nix
+++ b/pkgs/development/libraries/glew/default.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchurl, mesa_glu, xlibsWrapper, libXmu, libXi }:
+{ stdenv, fetchurl, mesa_glu, xlibsWrapper, libXmu, libXi
+, buildPlatform, hostPlatform
+}:
 
 with stdenv.lib;
 
@@ -37,13 +39,9 @@ stdenv.mkDerivation rec {
     rm $out/lib/*.a
   '';
 
-  crossAttrs.makeFlags = [
-    "CC=${stdenv.cross.config}-gcc"
-    "LD=${stdenv.cross.config}-gcc"
-    "AR=${stdenv.cross.config}-ar"
-    "STRIP="
-  ] ++ optional (stdenv.cross.libc == "msvcrt") "SYSTEM=mingw"
-    ++ optional (stdenv.cross.libc == "libSystem") "SYSTEM=darwin";
+  makeFlags = if hostPlatform == buildPlatform then null else [
+    "SYSTEM=${if hostPlatform.isMinGW then "mingw" else hostPlatform.parsed.kernel}"
+  ];
 
   meta = with stdenv.lib; {
     description = "An OpenGL extension loading library for C(++)";

From c23028bdadd3864e15bf25caa1785208db4ae773 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed, 28 Jun 2017 11:54:21 -0400
Subject: [PATCH 17/69] cc-wrapper: Also export env var for windres, when it is
 present

---
 pkgs/build-support/cc-wrapper/default.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index 0c624a1454a3..ad6f6832298a 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -71,7 +71,7 @@ let
 
     '' + stdenv.lib.optionalString (textFile == ./setup-hook.sh) ''
       cat << 'EOF' >> $out
-        for CMD in ar as nm objcopy ranlib strip strings size ld
+        for CMD in ar as nm objcopy ranlib strip strings size ld windres
         do
           # which is not part of stdenv, but compgen will do for now
           if

From 60eff17b2799d6e5813a0899d506d455ad360f4b Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed, 28 Jun 2017 11:57:01 -0400
Subject: [PATCH 18/69] openssl: cc-wrapper can be relied on to export these
 env vars

---
 pkgs/development/libraries/openssl/default.nix | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/pkgs/development/libraries/openssl/default.nix b/pkgs/development/libraries/openssl/default.nix
index 8582c0a1833e..b3ce2fdbbb06 100644
--- a/pkgs/development/libraries/openssl/default.nix
+++ b/pkgs/development/libraries/openssl/default.nix
@@ -1,12 +1,14 @@
 { stdenv, fetchurl, buildPackages, perl
+, hostPlatform
 , withCryptodev ? false, cryptodevHeaders
-, enableSSL2 ? false }:
+, enableSSL2 ? false
+}:
 
 with stdenv.lib;
 
 let
 
-  opensslCrossSystem = stdenv.cross.openssl.system or
+  opensslCrossSystem = hostPlatform.openssl.system or
     (throw "openssl needs its platform name cross building");
 
   common = args@{ version, sha256, patches ? [] }: stdenv.mkDerivation rec {
@@ -23,8 +25,7 @@ let
       ++ optional (versionOlder version "1.1.0")
           (if stdenv.isDarwin then ./use-etc-ssl-certs-darwin.patch else ./use-etc-ssl-certs.patch)
       ++ optional stdenv.isCygwin ./1.0.1-cygwin64.patch
-      ++ optional
-           (versionOlder version "1.0.2" && (stdenv.isDarwin || (stdenv ? cross && stdenv.cross.libc == "libSystem")))
+      ++ optional (versionOlder version "1.0.2" && hostPlatform.isDarwin)
            ./darwin-arch.patch;
 
     outputs = [ "bin" "dev" "out" "man" ];
@@ -89,10 +90,6 @@ let
       preConfigure=''
         # It's configure does not like --build or --host
         export configureFlags="${concatStringsSep " " (configureFlags ++ [ opensslCrossSystem ])}"
-        # WINDRES and RANLIB need to be prefixed when cross compiling;
-        # the openssl configure script doesn't do that for us
-        export WINDRES=${stdenv.cross.config}-windres
-        export RANLIB=${stdenv.cross.config}-ranlib
       '';
       configureScript = "./Configure";
     };

From aac32fe2d1677fdf82c8ef1560c048f16ddc5e47 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed, 28 Jun 2017 12:02:31 -0400
Subject: [PATCH 19/69] vim: cc-wrapper can be relied on to export this env var

---
 pkgs/applications/editors/vim/default.nix | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/pkgs/applications/editors/vim/default.nix b/pkgs/applications/editors/vim/default.nix
index b8fee7bd1e24..4eefb207fd75 100644
--- a/pkgs/applications/editors/vim/default.nix
+++ b/pkgs/applications/editors/vim/default.nix
@@ -36,9 +36,6 @@ stdenv.mkDerivation rec {
     "ac_cv_sizeof_int=4"
     "vim_cv_memmove_handles_overlap=yes"
     "vim_cv_memmove_handles_overlap=yes"
-
-    # TODO(@Ericson2314): wont' be needed soon.
-    "STRIP=${hostPlatform.config}-strip"
   ];
 
   postInstall = ''

From f16ee76ca8b283a751f1fd4fc21de30243cc4640 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed, 28 Jun 2017 13:59:42 -0400
Subject: [PATCH 20/69] qt 4.8: Don't use stdenv.cross

---
 .../libraries/qt-4.x/4.8/default.nix          | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/pkgs/development/libraries/qt-4.x/4.8/default.nix b/pkgs/development/libraries/qt-4.x/4.8/default.nix
index dee83306cc6e..d3eaeed2f1e0 100644
--- a/pkgs/development/libraries/qt-4.x/4.8/default.nix
+++ b/pkgs/development/libraries/qt-4.x/4.8/default.nix
@@ -1,4 +1,5 @@
 { stdenv, fetchurl, fetchpatch, substituteAll
+, hostPlatform
 , libXrender, libXinerama, libXcursor, libXmu, libXv, libXext
 , libXfixes, libXrandr, libSM, freetype, fontconfig, zlib, libjpeg, libpng
 , libmng, which, mesaSupported, mesa, mesa_glu, openssl, dbus, cups, pkgconfig
@@ -182,9 +183,7 @@ stdenv.mkDerivation rec {
       rm -rf $out/tests
     '';
 
-  crossAttrs = let
-    isMingw = stdenv.cross.libc == "msvcrt";
-  in {
+  crossAttrs = {
     # I've not tried any case other than i686-pc-mingw32.
     # -nomake tools:   it fails linking some asian language symbols
     # -no-svg: it fails to build on mingw64
@@ -194,14 +193,14 @@ stdenv.mkDerivation rec {
       -no-svg
       -make qmake -make libs -nomake tools
       -nomake demos -nomake examples -nomake docs
-    '' + optionalString isMingw " -xplatform win32-g++-4.6";
+    '' + optionalString hostPlatform.isMinGW " -xplatform win32-g++-4.6";
     patches = [];
     preConfigure = ''
-      sed -i -e 's/ g++/ ${stdenv.cross.config}-g++/' \
-        -e 's/ gcc/ ${stdenv.cross.config}-gcc/' \
-        -e 's/ ar/ ${stdenv.cross.config}-ar/' \
-        -e 's/ strip/ ${stdenv.cross.config}-strip/' \
-        -e 's/ windres/ ${stdenv.cross.config}-windres/' \
+      sed -i -e 's/ g++/ ${stdenv.cc.prefix}g++/' \
+        -e 's/ gcc/ ${stdenv.cc.prefix}gcc/' \
+        -e 's/ ar/ ${stdenv.cc.prefix}ar/' \
+        -e 's/ strip/ ${stdenv.cc.prefix}strip/' \
+        -e 's/ windres/ ${stdenv.cc.prefix}windres/' \
         mkspecs/win32-g++/qmake.conf
     '';
 
@@ -211,7 +210,7 @@ stdenv.mkDerivation rec {
     '';
     configurePlatforms = [];
     dontStrip = true;
-  } // optionalAttrs isMingw {
+  } // optionalAttrs hostPlatform.isMinGW {
     propagatedBuildInputs = [ ];
   };
 

From 895c361480d489b620c96966ea653bb91db2628a Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed, 28 Jun 2017 14:11:08 -0400
Subject: [PATCH 21/69] WIP: optipng: cc-wrapper can be relied on to export
 these env vars

---
 pkgs/tools/graphics/optipng/default.nix | 26 ++++++++++++-------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/pkgs/tools/graphics/optipng/default.nix b/pkgs/tools/graphics/optipng/default.nix
index 0f7f7e2da2a2..471e8ee8df47 100644
--- a/pkgs/tools/graphics/optipng/default.nix
+++ b/pkgs/tools/graphics/optipng/default.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchurl, libpng, static ? false }:
+{ stdenv, fetchurl, libpng, static ? false
+, buildPlatform, hostPlatform
+}:
 
 # This package comes with its own copy of zlib, libpng and pngxtern
 
@@ -15,20 +17,16 @@ stdenv.mkDerivation rec {
   buildInputs = [ libpng ];
 
   LDFLAGS = optional static "-static";
-  configureFlags = "--with-system-zlib --with-system-libpng";
+  configureFlags = [
+    "--with-system-zlib"
+    "--with-system-libpng"
+  ] ++ stdenv.lib.optionals (hostPlatform != buildPlatform) [
+    #"-prefix=$out"
+  ];
 
-  crossAttrs = {
-    CC="${stdenv.cross.config}-gcc";
-    LD="${stdenv.cross.config}-gcc";
-    AR="${stdenv.cross.config}-ar";
-    RANLIB="${stdenv.cross.config}-ranlib";
-    configurePhase = ''
-      ./configure -prefix="$out" --with-system-zlib --with-system-libpng
-    '';
-    postInstall = optional (stdenv.cross.libc == "msvcrt") ''
-      mv "$out"/bin/optipng "$out"/bin/optipng.exe
-    '';
-  };
+  postInstall = if hostPlatform != buildPlatform && hostPlatform.isWindows then ''
+    mv "$out"/bin/optipng{,.exe}
+  '' else null;
 
   meta = with stdenv.lib; {
     homepage = http://optipng.sourceforge.net/;

From da668f66c79bd031b7231e0bd1090ec2d48d87c4 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed, 28 Jun 2017 14:23:59 -0400
Subject: [PATCH 22/69] zlib: cc-wrapper can be relied on to export this env
 var

---
 pkgs/development/libraries/zlib/default.nix | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix
index e6468771cd40..40334f0b4624 100644
--- a/pkgs/development/libraries/zlib/default.nix
+++ b/pkgs/development/libraries/zlib/default.nix
@@ -60,7 +60,7 @@ stdenv.mkDerivation rec {
   crossAttrs = {
     dontStrip = static;
     configurePlatforms = [];
-  } // stdenv.lib.optionalAttrs (stdenv.cross.libc == "msvcrt") {
+  } // stdenv.lib.optionalAttrs (hostPlatform.libc == "msvcrt") {
     installFlags = [
       "BINARY_PATH=$(out)/bin"
       "INCLUDE_PATH=$(dev)/include"
@@ -68,14 +68,12 @@ stdenv.mkDerivation rec {
     ];
     makeFlags = [
       "-f" "win32/Makefile.gcc"
-      "PREFIX=${stdenv.cross.config}-"
+      "PREFIX=${stdenv.cc.prefix}"
     ] ++ stdenv.lib.optional (!static) "SHARED_MODE=1";
 
     # Non-typical naming confuses libtool which then refuses to use zlib's DLL
     # in some cases, e.g. when compiling libpng.
     postInstall = postInstall + "ln -s zlib1.dll $out/bin/libz.dll";
-  } // stdenv.lib.optionalAttrs (stdenv.cross.libc == "libSystem") {
-    makeFlags = [ "RANLIB=${stdenv.cross.config}-ranlib" ];
   };
 
   passthru.version = version;

From 49347667a879991e4593c38ca18d7297f248b05c Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 15:59:14 -0400
Subject: [PATCH 23/69] gcc-wrapper-old: Don't use stdenv.cross

Take the dynamic linker logic for cc-wrapper for now
---
 .../build-support/gcc-wrapper-old/default.nix | 26 ++++++++++++-------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/pkgs/build-support/gcc-wrapper-old/default.nix b/pkgs/build-support/gcc-wrapper-old/default.nix
index f8a7c62edc73..a37d94c36e06 100644
--- a/pkgs/build-support/gcc-wrapper-old/default.nix
+++ b/pkgs/build-support/gcc-wrapper-old/default.nix
@@ -8,6 +8,7 @@
 { name ? "", stdenv, lib, nativeTools, nativeLibc, nativePrefix ? ""
 , gcc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? ""
 , zlib ? null
+, hostPlatform, targetPlatform
 }:
 
 assert nativeTools -> nativePrefix != "";
@@ -69,9 +70,9 @@ stdenv.mkDerivation {
     # the style in the gcc-cross-wrapper, but to keep a stable stdenv now I
     # do this sufficient if/else.
     dynamicLinker =
-      (if stdenv.cross.arch == "arm" then "ld-linux.so.3" else
-       if stdenv.cross.arch == "mips" then "ld.so.1" else
-       if stdenv.lib.hasSuffix "pc-gnu" stdenv.cross.config then "ld.so.1" else
+      (if hostPlatform.arch == "arm" then "ld-linux.so.3" else
+       if hostPlatform.arch == "mips" then "ld.so.1" else
+       if stdenv.lib.hasSuffix "pc-gnu" hostPlatform.config then "ld.so.1" else
        abort "don't know the name of the dynamic linker for this platform");
   };
 
@@ -85,15 +86,20 @@ stdenv.mkDerivation {
         + " (wrapper script)";
     };
 
-  # The dynamic linker has different names on different Linux platforms.
+  # The dynamic linker has different names on different platforms.
   dynamicLinker =
     if !nativeLibc then
-      (if stdenv.system == "i686-linux" then "ld-linux.so.2" else
-       if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
+      (if targetPlatform.system == "i686-linux"     then "ld-linux.so.2" else
+       if targetPlatform.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 == "powerpc-linux" then "ld.so.1" else
-       if stdenv.system == "mips64el-linux" then "ld.so.1" else
-       abort "don't know the name of the dynamic linker for this platform")
+       if targetPlatform.isArm32                    then "ld-linux*.so.3" else
+       if targetPlatform.system == "aarch64-linux"  then "ld-linux-aarch64.so.1" else
+       if targetPlatform.system == "powerpc-linux"  then "ld.so.1" else
+       if targetPlatform.system == "mips64el-linux" then "ld.so.1" else
+       if targetPlatform.system == "x86_64-darwin"  then "/usr/lib/dyld" else
+       if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1" else
+       builtins.trace
+         "Don't know the name of the dynamic linker for platform ${targetPlatform.config}, so guessing instead."
+         null)
     else "";
 }

From 784ffeaabda2d1b77d5d7c4d33e4d78297c16877 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:00:28 -0400
Subject: [PATCH 24/69] SDL: Don't use stdenv ? cross

Simplify and finess logic a bit in a way that doesn't affect the
default native build, too.
---
 pkgs/development/libraries/SDL/default.nix | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/pkgs/development/libraries/SDL/default.nix b/pkgs/development/libraries/SDL/default.nix
index eb470519b4ec..e71ad14b11fd 100644
--- a/pkgs/development/libraries/SDL/default.nix
+++ b/pkgs/development/libraries/SDL/default.nix
@@ -1,15 +1,15 @@
 { stdenv, fetchurl, fetchpatch, pkgconfig, audiofile, libcap
 , openglSupport ? false, mesa_noglu, mesa_glu
 , alsaSupport ? true, alsaLib
-, x11Support ? true, libXext, libICE, libXrandr
+, x11Support ? hostPlatform == buildPlatform, libXext, libICE, libXrandr
 , pulseaudioSupport ? true, libpulseaudio
 , OpenGL, CoreAudio, CoreServices, AudioUnit, Kernel, Cocoa
-, hostPlatform
+, hostPlatform, buildPlatform
 }:
 
 # OSS is no longer supported, for it's much crappier than ALSA and
 # PulseAudio.
-assert (stdenv.isLinux && !(stdenv ? cross)) -> alsaSupport || pulseaudioSupport;
+assert hostPlatform.isLinux -> alsaSupport || pulseaudioSupport;
 
 let
   inherit (stdenv.lib) optional optionals;
@@ -53,9 +53,8 @@ stdenv.mkDerivation rec {
     "--enable-rpath"
     "--disable-pulseaudio-shared"
     "--disable-osmesa-shared"
-  ] ++ optionals (stdenv ? cross) ([
-    "--without-x"
-  ] ++ optional alsaSupport "--with-alsa-prefix=${alsaLib.out}/lib");
+  ] ++ optional (!x11Support) "--without-x"
+    ++ optional (alsaSupport && hostPlatform != buildPlatform) "--with-alsa-prefix=${alsaLib.out}/lib";
 
   patches = [
     # Fix window resizing issues, e.g. for xmonad

From 67ae0f03700d1ad9a9a9f2f0812141ca8a7825f8 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:01:43 -0400
Subject: [PATCH 25/69] boehm-gc: Don't use stdenv ? cross

---
 pkgs/development/libraries/boehm-gc/default.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/development/libraries/boehm-gc/default.nix b/pkgs/development/libraries/boehm-gc/default.nix
index 96e41790aac8..d32ec6cbf58b 100644
--- a/pkgs/development/libraries/boehm-gc/default.nix
+++ b/pkgs/development/libraries/boehm-gc/default.nix
@@ -1,4 +1,6 @@
-{ lib, stdenv, fetchurl, pkgconfig, libatomic_ops, enableLargeConfig ? false }:
+{ lib, stdenv, fetchurl, pkgconfig, libatomic_ops, enableLargeConfig ? false
+, buildPlatform, hostPlatform
+}:
 
 stdenv.mkDerivation rec {
   name = "boehm-gc-7.6.0";
@@ -20,7 +22,7 @@ stdenv.mkDerivation rec {
   doCheck = true;
 
   # Don't run the native `strip' when cross-compiling.
-  dontStrip = stdenv ? cross;
+  dontStrip = hostPlatform != buildPlatform;
 
   postInstall =
     ''

From df8c390a5a9398c51d8e9651b7f856f03eb6fdac Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:02:40 -0400
Subject: [PATCH 26/69] boost: Don't use stdenv ? cross

---
 pkgs/development/libraries/boost/generic.nix | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/pkgs/development/libraries/boost/generic.nix b/pkgs/development/libraries/boost/generic.nix
index 14d0c251c96f..9a6c5d7b413a 100644
--- a/pkgs/development/libraries/boost/generic.nix
+++ b/pkgs/development/libraries/boost/generic.nix
@@ -1,5 +1,5 @@
 { stdenv, fetchurl, icu, expat, zlib, bzip2, python, fixDarwinDylibNames, libiconv
-, hostPlatform
+, buildPlatform, hostPlatform
 , toolset ? if stdenv.cc.isClang then "clang" else null
 , enableRelease ? true
 , enableDebug ? false
@@ -148,13 +148,13 @@ stdenv.mkDerivation {
   enableParallelBuilding = true;
 
   buildInputs = [ expat zlib bzip2 libiconv ]
-    ++ stdenv.lib.optionals (! stdenv ? cross) [ python icu ]
+    ++ stdenv.lib.optionals (hostPlatform == buildPlatform) [ python icu ]
     ++ stdenv.lib.optional stdenv.isDarwin fixDarwinDylibNames;
 
   configureScript = "./bootstrap.sh";
   configureFlags = commonConfigureFlags
     ++ [ "--with-python=${python.interpreter}" ]
-    ++ optional (! stdenv ? cross) "--with-icu=${icu.dev}"
+    ++ optional (hostPlatform == buildPlatform) "--with-icu=${icu.dev}"
     ++ optional (toolset != null) "--with-toolset=${toolset}";
 
   buildPhase = builder nativeB2Args;

From 0fa3d99f4ee17dc9a639b9535aaa2df8f242f453 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:07:38 -0400
Subject: [PATCH 27/69] fontconfig 2.10: Don't use stdenv.cross

---
 pkgs/development/libraries/fontconfig/2.10.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/development/libraries/fontconfig/2.10.nix b/pkgs/development/libraries/fontconfig/2.10.nix
index 302992fc8c8a..7eaba8f75ec4 100644
--- a/pkgs/development/libraries/fontconfig/2.10.nix
+++ b/pkgs/development/libraries/fontconfig/2.10.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchurl, pkgconfig, freetype, expat }:
+{ stdenv, fetchurl, pkgconfig, freetype, expat
+, hostPlatform
+}:
 
 stdenv.mkDerivation rec {
   name = "fontconfig-2.10.2";
@@ -21,7 +23,7 @@ stdenv.mkDerivation rec {
   ];
 
   # We should find a better way to access the arch reliably.
-  crossArch = stdenv.cross.arch or null;
+  crossArch = hostPlatform.arch or null;
 
   preConfigure = ''
     if test -n "$crossConfig"; then

From 9b2d1cbc7042056dd475f4c5aa41b04c992b9495 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:09:01 -0400
Subject: [PATCH 28/69] fontconfig default: Don't use stdenv.cross

---
 pkgs/development/libraries/fontconfig/default.nix | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/pkgs/development/libraries/fontconfig/default.nix b/pkgs/development/libraries/fontconfig/default.nix
index 14983b744df9..f176aa0878c8 100644
--- a/pkgs/development/libraries/fontconfig/default.nix
+++ b/pkgs/development/libraries/fontconfig/default.nix
@@ -1,5 +1,7 @@
-{ stdenv, fetchurl, fetchpatch, pkgconfig, freetype, expat, libxslt, dejavu_fonts
-, substituteAll }:
+{ stdenv, substituteAll, fetchurl, fetchpatch
+, pkgconfig, freetype, expat, libxslt, dejavu_fonts
+, hostPlatform
+}:
 
 /** Font configuration scheme
  - ./config-compat.patch makes fontconfig try the following root configs, in order:
@@ -53,7 +55,7 @@ stdenv.mkDerivation rec {
   ];
 
   # We should find a better way to access the arch reliably.
-  crossArch = stdenv.cross.arch or null;
+  crossArch = hostPlatform.arch or null;
 
   preConfigure = ''
     if test -n "$crossConfig"; then

From cebe4ee5c99d50eaff7d0ffb280a17ff8d471c81 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:10:03 -0400
Subject: [PATCH 29/69] freetype default: Don't use stdenv.cross

---
 pkgs/development/libraries/freetype/default.nix | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/pkgs/development/libraries/freetype/default.nix b/pkgs/development/libraries/freetype/default.nix
index 9b2c6fe11e15..8f16f85cabf7 100644
--- a/pkgs/development/libraries/freetype/default.nix
+++ b/pkgs/development/libraries/freetype/default.nix
@@ -1,12 +1,12 @@
-{
-  stdenv, lib, fetchurl, copyPathsToStore,
-  pkgconfig, which,
-  zlib, bzip2, libpng, gnumake, glib,
+{ stdenv, lib, fetchurl, copyPathsToStore
+, hostPlatform
+, pkgconfig, which
+, zlib, bzip2, libpng, gnumake, glib
 
-  # FreeType supports LCD filtering (colloquially referred to as sub-pixel rendering).
+, # FreeType supports LCD filtering (colloquially referred to as sub-pixel rendering).
   # LCD filtering is also known as ClearType and covered by several Microsoft patents.
   # This option allows it to be disabled. See http://www.freetype.org/patents.html.
-  useEncumberedCode ? true,
+  useEncumberedCode ? true
 }:
 
 let
@@ -67,7 +67,7 @@ in stdenv.mkDerivation {
 
   postInstall = glib.flattenInclude;
 
-  crossAttrs = stdenv.lib.optionalAttrs (stdenv.cross.libc or null != "msvcrt") {
+  crossAttrs = stdenv.lib.optionalAttrs (hostPlatform.libc or null != "msvcrt") {
     # Somehow it calls the unwrapped gcc, "i686-pc-linux-gnu-gcc", instead
     # of gcc. I think it's due to the unwrapped gcc being in the PATH. I don't
     # know why it's on the PATH.

From ade488c52a32433b1dc4d20f39fead75bcc4ee3d Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:11:06 -0400
Subject: [PATCH 30/69] glew 1.10: Don't use stdenv ? cross

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

diff --git a/pkgs/development/libraries/glew/1.10.nix b/pkgs/development/libraries/glew/1.10.nix
index 8500a54f970c..b2e1b26704f3 100644
--- a/pkgs/development/libraries/glew/1.10.nix
+++ b/pkgs/development/libraries/glew/1.10.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
 
   patchPhase = ''
     sed -i 's|lib64|lib|' config/Makefile.linux
-    ${optionalString (stdenv ? cross) ''
+    ${optionalString (hostPlatform != buildPlatform) ''
     sed -i -e 's/\(INSTALL.*\)-s/\1/' Makefile
     ''}
   '';

From de1125ea2caca9ca76dc1b4ade84565b5547ca0c Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:12:05 -0400
Subject: [PATCH 31/69] glew default: Don't use stdenv ? cross

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

diff --git a/pkgs/development/libraries/glew/default.nix b/pkgs/development/libraries/glew/default.nix
index f8df5d5baf0d..ecf1e914a7b1 100644
--- a/pkgs/development/libraries/glew/default.nix
+++ b/pkgs/development/libraries/glew/default.nix
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
 
   patchPhase = ''
     sed -i 's|lib64|lib|' config/Makefile.linux
-    ${optionalString (stdenv ? cross) ''
+    ${optionalString (hostPlatform != buildPlatform) ''
     sed -i -e 's/\(INSTALL.*\)-s/\1/' Makefile
     ''}
   '';

From 58196b607e18c3c99268d40a0fee60462dccbdaf Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:13:11 -0400
Subject: [PATCH 32/69] libav: Don't use stdenv.cross

---
 pkgs/development/libraries/libav/default.nix | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/pkgs/development/libraries/libav/default.nix b/pkgs/development/libraries/libav/default.nix
index 785e3599bf17..3d4fbab3e422 100644
--- a/pkgs/development/libraries/libav/default.nix
+++ b/pkgs/development/libraries/libav/default.nix
@@ -13,6 +13,7 @@
 , SDL # only for avplay in $bin, adds nontrivial closure to it
 , enableGPL ? true # ToDo: some additional default stuff may need GPL
 , enableUnfree ? faacSupport
+, hostPlatform
 }:
 
 assert faacSupport -> enableUnfree;
@@ -107,10 +108,10 @@ let
     crossAttrs = {
       configurePlatforms = [];
       configureFlags = configureFlags ++ [
-        "--cross-prefix=${stdenv.cross.config}-"
+        "--cross-prefix=${stdenv.cc.prefix}"
         "--enable-cross-compile"
         "--target_os=linux"
-        "--arch=${stdenv.cross.arch}"
+        "--arch=${hostPlatform.arch}"
         ];
     };
 

From 5a21bb6917abc75f294b49b7902bc9b5545aad82 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:13:56 -0400
Subject: [PATCH 33/69] libffi: Don't use stdenv ? cross

---
 pkgs/development/libraries/libffi/default.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/development/libraries/libffi/default.nix b/pkgs/development/libraries/libffi/default.nix
index b203f6346476..ca149bd3db35 100644
--- a/pkgs/development/libraries/libffi/default.nix
+++ b/pkgs/development/libraries/libffi/default.nix
@@ -1,4 +1,6 @@
-{ fetchurl, stdenv, dejagnu, doCheck ? false }:
+{ fetchurl, stdenv, dejagnu, doCheck ? false
+, buildPlatform, hostPlatform
+}:
 
 stdenv.mkDerivation rec {
   name = "libffi-3.2.1";
@@ -21,7 +23,7 @@ stdenv.mkDerivation rec {
 
   inherit doCheck;
 
-  dontStrip = stdenv ? cross; # Don't run the native `strip' when cross-compiling.
+  dontStrip = hostPlatform != buildPlatform; # Don't run the native `strip' when cross-compiling.
 
   # Install headers and libs in the right places.
   postFixup = ''

From db0af50973c11fbd3a402ad703012d4af8c70be9 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:14:36 -0400
Subject: [PATCH 34/69] libiconv: Don't use stdenv ? cross

---
 pkgs/development/libraries/libiconv/default.nix | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/pkgs/development/libraries/libiconv/default.nix b/pkgs/development/libraries/libiconv/default.nix
index 4c634de92468..a056f148683c 100644
--- a/pkgs/development/libraries/libiconv/default.nix
+++ b/pkgs/development/libraries/libiconv/default.nix
@@ -1,6 +1,8 @@
-{ fetchurl, stdenv, lib }:
+{ fetchurl, stdenv, lib
+, buildPlatform, hostPlatform
+}:
 
-assert !stdenv.isLinux || stdenv ? cross; # TODO: improve on cross
+assert !stdenv.isLinux || hostPlatform != buildPlatform; # TODO: improve on cross
 
 stdenv.mkDerivation rec {
   name = "libiconv-${version}";
@@ -17,7 +19,7 @@ stdenv.mkDerivation rec {
   ];
 
   postPatch =
-    lib.optionalString ((stdenv ? cross && stdenv.cross.libc == "msvcrt") || stdenv.cc.nativeLibc)
+    lib.optionalString ((hostPlatform != buildPlatform && hostPlatform.libc == "msvcrt") || stdenv.cc.nativeLibc)
       ''
         sed '/^_GL_WARN_ON_USE (gets/d' -i srclib/stdio.in.h
       '';

From 737e344e503df91aef707649e82b1294e709f960 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:16:39 -0400
Subject: [PATCH 35/69] libjpeg-turbo: Don't use stdenv.cross

---
 pkgs/development/libraries/libjpeg-turbo/default.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/development/libraries/libjpeg-turbo/default.nix b/pkgs/development/libraries/libjpeg-turbo/default.nix
index a59a1702e173..cd8484170bdb 100644
--- a/pkgs/development/libraries/libjpeg-turbo/default.nix
+++ b/pkgs/development/libraries/libjpeg-turbo/default.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchurl, nasm }:
+{ stdenv, fetchurl, nasm
+, hostPlatform
+}:
 
 stdenv.mkDerivation rec {
   name = "libjpeg-turbo-${version}";
@@ -10,7 +12,7 @@ stdenv.mkDerivation rec {
   }; # github releases still need autotools, surprisingly
 
   patches =
-    stdenv.lib.optional (stdenv.cross.libc or null == "msvcrt")
+    stdenv.lib.optional (hostPlatform.libc or null == "msvcrt")
       ./mingw-boolean.patch;
 
   outputs = [ "bin" "dev" "out" "doc" ];

From a9c90df12ef0d462e42363e9613d7517ae333e53 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:17:38 -0400
Subject: [PATCH 36/69] libmsgpack generic: Don't use stdenv.cross

---
 pkgs/development/libraries/libmsgpack/generic.nix | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pkgs/development/libraries/libmsgpack/generic.nix b/pkgs/development/libraries/libmsgpack/generic.nix
index 2da703da4cfd..c6870f77f1f3 100644
--- a/pkgs/development/libraries/libmsgpack/generic.nix
+++ b/pkgs/development/libraries/libmsgpack/generic.nix
@@ -1,5 +1,6 @@
 { stdenv, cmake
 , version, src, patches ? [ ]
+, hostPlatform
 , ...
 }:
 
@@ -11,7 +12,7 @@ stdenv.mkDerivation rec {
   nativeBuildInputs = [ cmake ];
 
   crossAttrs = {
-  } // stdenv.lib.optionalAttrs (stdenv.cross.libc == "msvcrt") {
+  } // stdenv.lib.optionalAttrs (hostPlatform.libc == "msvcrt") {
     cmakeFlags = "-DMSGPACK_BUILD_EXAMPLES=OFF -DCMAKE_SYSTEM_NAME=Windows";
   };
 

From bdbdb08eef9b0407fe16fac2ec9efb5b8cf5d867 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:20:55 -0400
Subject: [PATCH 37/69] libpng 12: Don't use stdenv ? cross

---
 pkgs/development/libraries/libpng/12.nix | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/pkgs/development/libraries/libpng/12.nix b/pkgs/development/libraries/libpng/12.nix
index b3f7f96e9362..457f99ef13bd 100644
--- a/pkgs/development/libraries/libpng/12.nix
+++ b/pkgs/development/libraries/libpng/12.nix
@@ -1,6 +1,8 @@
-{ stdenv, fetchurl, zlib }:
+{ stdenv, fetchurl, zlib
+, buildPlatform, hostPlatform
+}:
 
-assert !(stdenv ? cross) -> zlib != null;
+assert hostPlatform == buildPlatform -> zlib != null;
 
 stdenv.mkDerivation rec {
   name = "libpng-1.2.57";
@@ -16,7 +18,7 @@ stdenv.mkDerivation rec {
 
   passthru = { inherit zlib; };
 
-  crossAttrs = stdenv.lib.optionalAttrs (stdenv.cross.libc == "libSystem") {
+  crossAttrs = stdenv.lib.optionalAttrs (hostPlatform.libc == "libSystem") {
     propagatedBuildInputs = [];
     passthru = {};
   };

From a850ddbefc28f947833abb021aa2eb1390c900d4 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:21:38 -0400
Subject: [PATCH 38/69] libpng default: Don't use stdenv.cross

---
 pkgs/development/libraries/libpng/default.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/development/libraries/libpng/default.nix b/pkgs/development/libraries/libpng/default.nix
index 92e0fa339b24..c2f50af84ca8 100644
--- a/pkgs/development/libraries/libpng/default.nix
+++ b/pkgs/development/libraries/libpng/default.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchurl, zlib, apngSupport ? true }:
+{ stdenv, fetchurl, zlib, apngSupport ? true
+, buildPlatform, hostPlatform
+}:
 
 assert zlib != null;
 
@@ -29,7 +31,7 @@ in stdenv.mkDerivation rec {
 
   # it's hard to cross-run tests and some check programs didn't compile anyway
   makeFlags = stdenv.lib.optional (!doCheck) "check_PROGRAMS=";
-  doCheck = ! stdenv ? cross;
+  doCheck = hostPlatform == buildPlatform;
 
   passthru = { inherit zlib; };
 

From 9d56714419208e598f8c0b66024e419912d2c24b Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:22:12 -0400
Subject: [PATCH 39/69] libssh2: Don't use stdenv.cross

---
 pkgs/development/libraries/libssh2/default.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/development/libraries/libssh2/default.nix b/pkgs/development/libraries/libssh2/default.nix
index 4320cacc590a..4d754dc80866 100644
--- a/pkgs/development/libraries/libssh2/default.nix
+++ b/pkgs/development/libraries/libssh2/default.nix
@@ -1,4 +1,6 @@
-{stdenv, fetchurlBoot, openssl, zlib, windows}:
+{ stdenv, fetchurlBoot, openssl, zlib, windows
+, hostPlatform
+}:
 
 stdenv.mkDerivation rec {
   name = "libssh2-1.8.0";
@@ -20,7 +22,7 @@ stdenv.mkDerivation rec {
       "--with-libz"
       "--with-libz-prefix=${zlib.crossDrv}"
     ];
-  } // stdenv.lib.optionalAttrs (stdenv.cross.libc == "msvcrt") {
+  } // stdenv.lib.optionalAttrs (hostPlatform.libc == "msvcrt") {
     # mingw needs import library of ws2_32 to build the shared library
     preConfigure = ''
       export LDFLAGS="-L${windows.mingw_w64}/lib $LDFLAGS"

From 8b726dc11654901224b3142348b8a55460fae550 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:22:44 -0400
Subject: [PATCH 40/69] newt: Don't use stdenv.cross

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

diff --git a/pkgs/development/libraries/newt/default.nix b/pkgs/development/libraries/newt/default.nix
index 8a4b793cad79..9002d06693e5 100644
--- a/pkgs/development/libraries/newt/default.nix
+++ b/pkgs/development/libraries/newt/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
   NIX_LDFLAGS = "-lncurses";
 
   crossAttrs = {
-    makeFlags = "CROSS_COMPILE=${stdenv.cross.config}-";
+    makeFlags = "CROSS_COMPILE=${stdenv.cc.prefix}";
   };
 
   meta = with stdenv.lib; {

From 51856df2a1b465eb93d5966f2013f64a916d5a65 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:23:34 -0400
Subject: [PATCH 41/69] nlohmann_json: Don't use stdenv.cross

---
 pkgs/development/libraries/nlohmann_json/default.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/development/libraries/nlohmann_json/default.nix b/pkgs/development/libraries/nlohmann_json/default.nix
index a5a808c1f615..9fb614cd071a 100644
--- a/pkgs/development/libraries/nlohmann_json/default.nix
+++ b/pkgs/development/libraries/nlohmann_json/default.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchFromGitHub, cmake }:
+{ stdenv, fetchFromGitHub, cmake
+, hostPlatform
+}:
 
 stdenv.mkDerivation rec {
   name = "nlohmann_json-${version}";
@@ -21,7 +23,7 @@ stdenv.mkDerivation rec {
   crossAttrs = {
     cmakeFlags = "-DBuildTests=OFF";
     doCheck = false;
-  } // stdenv.lib.optionalAttrs (stdenv.cross.libc == "msvcrt") {
+  } // stdenv.lib.optionalAttrs (hostPlatform.libc == "msvcrt") {
     cmakeFlags = "-DBuildTests=OFF -DCMAKE_SYSTEM_NAME=Windows";
   };
 

From d28eb3b7a04dc7b057e3f0ee77cc7e07cfc7cf61 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:24:16 -0400
Subject: [PATCH 42/69] poppler: Don't use stdenv.cross

---
 pkgs/development/libraries/poppler/default.nix | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pkgs/development/libraries/poppler/default.nix b/pkgs/development/libraries/poppler/default.nix
index 20e35fa3e089..856c7bac8ce1 100644
--- a/pkgs/development/libraries/poppler/default.nix
+++ b/pkgs/development/libraries/poppler/default.nix
@@ -6,6 +6,7 @@
 , introspectionSupport ? false, gobjectIntrospection ? null
 , utils ? false
 , minimal ? false, suffix ? "glib"
+, hostPlatform
 }:
 
 let # beware: updates often break cups-filters build
@@ -56,7 +57,7 @@ stdenv.mkDerivation rec {
 
   crossAttrs.postPatch =
     # there are tests using `strXXX_s` functions that are missing apparently
-    stdenv.lib.optionalString (stdenv.cross.libc or null == "msvcrt")
+    stdenv.lib.optionalString (hostPlatform.libc or null == "msvcrt")
       "sed '/^SUBDIRS =/s/ test / /' -i Makefile.in";
 
   meta = with lib; {

From a46b063ac1038be9e52b97714d7a1a090d53545f Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:25:05 -0400
Subject: [PATCH 43/69] readline 6.2: Don't use stdenv ? cross

---
 pkgs/development/libraries/readline/6.2.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/development/libraries/readline/6.2.nix b/pkgs/development/libraries/readline/6.2.nix
index 65ab4ed24cec..2c800e23b27f 100644
--- a/pkgs/development/libraries/readline/6.2.nix
+++ b/pkgs/development/libraries/readline/6.2.nix
@@ -1,4 +1,6 @@
-{ fetchurl, stdenv, ncurses }:
+{ fetchurl, stdenv, ncurses
+, buildPlatform, hostPlatform
+}:
 
 stdenv.mkDerivation (rec {
   name = "readline-6.2";
@@ -57,6 +59,6 @@ stdenv.mkDerivation (rec {
 //
 
 # Don't run the native `strip' when cross-compiling.
-(if (stdenv ? cross)
+(if hostPlatform != buildPlatform
  then { dontStrip = true; }
  else { }))

From 45272c98f5c0cfe90176b706de9384e4c2803afb Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:26:37 -0400
Subject: [PATCH 44/69] readline 6.3: Don't use stdenv ? cross

---
 pkgs/development/libraries/readline/6.3.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/development/libraries/readline/6.3.nix b/pkgs/development/libraries/readline/6.3.nix
index 80cc7e923b83..822ce7b0055d 100644
--- a/pkgs/development/libraries/readline/6.3.nix
+++ b/pkgs/development/libraries/readline/6.3.nix
@@ -1,4 +1,6 @@
-{ fetchurl, stdenv, ncurses }:
+{ fetchurl, stdenv, ncurses
+, buildPlatform, hostPlatform
+}:
 
 stdenv.mkDerivation rec {
   name = "readline-6.3p08";
@@ -29,7 +31,7 @@ stdenv.mkDerivation rec {
        import ./readline-6.3-patches.nix patch);
 
   # Don't run the native `strip' when cross-compiling.
-  dontStrip = stdenv ? cross;
+  dontStrip = hostPlatform != buildPlatform;
   bash_cv_func_sigsetjmp = if stdenv.isCygwin then "missing" else null;
 
   meta = with stdenv.lib; {

From f9730bc8dadd9f4d170a5f3ac3cfb7dedd08250f Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:27:22 -0400
Subject: [PATCH 45/69] readline 7.0: Don't use stdenv ? cross

---
 pkgs/development/libraries/readline/7.0.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/development/libraries/readline/7.0.nix b/pkgs/development/libraries/readline/7.0.nix
index 9d1c1c57f8c1..7cc76e087685 100644
--- a/pkgs/development/libraries/readline/7.0.nix
+++ b/pkgs/development/libraries/readline/7.0.nix
@@ -1,4 +1,6 @@
-{ fetchurl, stdenv, ncurses }:
+{ fetchurl, stdenv, ncurses
+, buildPlatform, hostPlatform
+}:
 
 stdenv.mkDerivation rec {
   name = "readline-${version}";
@@ -33,7 +35,7 @@ stdenv.mkDerivation rec {
     */
 
   # Don't run the native `strip' when cross-compiling.
-  dontStrip = stdenv ? cross;
+  dontStrip = hostPlatform != buildPlatform;
   bash_cv_func_sigsetjmp = if stdenv.isCygwin then "missing" else null;
 
   meta = with stdenv.lib; {

From 3e69864717c89aa8cef18f17bcb1f8f16a6fdf1f Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:28:34 -0400
Subject: [PATCH 46/69] cmake 2.8: Don't use stdenv ? cross

---
 pkgs/development/tools/build-managers/cmake/2.8.nix | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pkgs/development/tools/build-managers/cmake/2.8.nix b/pkgs/development/tools/build-managers/cmake/2.8.nix
index 590de68d52f7..fb38e52811cf 100644
--- a/pkgs/development/tools/build-managers/cmake/2.8.nix
+++ b/pkgs/development/tools/build-managers/cmake/2.8.nix
@@ -1,5 +1,6 @@
 { stdenv, fetchurl, fetchpatch, replace, curl, expat, zlib, bzip2
 , useNcurses ? false, ncurses, useQt4 ? false, qt4, wantPS ? false, ps ? null
+, buildPlatform, hostPlatform
 }:
 
 with stdenv.lib;
@@ -35,7 +36,7 @@ stdenv.mkDerivation rec {
     })] ++
     # Don't search in non-Nix locations such as /usr, but do search in our libc.
     [ ./search-path.patch ] ++
-    optional (stdenv ? cross) (fetchurl {
+    optional (hostPlatform != buildPlatform) (fetchurl {
       name = "fix-darwin-cross-compile.patch";
       url = "http://public.kitware.com/Bug/file_download.php?"
           + "file_id=4981&type=bug";

From 9cd606467fa0648e851bf8c5436bc773b6a1c5bc Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:29:17 -0400
Subject: [PATCH 47/69] libtool2: Don't use stdenv ? cross

---
 pkgs/development/tools/misc/libtool/libtool2.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/development/tools/misc/libtool/libtool2.nix b/pkgs/development/tools/misc/libtool/libtool2.nix
index a81255212da5..f25fbcd00d84 100644
--- a/pkgs/development/tools/misc/libtool/libtool2.nix
+++ b/pkgs/development/tools/misc/libtool/libtool2.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchurl, m4, perl, help2man }:
+{ stdenv, fetchurl, m4, perl, help2man
+, buildPlatform, hostPlatform
+}:
 
 stdenv.mkDerivation rec {
   name = "libtool-2.4.6";
@@ -23,7 +25,7 @@ stdenv.mkDerivation rec {
 
   # Don't run the native `strip' when cross-compiling.  This breaks at least
   # with `.a' files for MinGW.
-  dontStrip = stdenv ? cross;
+  dontStrip = hostPlatform != buildPlatform;
 
   meta = {
     description = "GNU Libtool, a generic library support script";

From a7f81284a5adac45370a876c98e628b2ef7156d3 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:30:13 -0400
Subject: [PATCH 48/69] uboot: Don't use stdenv.cross

---
 pkgs/misc/uboot/default.nix | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/pkgs/misc/uboot/default.nix b/pkgs/misc/uboot/default.nix
index 07ccd419f4bc..a3e4f12cd892 100644
--- a/pkgs/misc/uboot/default.nix
+++ b/pkgs/misc/uboot/default.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchurl, bc, dtc, python2 }:
+{ stdenv, fetchurl, bc, dtc, python2
+, hostPlatform
+}:
 
 let
   buildUBoot = { targetPlatforms
@@ -43,8 +45,8 @@ let
 
     crossAttrs = {
       makeFlags = [
-        "ARCH=${stdenv.cross.platform.kernelArch}"
-        "CROSS_COMPILE=${stdenv.cross.config}-"
+        "ARCH=${hostPlatform.platform.kernelArch}"
+        "CROSS_COMPILE=${stdenv.cc.prefix}"
       ];
     };
 

From c5b4b6c911a2965bd616370ec79262df3a4036f5 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:30:50 -0400
Subject: [PATCH 49/69] kernel-headers: Don't use stdenv.cross

---
 pkgs/os-specific/linux/kernel-headers/default.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/os-specific/linux/kernel-headers/default.nix b/pkgs/os-specific/linux/kernel-headers/default.nix
index a33d24fc847b..da67747b8b24 100644
--- a/pkgs/os-specific/linux/kernel-headers/default.nix
+++ b/pkgs/os-specific/linux/kernel-headers/default.nix
@@ -1,4 +1,6 @@
-{ stdenv, kernel, perl }:
+{ stdenv, kernel, perl
+, hostPlatform
+}:
 
 let
   baseBuildFlags = [ "INSTALL_HDR_PATH=$(out)" "headers_install" ];
@@ -13,7 +15,7 @@ in stdenv.mkDerivation {
 
   crossAttrs = {
     inherit (kernel.crossDrv) src patches;
-    buildFlags = [ "ARCH=${stdenv.cross.platform.kernelArch}" ] ++ baseBuildFlags;
+    buildFlags = [ "ARCH=${hostPlatform.platform.kernelArch}" ] ++ baseBuildFlags;
   };
 
   installPhase = ''

From 459d07d41cccbfecf3f1b313dd93fe33e38ff153 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:32:25 -0400
Subject: [PATCH 50/69] kernel generic: Don't use stdenv.cross

---
 pkgs/os-specific/linux/kernel/generic.nix                   | 5 +++--
 pkgs/os-specific/linux/kernel/linux-3.10.nix                | 2 +-
 pkgs/os-specific/linux/kernel/linux-4.11.nix                | 2 +-
 pkgs/os-specific/linux/kernel/linux-4.4.nix                 | 2 +-
 pkgs/os-specific/linux/kernel/linux-4.9.nix                 | 2 +-
 pkgs/os-specific/linux/kernel/linux-chromiumos-3.18.nix     | 2 +-
 pkgs/os-specific/linux/kernel/linux-hardened-copperhead.nix | 2 +-
 pkgs/os-specific/linux/kernel/linux-mptcp.nix               | 2 +-
 pkgs/os-specific/linux/kernel/linux-rpi.nix                 | 2 +-
 pkgs/os-specific/linux/kernel/linux-testing.nix             | 2 +-
 10 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/pkgs/os-specific/linux/kernel/generic.nix b/pkgs/os-specific/linux/kernel/generic.nix
index 16b35e9aa3e2..bbe867926927 100644
--- a/pkgs/os-specific/linux/kernel/generic.nix
+++ b/pkgs/os-specific/linux/kernel/generic.nix
@@ -25,6 +25,7 @@
   kernelPatches ? []
 , ignoreConfigErrors ? stdenv.platform.name != "pc"
 , extraMeta ? {}
+, hostPlatform
 , ...
 }:
 
@@ -59,7 +60,7 @@ let
     arch = stdenv.platform.kernelArch;
 
     crossAttrs = let
-        cp = stdenv.cross.platform;
+        cp = hostPlatform.platform;
       in {
         arch = cp.kernelArch;
         platformName = cp.name;
@@ -128,7 +129,7 @@ let
     };
 
   config = configWithPlatform stdenv.platform;
-  configCross = configWithPlatform stdenv.cross.platform;
+  configCross = configWithPlatform hostPlatform.platform;
 
   nativeDrv = lib.addPassthru kernel.nativeDrv passthru;
 
diff --git a/pkgs/os-specific/linux/kernel/linux-3.10.nix b/pkgs/os-specific/linux/kernel/linux-3.10.nix
index 8ab879f7b00e..9587ba356ff5 100644
--- a/pkgs/os-specific/linux/kernel/linux-3.10.nix
+++ b/pkgs/os-specific/linux/kernel/linux-3.10.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
+{ stdenv, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
 
 import ./generic.nix (args // rec {
   version = "3.10.105";
diff --git a/pkgs/os-specific/linux/kernel/linux-4.11.nix b/pkgs/os-specific/linux/kernel/linux-4.11.nix
index f74b8f62120d..3019c6fcb964 100644
--- a/pkgs/os-specific/linux/kernel/linux-4.11.nix
+++ b/pkgs/os-specific/linux/kernel/linux-4.11.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
+{ stdenv, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
 
 import ./generic.nix (args // rec {
   version = "4.11.7";
diff --git a/pkgs/os-specific/linux/kernel/linux-4.4.nix b/pkgs/os-specific/linux/kernel/linux-4.4.nix
index 5328bb9a0432..4f272c2e43ff 100644
--- a/pkgs/os-specific/linux/kernel/linux-4.4.nix
+++ b/pkgs/os-specific/linux/kernel/linux-4.4.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
+{ stdenv, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
 
 import ./generic.nix (args // rec {
   version = "4.4.73";
diff --git a/pkgs/os-specific/linux/kernel/linux-4.9.nix b/pkgs/os-specific/linux/kernel/linux-4.9.nix
index 38d63a22f70d..a45ba31c0a93 100644
--- a/pkgs/os-specific/linux/kernel/linux-4.9.nix
+++ b/pkgs/os-specific/linux/kernel/linux-4.9.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
+{ stdenv, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
 
 import ./generic.nix (args // rec {
   version = "4.9.34";
diff --git a/pkgs/os-specific/linux/kernel/linux-chromiumos-3.18.nix b/pkgs/os-specific/linux/kernel/linux-chromiumos-3.18.nix
index b80c9acd659e..e27b2afb200e 100644
--- a/pkgs/os-specific/linux/kernel/linux-chromiumos-3.18.nix
+++ b/pkgs/os-specific/linux/kernel/linux-chromiumos-3.18.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchgit, perl, buildLinux, ncurses, ... } @ args:
+{ stdenv, hostPlatform, fetchgit, perl, buildLinux, ncurses, ... } @ args:
 
 # ChromiumOS requires a 64bit build host
 assert stdenv.is64bit;
diff --git a/pkgs/os-specific/linux/kernel/linux-hardened-copperhead.nix b/pkgs/os-specific/linux/kernel/linux-hardened-copperhead.nix
index 36a019215124..7f4a89dc51e2 100644
--- a/pkgs/os-specific/linux/kernel/linux-hardened-copperhead.nix
+++ b/pkgs/os-specific/linux/kernel/linux-hardened-copperhead.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, perl, buildLinux, ... } @ args:
+{ stdenv, hostPlatform, fetchFromGitHub, perl, buildLinux, ... } @ args:
 
 let
   version = "4.11.7";
diff --git a/pkgs/os-specific/linux/kernel/linux-mptcp.nix b/pkgs/os-specific/linux/kernel/linux-mptcp.nix
index 3d244b794e94..7e6110bf4a39 100644
--- a/pkgs/os-specific/linux/kernel/linux-mptcp.nix
+++ b/pkgs/os-specific/linux/kernel/linux-mptcp.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
+{ stdenv, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
 
 import ./generic.nix (args // rec {
   mptcpVersion = "0.91.3";
diff --git a/pkgs/os-specific/linux/kernel/linux-rpi.nix b/pkgs/os-specific/linux/kernel/linux-rpi.nix
index 9bc6feb3de22..0e7f332e6177 100644
--- a/pkgs/os-specific/linux/kernel/linux-rpi.nix
+++ b/pkgs/os-specific/linux/kernel/linux-rpi.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, perl, buildLinux, ... } @ args:
+{ stdenv, hostPlatform, fetchFromGitHub, perl, buildLinux, ... } @ args:
 
 let
   modDirVersion = "4.9.24";
diff --git a/pkgs/os-specific/linux/kernel/linux-testing.nix b/pkgs/os-specific/linux/kernel/linux-testing.nix
index 6bde598c47ab..45c6a5bf0e88 100644
--- a/pkgs/os-specific/linux/kernel/linux-testing.nix
+++ b/pkgs/os-specific/linux/kernel/linux-testing.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
+{ stdenv, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
 
 import ./generic.nix (args // rec {
   version = "4.12-rc6";

From 1e3b45cfdb17d6d83229c2ae677d31f8736d90f0 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:33:04 -0400
Subject: [PATCH 51/69] kernel manual-config: Don't use stdenv.cross

---
 pkgs/os-specific/linux/kernel/manual-config.nix | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix
index 3466cafa2660..c295293fa2cc 100644
--- a/pkgs/os-specific/linux/kernel/manual-config.nix
+++ b/pkgs/os-specific/linux/kernel/manual-config.nix
@@ -1,5 +1,6 @@
 { stdenv, runCommand, nettools, bc, perl, gmp, libmpc, mpfr, kmod, openssl
 , writeTextFile, ubootChooser
+, hostPlatform
 }:
 
 let
@@ -232,7 +233,7 @@ stdenv.mkDerivation ((drvAttrs config stdenv.platform (kernelPatches ++ nativeKe
 
   karch = stdenv.platform.kernelArch;
 
-  crossAttrs = let cp = stdenv.cross.platform; in
+  crossAttrs = let cp = hostPlatform.platform; in
     (drvAttrs crossConfig cp (kernelPatches ++ crossKernelPatches) crossConfigfile) // {
       makeFlags = commonMakeFlags ++ [
         "ARCH=${cp.kernelArch}"

From 16781a389237acac3342f8440f5afd282627448f Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:37:58 -0400
Subject: [PATCH 52/69] kernel perf: Don't use stdenv.cross

---
 pkgs/os-specific/linux/kernel/perf.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pkgs/os-specific/linux/kernel/perf.nix b/pkgs/os-specific/linux/kernel/perf.nix
index 0a3b4070be17..3fbad924568f 100644
--- a/pkgs/os-specific/linux/kernel/perf.nix
+++ b/pkgs/os-specific/linux/kernel/perf.nix
@@ -49,7 +49,7 @@ stdenv.mkDerivation {
     /* I don't want cross-python or cross-perl -
        I don't know if cross-python even works */
     propagatedBuildInputs = [ elfutils.crossDrv newt.crossDrv ];
-    makeFlags = "CROSS_COMPILE=${stdenv.cross.config}-";
+    makeFlags = "CROSS_COMPILE=${stdenv.cc.prefix}";
     elfutils = elfutils.crossDrv;
     inherit (kernel.crossDrv) src patches;
   };

From a210b08d188404c13498ff075b9a3b28d063642d Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:38:33 -0400
Subject: [PATCH 53/69] klibc: Don't use crossAttrs

---
 pkgs/os-specific/linux/klibc/default.nix | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/pkgs/os-specific/linux/klibc/default.nix b/pkgs/os-specific/linux/klibc/default.nix
index 84b66ac0d9c7..92ac1a77898c 100644
--- a/pkgs/os-specific/linux/klibc/default.nix
+++ b/pkgs/os-specific/linux/klibc/default.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchurl, linuxHeaders, perl }:
+{ stdenv, fetchurl, linuxHeaders, perl
+, buildPlatform, hostPlatform
+}:
 
 let
   commonMakeFlags = [
@@ -23,17 +25,12 @@ stdenv.mkDerivation rec {
   hardeningDisable = [ "format" "stackprotector" ];
 
   makeFlags = commonMakeFlags ++ [
-    "KLIBCARCH=${stdenv.platform.kernelArch}"
+    "KLIBCARCH=${hostPlatform.platform.kernelArch}"
     "KLIBCKERNELSRC=${linuxHeaders}"
-  ] ++ stdenv.lib.optional (stdenv.platform.kernelArch == "arm") "CONFIG_AEABI=y";
-
-  crossAttrs = {
-    makeFlags = commonMakeFlags ++ [
-      "KLIBCARCH=${stdenv.cross.platform.kernelArch}"
-      "KLIBCKERNELSRC=${linuxHeaders.crossDrv}"
-      "CROSS_COMPILE=${stdenv.cross.config}-"
-    ] ++ stdenv.lib.optional (stdenv.cross.platform.kernelArch == "arm") "CONFIG_AEABI=y";
-  };
+  ] # TODO(@Ericson2314): We now can get the ABI from
+    # `hostPlatform.parsed.abi`, is this still a good idea?
+    ++ stdenv.lib.optional (hostPlatform.platform.kernelArch == "arm") "CONFIG_AEABI=y"
+    ++ stdenv.lib.optional (hostPlatform != buildPlatform) "CROSS_COMPILE=${stdenv.cc.prefix}";
 
   # Install static binaries as well.
   postInstall = ''

From 5d83d36389f5dbd84913e8f582e126bedd278fbe Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:39:12 -0400
Subject: [PATCH 54/69] mdadm: Don't use stdenv.cross

---
 pkgs/os-specific/linux/mdadm/4.nix       | 9 ++++++---
 pkgs/os-specific/linux/mdadm/default.nix | 9 ++++++---
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/pkgs/os-specific/linux/mdadm/4.nix b/pkgs/os-specific/linux/mdadm/4.nix
index 05d98de0b234..a83e7c852ee2 100644
--- a/pkgs/os-specific/linux/mdadm/4.nix
+++ b/pkgs/os-specific/linux/mdadm/4.nix
@@ -1,4 +1,7 @@
-{ stdenv, fetchurl, groff }:
+{ stdenv
+, fetchurl, groff
+, buildPlatform, hostPlatform
+}:
 
 assert stdenv.isLinux;
 
@@ -19,8 +22,8 @@ stdenv.mkDerivation rec {
   makeFlags = [
     "NIXOS=1" "INSTALL=install" "INSTALL_BINDIR=$(out)/sbin"
     "MANDIR=$(out)/share/man" "RUN_DIR=/dev/.mdadm"
-  ] ++ stdenv.lib.optionals (stdenv ? cross) [
-    "CROSS_COMPILE=${stdenv.cross.config}-"
+  ] ++ stdenv.lib.optionals (hostPlatform != buildPlatform) [
+    "CROSS_COMPILE=${stdenv.cc.prefix}"
   ];
 
   nativeBuildInputs = [ groff ];
diff --git a/pkgs/os-specific/linux/mdadm/default.nix b/pkgs/os-specific/linux/mdadm/default.nix
index e0109791ef22..589099c911cf 100644
--- a/pkgs/os-specific/linux/mdadm/default.nix
+++ b/pkgs/os-specific/linux/mdadm/default.nix
@@ -1,4 +1,7 @@
-{ stdenv, fetchurl, groff }:
+{ stdenv
+, fetchurl, groff
+, buildPlatform, hostPlatform
+}:
 
 assert stdenv.isLinux;
 
@@ -19,8 +22,8 @@ stdenv.mkDerivation rec {
   makeFlags = [
     "NIXOS=1" "INSTALL=install" "INSTALL_BINDIR=$(out)/sbin"
     "MANDIR=$(out)/share/man" "RUN_DIR=/dev/.mdadm"
-  ] ++ stdenv.lib.optionals (stdenv ? cross) [
-    "CROSS_COMPILE=${stdenv.cross.config}-"
+  ] ++ stdenv.lib.optionals (hostPlatform != buildPlatform) [
+    "CROSS_COMPILE=${stdenv.cc.prefix}"
   ];
 
   nativeBuildInputs = [ groff ];

From 66e22e1229fc6d544381d4450425d8bd5dc3f2ac Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:40:25 -0400
Subject: [PATCH 55/69] mingetty: Rely on cc-wrapper to export this env var

---
 pkgs/os-specific/linux/mingetty/default.nix | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/pkgs/os-specific/linux/mingetty/default.nix b/pkgs/os-specific/linux/mingetty/default.nix
index 4e2888fa942a..a8348acd5d76 100644
--- a/pkgs/os-specific/linux/mingetty/default.nix
+++ b/pkgs/os-specific/linux/mingetty/default.nix
@@ -8,10 +8,6 @@ stdenv.mkDerivation {
     sha256 = "05yxrp44ky2kg6qknk1ih0kvwkgbn9fbz77r3vci7agslh5wjm8g";
   };
 
-  crossAttrs = {
-    makeFlags = "CC=${stdenv.cross.config}-gcc";
-  };
-
   preInstall = ''
     mkdir -p $out/sbin $out/share/man/man8
     makeFlagsArray=(SBINDIR=$out/sbin MANDIR=$out/share/man/man8)

From b8ed3c65bb23aeb845b45bafd44d920219d891a3 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:41:06 -0400
Subject: [PATCH 56/69] propcps: Rely on cc-wrapper to export this env var

---
 pkgs/os-specific/linux/procps-ng/default.nix | 4 ----
 pkgs/os-specific/linux/procps/watch.nix      | 4 ----
 2 files changed, 8 deletions(-)

diff --git a/pkgs/os-specific/linux/procps-ng/default.nix b/pkgs/os-specific/linux/procps-ng/default.nix
index c52dfbe461ae..bccae52c3675 100644
--- a/pkgs/os-specific/linux/procps-ng/default.nix
+++ b/pkgs/os-specific/linux/procps-ng/default.nix
@@ -15,10 +15,6 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
-  crossAttrs = {
-    CC = stdenv.cross.config + "-gcc";
-  };
-
   # Too red
   configureFlags = [ "--disable-modern-top" ];
 
diff --git a/pkgs/os-specific/linux/procps/watch.nix b/pkgs/os-specific/linux/procps/watch.nix
index 2547e26def4b..5fdd1287a647 100644
--- a/pkgs/os-specific/linux/procps/watch.nix
+++ b/pkgs/os-specific/linux/procps/watch.nix
@@ -15,10 +15,6 @@ stdenv.mkDerivation {
 
   enableParallelBuilding = true;
 
-  crossAttrs = {
-    CC = stdenv.cross.config + "-gcc";
-  };
-
   installPhase = "mkdir $out; mkdir -p $out/bin; cp -p watch $out/bin";
 
   meta = {

From a291194d2f38a7cf300d29ddd4a928409769a508 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:42:27 -0400
Subject: [PATCH 57/69] shadow: Don't use stdenv ? cross

---
 pkgs/os-specific/linux/shadow/default.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/os-specific/linux/shadow/default.nix b/pkgs/os-specific/linux/shadow/default.nix
index 6d83c98a422e..0c0edde05e22 100644
--- a/pkgs/os-specific/linux/shadow/default.nix
+++ b/pkgs/os-specific/linux/shadow/default.nix
@@ -1,11 +1,13 @@
 { stdenv, fetchpatch, fetchFromGitHub, autoreconfHook, libxslt, libxml2
 , docbook_xml_dtd_412, docbook_xsl, gnome_doc_utils, flex, bison
-, pam ? null, glibcCross ? null }:
+, pam ? null, glibcCross ? null
+, buildPlatform, hostPlatform
+}:
 
 let
 
   glibc =
-    if stdenv ? cross
+    if hostPlatform != buildPlatform
     then glibcCross
     else assert stdenv ? glibc; stdenv.glibc;
 

From 14d3ed8c386d8444e59b342617f9ccef343382a2 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:43:18 -0400
Subject: [PATCH 58/69] sysvinit: Rely on cc-wrapper to export this env var

---
 pkgs/os-specific/linux/sysvinit/default.nix | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/pkgs/os-specific/linux/sysvinit/default.nix b/pkgs/os-specific/linux/sysvinit/default.nix
index 042e601ec14f..6ec8abdc1760 100644
--- a/pkgs/os-specific/linux/sysvinit/default.nix
+++ b/pkgs/os-specific/linux/sysvinit/default.nix
@@ -15,11 +15,7 @@ stdenv.mkDerivation {
     sed -i -e "s,/sbin/,$out/sbin/," src/halt.c src/init.c src/paths.h
   '';
 
-  makeFlags = "SULOGINLIBS=-lcrypt ROOT=$(out) MANDIR=/share/man";
-
-  crossAttrs = {
-    makeFlags = "SULOGINLIBS=-lcrypt ROOT=$(out) MANDIR=/share/man CC=${stdenv.cross.config}-gcc";
-  };
+  makeFlags = [ "SULOGINLIBS=-lcrypt" "ROOT=$(out)" "MANDIR=/share/man" ];
 
   preInstall =
     ''

From c4ab3ef580704a00e2de00180de089043da2e0e2 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:44:00 -0400
Subject: [PATCH 59/69] jom: Don't use stdenc.cross

---
 pkgs/os-specific/windows/jom/default.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pkgs/os-specific/windows/jom/default.nix b/pkgs/os-specific/windows/jom/default.nix
index 6537503add8f..b2b23f200455 100644
--- a/pkgs/os-specific/windows/jom/default.nix
+++ b/pkgs/os-specific/windows/jom/default.nix
@@ -18,7 +18,7 @@ stdenv.mkDerivation {
   QTDIR = qt48;
   
   crossAttrs = {
-    # cmakeFlags = "-DWIN32=1 -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_RC_COMPILER=${stdenv.cross.config}-windres";
+    # cmakeFlags = "-DWIN32=1 -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_RC_COMPILER=${stdenv.cc.prefix}windres";
     QTDIR = qt48.crossDrv;
     preBuild = ''
       export NIX_CROSS_CFLAGS_COMPILE=-fpermissive

From 2f37cad1b976ceec47d92dc1e3bc9456cf49ea1f Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:44:54 -0400
Subject: [PATCH 60/69] wxMSW-2.8: Don't use stdenv ? cross

---
 pkgs/os-specific/windows/pthread-w32/default.nix | 2 +-
 pkgs/os-specific/windows/wxMSW-2.8/default.nix   | 9 ++-------
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/pkgs/os-specific/windows/pthread-w32/default.nix b/pkgs/os-specific/windows/pthread-w32/default.nix
index dde4f5d73711..f0b6852d5bf9 100644
--- a/pkgs/os-specific/windows/pthread-w32/default.nix
+++ b/pkgs/os-specific/windows/pthread-w32/default.nix
@@ -1,7 +1,7 @@
 { fetchurl, stdenv, mingw_headers }:
 
 # This file is tweaked for cross-compilation only.
-assert stdenv ? cross;
+assert hostPlatform != buildPlatform;
 
 stdenv.mkDerivation {
   name = "pthread-w32-1.10.0";
diff --git a/pkgs/os-specific/windows/wxMSW-2.8/default.nix b/pkgs/os-specific/windows/wxMSW-2.8/default.nix
index 5c79460060ad..6c52ce1e6f38 100644
--- a/pkgs/os-specific/windows/wxMSW-2.8/default.nix
+++ b/pkgs/os-specific/windows/wxMSW-2.8/default.nix
@@ -1,7 +1,8 @@
 { stdenv, fetchurl, compat24 ? false, compat26 ? true, unicode ? true,
+, hostPlatform
 }:
 
-assert stdenv ? cross -> stdenv.cross.libc == "msvcrt";
+assert hostPlatform.isWindows;
 
 stdenv.mkDerivation {
   name = "wxMSW-2.8.11";
@@ -19,12 +20,6 @@ stdenv.mkDerivation {
     "--with-opengl"
   ];
 
-  # Cross build only tested for mingw32
-  checkCross = throw "This package can only be cross-built" false;
-  crossAttrs = {
-    checkCross = true;
-  };
-
   preConfigure = "
     substituteInPlace configure --replace /usr /no-such-path
   ";

From 1b882edf780a6260cb0a5288a3582ca4d9db82cf Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:46:25 -0400
Subject: [PATCH 61/69] mtdutils: Rely on cc-wrapper to export this env var

---
 pkgs/tools/filesystems/mtdutils/default.nix | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/pkgs/tools/filesystems/mtdutils/default.nix b/pkgs/tools/filesystems/mtdutils/default.nix
index ed3850b9fdd6..d0ceaf94a75f 100644
--- a/pkgs/tools/filesystems/mtdutils/default.nix
+++ b/pkgs/tools/filesystems/mtdutils/default.nix
@@ -15,10 +15,6 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ libuuid lzo zlib acl ];
 
-  crossAttrs = {
-    makeFlags = "CC=${stdenv.cross.config}-gcc";
-  };
-
   meta = {
     description = "Tools for MTD filesystems";
     license = stdenv.lib.licenses.gpl2Plus;

From 822084fa37192b41fb234e01a220efa064c0d64b Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:47:36 -0400
Subject: [PATCH 62/69] tcpdump: Don't use stdenv.cross

---
 pkgs/tools/networking/tcpdump/default.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/tools/networking/tcpdump/default.nix b/pkgs/tools/networking/tcpdump/default.nix
index 42cb3867e05c..a7130a3891b9 100644
--- a/pkgs/tools/networking/tcpdump/default.nix
+++ b/pkgs/tools/networking/tcpdump/default.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchurl, libpcap, enableStatic ? false }:
+{ stdenv, fetchurl, libpcap, enableStatic ? false
+, hostPlatform
+}:
 
 stdenv.mkDerivation rec {
   name = "tcpdump-${version}";
@@ -15,7 +17,7 @@ stdenv.mkDerivation rec {
   crossAttrs = {
     LDFLAGS = if enableStatic then "-static" else "";
     configureFlags = [ "ac_cv_linux_vers=2" ] ++ (stdenv.lib.optional
-      (stdenv.cross.platform.kernelMajor == "2.4") "--disable-ipv6");
+      (hostPlatform.platform.kernelMajor == "2.4") "--disable-ipv6");
   };
 
   meta = {

From 40be9738abfcde500937f1d7e2356164e77658e8 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:48:43 -0400
Subject: [PATCH 63/69] nix: Don't use stdenv.cross

---
 pkgs/tools/package-management/nix/default.nix | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/pkgs/tools/package-management/nix/default.nix b/pkgs/tools/package-management/nix/default.nix
index 3aa18fad9423..45dfd52dba19 100644
--- a/pkgs/tools/package-management/nix/default.nix
+++ b/pkgs/tools/package-management/nix/default.nix
@@ -2,6 +2,7 @@
 , pkgconfig, boehmgc, perlPackages, libsodium, aws-sdk-cpp, brotli, readline
 , autoreconfHook, autoconf-archive, bison, flex, libxml2, libxslt, docbook5, docbook5_xsl
 , libseccomp, busybox
+, hostPlatform
 , storeDir ? "/nix/store"
 , stateDir ? "/nix/var"
 , confDir ? "/etc"
@@ -95,8 +96,8 @@ let
           --disable-init-state
           --enable-gc
         '' + stdenv.lib.optionalString (
-            stdenv.cross ? nix && stdenv.cross.nix ? system
-        ) ''--with-system=${stdenv.cross.nix.system}'';
+            hostPlatform ? nix && hostPlatform.nix ? system
+        ) ''--with-system=${hostPlatform.nix.system}'';
 
       doInstallCheck = false;
     };

From 82a09181a4bac183b98084d7e1f463d8c98afff6 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:55:16 -0400
Subject: [PATCH 64/69] tm: Rely on cc-wrapper to export this env var

---
 pkgs/tools/system/tm/default.nix | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/pkgs/tools/system/tm/default.nix b/pkgs/tools/system/tm/default.nix
index 3326f535b5f6..3442dbb62b05 100644
--- a/pkgs/tools/system/tm/default.nix
+++ b/pkgs/tools/system/tm/default.nix
@@ -10,10 +10,6 @@ stdenv.mkDerivation {
     sed -i 's@/usr/bin/install@install@g ; s/gcc/cc/g' Makefile
   '';
 
-  crossAttrs = {
-    makeFlags = "CC=${stdenv.cross.config}-gcc";
-  };
-
   src = fetchurl {
     url = http://vicerveza.homeunix.net/~viric/soft/tm/tm-0.4.1.tar.gz;
     sha256 = "3b389bc03b6964ad5ffa57a344b891fdbcf7c9b2604adda723a863f83657c4a0";

From 60ce1e3b901013f5e5715c51a799940efc6cc2a4 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:55:50 -0400
Subject: [PATCH 65/69] ts: Rely on cc-wrapper to export this env var

---
 pkgs/tools/system/ts/default.nix | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/pkgs/tools/system/ts/default.nix b/pkgs/tools/system/ts/default.nix
index 97b35378673e..cce18b5d54b4 100644
--- a/pkgs/tools/system/ts/default.nix
+++ b/pkgs/tools/system/ts/default.nix
@@ -1,5 +1,6 @@
-{stdenv, fetchurl,
-sendmailPath ? "/run/wrappers/bin/sendmail" }:
+{ stdenv, fetchurl
+, sendmailPath ? "/run/wrappers/bin/sendmail"
+}:
 
 stdenv.mkDerivation rec {
 
@@ -7,10 +8,6 @@ stdenv.mkDerivation rec {
 
   installPhase=''make install "PREFIX=$out"'';
 
-  crossAttrs = {
-    makeFlags = "CC=${stdenv.cross.config}-gcc";
-  };
-
   patchPhase = ''
     sed -i s,/usr/sbin/sendmail,${sendmailPath}, mail.c ts.1
   '';

From 936196129d0cf8500106bbd66c25d18b19dae3ec Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:56:12 -0400
Subject: [PATCH 66/69] html-tidy: Don't use stdenv.cross

---
 pkgs/tools/text/html-tidy/default.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/tools/text/html-tidy/default.nix b/pkgs/tools/text/html-tidy/default.nix
index 1a264885b485..cc3283cf8541 100644
--- a/pkgs/tools/text/html-tidy/default.nix
+++ b/pkgs/tools/text/html-tidy/default.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchFromGitHub, cmake, libxslt }:
+{ stdenv, fetchFromGitHub, cmake, libxslt
+, hostPlatform
+}:
 
 stdenv.mkDerivation rec {
   name = "html-tidy-${version}";
@@ -14,7 +16,7 @@ stdenv.mkDerivation rec {
   nativeBuildInputs = [ cmake libxslt/*manpage*/ ];
 
   cmakeFlags = stdenv.lib.optional
-    (stdenv.cross.libc or null == "msvcrt") "-DCMAKE_SYSTEM_NAME=Windows";
+    (hostPlatform.libc or null == "msvcrt") "-DCMAKE_SYSTEM_NAME=Windows";
 
   # ATM bin/tidy is statically linked, as upstream provides no other option yet.
   # https://github.com/htacg/tidy-html5/issues/326#issuecomment-160322107

From 10685e395655b0ccf5e863d948c79dd153db923e Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 16:57:08 -0400
Subject: [PATCH 67/69] replace: Rely on cc-wrapper to export env var

---
 pkgs/tools/text/replace/default.nix | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/pkgs/tools/text/replace/default.nix b/pkgs/tools/text/replace/default.nix
index 40728c2c3ec5..18ef074c8a52 100644
--- a/pkgs/tools/text/replace/default.nix
+++ b/pkgs/tools/text/replace/default.nix
@@ -1,4 +1,4 @@
-{stdenv, fetchurl}:
+{ stdenv, fetchurl }:
 
 stdenv.mkDerivation {
   name = "replace-2.24";
@@ -10,10 +10,6 @@ stdenv.mkDerivation {
 
   makeFlags = "TREE=\$(out) MANTREE=\$(TREE)/share/man";
 
-  crossAttrs = {
-    makeFlags = "TREE=\$(out) MANTREE=\$(TREE)/share/man CC=${stdenv.cross.config}-gcc";
-  };
-
   preBuild = ''
     sed -e "s@/bin/mv@$(type -P mv)@" -i replace.h
   '';

From 9f156f4a8a945dee1beeb49f6c2acb395c0af9c8 Mon Sep 17 00:00:00 2001
From: hsloan <ishaqsloan@gmail.com>
Date: Wed, 28 Jun 2017 17:39:33 -0400
Subject: [PATCH 68/69] top-level: stdenv.cross vanquished

---
 doc/cross-compilation.xml | 5 -----
 pkgs/top-level/stage.nix  | 2 --
 2 files changed, 7 deletions(-)

diff --git a/doc/cross-compilation.xml b/doc/cross-compilation.xml
index 7ff354376116..650db718665c 100644
--- a/doc/cross-compilation.xml
+++ b/doc/cross-compilation.xml
@@ -79,11 +79,6 @@
         </listitem>
       </varlistentry>
     </variablelist>
-    <note><para>
-      If you dig around nixpkgs, you may notice there is also <varname>stdenv.cross</varname>.
-      This field defined as <varname>hostPlatform</varname> when the host and build platforms differ, but otherwise not defined at all.
-      This field is obsolete and will soon disappear—please do not use it.
-    </para></note>
     <para>
       The exact schema these fields follow is a bit ill-defined due to a long and convoluted evolution, but this is slowly being cleaned up.
       You can see examples of ones used in practice in <literal>lib.systems.examples</literal>; note how they are not all very consistent.
diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix
index f6e7f41ed883..2a8f4ff4b3cf 100644
--- a/pkgs/top-level/stage.nix
+++ b/pkgs/top-level/stage.nix
@@ -110,8 +110,6 @@ let
   in {
     stdenv = super.stdenv // {
       inherit (buildPlatform) platform;
-    } // lib.optionalAttrs (hostPlatform != buildPlatform) {
-      cross = hostPlatform;
     };
     inherit (buildPlatform) system platform;
   };

From b0ada07f36abc21c990000b5cdbe780157d6b92b Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed, 28 Jun 2017 22:31:24 -0400
Subject: [PATCH 69/69] wxMSW: Fix syntax --- travis eval did not catch

---
 pkgs/os-specific/windows/wxMSW-2.8/default.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pkgs/os-specific/windows/wxMSW-2.8/default.nix b/pkgs/os-specific/windows/wxMSW-2.8/default.nix
index 6c52ce1e6f38..8770140cc633 100644
--- a/pkgs/os-specific/windows/wxMSW-2.8/default.nix
+++ b/pkgs/os-specific/windows/wxMSW-2.8/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, compat24 ? false, compat26 ? true, unicode ? true,
+{ stdenv, fetchurl, compat24 ? false, compat26 ? true, unicode ? true
 , hostPlatform
 }: