summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Bauer <mjbauer95@gmail.com>2019-04-26 22:20:03 -0400
committerGitHub <noreply@github.com>2019-04-26 22:20:03 -0400
commit87944c3125c4e69a69e76003c0ed5bf47bf0c4d8 (patch)
tree6c6e4f084e2ed6567719d44b4dd377829cd2c6f8
parent1cf626ce29f154c5742196327e03dbd61d0ed988 (diff)
parentc1f1a0ea159a4513be524fa775ad708debd19aa1 (diff)
downloadnixpkgs-87944c3125c4e69a69e76003c0ed5bf47bf0c4d8.tar
nixpkgs-87944c3125c4e69a69e76003c0ed5bf47bf0c4d8.tar.gz
nixpkgs-87944c3125c4e69a69e76003c0ed5bf47bf0c4d8.tar.bz2
nixpkgs-87944c3125c4e69a69e76003c0ed5bf47bf0c4d8.tar.lz
nixpkgs-87944c3125c4e69a69e76003c0ed5bf47bf0c4d8.tar.xz
nixpkgs-87944c3125c4e69a69e76003c0ed5bf47bf0c4d8.tar.zst
nixpkgs-87944c3125c4e69a69e76003c0ed5bf47bf0c4d8.zip
Merge pull request #56744 from matthewbauer/macos-10-12
Update macOS to 10.12
-rw-r--r--pkgs/applications/audio/fluidsynth/default.nix1
-rw-r--r--pkgs/applications/editors/emacs/macport.nix2
-rw-r--r--pkgs/applications/graphics/imgcat/default.nix2
-rw-r--r--pkgs/applications/misc/tthsum/default.nix2
-rw-r--r--pkgs/applications/networking/browsers/firefox/common.nix8
-rw-r--r--pkgs/applications/networking/instant-messengers/spectral/default.nix4
-rw-r--r--pkgs/applications/science/astronomy/xplanet/default.nix2
-rw-r--r--pkgs/applications/science/biology/cmtk/default.nix2
-rw-r--r--pkgs/build-support/setup-hooks/patch-shebangs.sh53
-rw-r--r--pkgs/build-support/wrapper-common/utils.bash3
-rw-r--r--pkgs/desktops/gnome-3/core/dconf/default.nix2
-rw-r--r--pkgs/desktops/gnustep/default.nix6
-rw-r--r--pkgs/development/compilers/gcc/4.8/default.nix1
-rw-r--r--pkgs/development/compilers/gcc/4.9/default.nix1
-rw-r--r--pkgs/development/compilers/gcc/5/default.nix1
-rw-r--r--pkgs/development/compilers/go/1.10.nix6
-rw-r--r--pkgs/development/compilers/go/1.11.nix7
-rw-r--r--pkgs/development/compilers/go/1.12.nix5
-rw-r--r--pkgs/development/compilers/ldc/default.nix2
-rw-r--r--pkgs/development/compilers/llvm/3.7/libc++/default.nix1
-rw-r--r--pkgs/development/compilers/llvm/4/lld.nix1
-rw-r--r--pkgs/development/compilers/llvm/5/lld.nix1
-rw-r--r--pkgs/development/compilers/llvm/7/compiler-rt-clock_gettime.patch74
-rw-r--r--pkgs/development/compilers/llvm/7/compiler-rt.nix5
-rw-r--r--pkgs/development/compilers/llvm/8/compiler-rt-clock_gettime.patch74
-rw-r--r--pkgs/development/compilers/llvm/8/compiler-rt.nix3
-rw-r--r--pkgs/development/compilers/rust/default.nix11
-rw-r--r--pkgs/development/haskell-modules/configuration-nix.nix19
-rw-r--r--pkgs/development/interpreters/guile/2.0.nix9
-rw-r--r--pkgs/development/interpreters/guile/default.nix8
-rw-r--r--pkgs/development/interpreters/guile/filter-mkostemp-darwin.patch28
-rw-r--r--pkgs/development/libraries/boost/1.67.nix32
-rw-r--r--pkgs/development/libraries/boost/generic.nix5
-rw-r--r--pkgs/development/libraries/bullet/default.nix2
-rw-r--r--pkgs/development/libraries/clucene-core/2.x.nix2
-rw-r--r--pkgs/development/libraries/libao/default.nix2
-rw-r--r--pkgs/development/libraries/libcdio/default.nix2
-rw-r--r--pkgs/development/libraries/libdrm/default.nix5
-rw-r--r--pkgs/development/libraries/libdrm/libdrm-apple.patch88
-rw-r--r--pkgs/development/libraries/libproxy/default.nix8
-rw-r--r--pkgs/development/libraries/libsnark/darwin-fix-clock-gettime.patch41
-rw-r--r--pkgs/development/libraries/libsnark/default.nix2
-rw-r--r--pkgs/development/libraries/libtins/default.nix6
-rw-r--r--pkgs/development/libraries/mesa/darwin-clock-gettime.patch76
-rw-r--r--pkgs/development/libraries/mesa/default.nix2
-rw-r--r--pkgs/development/libraries/qt-4.x/4.8/default.nix1
-rw-r--r--pkgs/development/libraries/qt-5/5.11/default.nix32
-rw-r--r--pkgs/development/libraries/qt-5/5.11/qtbase-darwin-nseventtype.patch13
-rw-r--r--pkgs/development/libraries/qt-5/5.11/qtbase-darwin-revert-69221.patch73
-rw-r--r--pkgs/development/libraries/qt-5/5.11/qtbase-darwin.patch70
-rw-r--r--pkgs/development/libraries/qt-5/5.11/qtbase-revert-no-macos10.10.patch102
-rw-r--r--pkgs/development/libraries/qt-5/5.11/qtwebengine-clang-fix.patch30
-rw-r--r--pkgs/development/libraries/qt-5/5.11/qtwebengine-darwin-old-sdk.patch21
-rw-r--r--pkgs/development/libraries/qt-5/5.11/qtwebengine-darwin-sdk-10.10.patch160
-rw-r--r--pkgs/development/libraries/qt-5/5.11/qtwebkit-darwin-no-qos-classes.patch11
-rw-r--r--pkgs/development/libraries/qt-5/5.11/qtwebkit-darwin-no-readline.patch45
-rw-r--r--pkgs/development/libraries/qt-5/5.12/default.nix12
-rw-r--r--pkgs/development/libraries/qt-5/5.12/qtbase-darwin-nseventtype.patch13
-rw-r--r--pkgs/development/libraries/qt-5/5.12/qtbase-darwin.patch70
-rw-r--r--pkgs/development/libraries/qt-5/5.12/qtbase-revert-no-macos10.10.patch102
-rw-r--r--pkgs/development/libraries/qt-5/5.9/default.nix2
-rw-r--r--pkgs/development/libraries/qt-5/5.9/qtbase-darwin.patch35
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtbase.nix36
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtwebengine.nix18
-rw-r--r--pkgs/development/libraries/science/math/fenics/default.nix9
-rw-r--r--pkgs/development/libraries/tk/generic.nix4
-rw-r--r--pkgs/development/libraries/wxwidgets/2.9/default.nix3
-rw-r--r--pkgs/development/libraries/wxwidgets/3.0/default.nix1
-rw-r--r--pkgs/development/libraries/wxwidgets/3.0/mac.nix1
-rw-r--r--pkgs/development/python-modules/cffi/default.nix2
-rw-r--r--pkgs/development/python-modules/cryptography/default.nix8
-rw-r--r--pkgs/development/python-modules/matplotlib/2.nix2
-rw-r--r--pkgs/development/python-modules/matplotlib/darwin-stdenv-2.2.3.patch10
-rw-r--r--pkgs/development/python-modules/matplotlib/darwin-stdenv.patch12
-rw-r--r--pkgs/development/python-modules/matplotlib/default.nix3
-rw-r--r--pkgs/development/python-modules/paho-mqtt/default.nix4
-rw-r--r--pkgs/development/python-modules/papis/default.nix3
-rw-r--r--pkgs/development/python-modules/sqlalchemy-migrate/default.nix2
-rw-r--r--pkgs/development/python-modules/xlib/default.nix2
-rw-r--r--pkgs/development/python-modules/xml2rfc/default.nix3
-rw-r--r--pkgs/development/python-modules/zope_testrunner/default.nix2
-rw-r--r--pkgs/development/tools/analysis/valgrind/default.nix8
-rw-r--r--pkgs/development/tools/build-managers/cmake/application-services.patch12
-rw-r--r--pkgs/development/tools/build-managers/cmake/default.nix3
-rw-r--r--pkgs/development/tools/build-managers/dub/default.nix2
-rw-r--r--pkgs/development/tools/misc/gnum4/darwin-secure-format.patch (renamed from pkgs/stdenv/darwin/darwin-secure-format.patch)0
-rw-r--r--pkgs/development/tools/misc/gnum4/default.nix3
-rw-r--r--pkgs/development/tools/misc/tokei/default.nix4
-rw-r--r--pkgs/development/tools/xcbuild/toolchains.nix1
-rw-r--r--pkgs/development/tools/xcbuild/wrapper.nix14
-rw-r--r--pkgs/games/gargoyle/darwin.patch64
-rw-r--r--pkgs/games/gargoyle/default.nix2
-rw-r--r--pkgs/games/quake2/yquake2/default.nix2
-rw-r--r--pkgs/misc/jackaudio/default.nix1
-rw-r--r--pkgs/os-specific/darwin/apple-sdk/default.nix38
-rw-r--r--pkgs/os-specific/darwin/apple-sdk/frameworks.nix20
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/Libc/CrashReporterClient.h51
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/Libc/default.nix2
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix47
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/Libsystem/system_c_symbols27
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/Libsystem/system_kernel_symbols158
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/Security/boot.nix116
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/Security/default.nix119
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/SmartCardServices/default.nix42
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/adv_cmds/boot.nix91
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/adv_cmds/default.nix103
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/adv_cmds/xcode.nix59
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/bootstrap_cmds/default.nix1
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/default.nix139
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/diskdev_cmds/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/dtrace/default.nix79
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/dtrace/xcode.nix47
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/file_cmds/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/hfs/default.nix8
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_csp/GNUmakefile11
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_csp/default.nix31
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_cspdl/GNUmakefile10
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_cspdl/default.nix16
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_file_dl/GNUmakefile10
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_file_dl/default.nix17
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_cl/GNUmakefile10
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_cl/default.nix18
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_tp/GNUmakefile11
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_tp/default.nix19
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_asn1/GNUmakefile11
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_asn1/default.nix14
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_client/GNUmakefile10
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_client/default.nix8
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_plugin/GNUmakefile10
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_plugin/default.nix15
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utilities/GNUmakefile13
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utilities/default.nix13
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utilities/handletemplates.patch19
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utils/GNUmakefile13
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utils/default.nix8
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_codesigning/GNUmakefile10
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_codesigning/default.nix33
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_cssm/GNUmakefile11
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_cssm/default.nix14
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_filedb/GNUmakefile10
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_filedb/default.nix13
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_generic/default.nix63
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_generic/impure_deps.nix128
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_keychain/GNUmakefile10
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_keychain/default.nix43
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_mds/GNUmakefile10
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_mds/default.nix11
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_ocspd/GNUmakefile10
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_ocspd/default.nix20
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_pkcs12/GNUmakefile11
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_pkcs12/default.nix15
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_sd_cspdl/GNUmakefile10
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_sd_cspdl/default.nix10
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_utilities/GNUmakefile11
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurity_utilities/default.nix28
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurityd/GNUmakefile11
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurityd/default.nix23
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libsecurityd/xdr-arity.patch79
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libutil/default.nix26
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libutil/new.nix29
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/security_dotmac_tp/GNUmakefile8
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/security_dotmac_tp/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/security_systemkeychain/default.nix32
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/top/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix93
-rw-r--r--pkgs/os-specific/darwin/binutils/default.nix2
-rw-r--r--pkgs/os-specific/darwin/cctools/apfs.patch22
-rw-r--r--pkgs/os-specific/darwin/cctools/ld-tbd-v2.patch98
-rw-r--r--pkgs/os-specific/darwin/cctools/port.nix64
-rw-r--r--pkgs/os-specific/darwin/cctools/support-ios.patch13
-rw-r--r--pkgs/os-specific/darwin/cctools/undo-unknown-triple.patch17
-rw-r--r--pkgs/os-specific/darwin/cf-private/default.nix5
-rw-r--r--pkgs/os-specific/darwin/darling/default.nix3
-rw-r--r--pkgs/os-specific/darwin/libtapi/default.nix29
-rw-r--r--pkgs/os-specific/darwin/osx-private-sdk/default.nix27
-rw-r--r--pkgs/os-specific/darwin/security-tool/GNUmakefile14
-rw-r--r--pkgs/os-specific/darwin/security-tool/default.nix101
-rw-r--r--pkgs/stdenv/darwin/default.nix51
-rw-r--r--pkgs/stdenv/darwin/make-bootstrap-tools.nix8
-rw-r--r--pkgs/stdenv/generic/setup.sh11
-rw-r--r--pkgs/tools/archivers/gnutar/default.nix1
-rw-r--r--pkgs/tools/archivers/p7zip/default.nix2
-rw-r--r--pkgs/tools/compression/pbzip2/default.nix2
-rw-r--r--pkgs/tools/filesystems/e2fsprogs/default.nix4
-rw-r--r--pkgs/tools/filesystems/file-rename/default.nix2
-rw-r--r--pkgs/tools/misc/toybox/default.nix2
-rw-r--r--pkgs/tools/networking/ntopng/default.nix2
-rw-r--r--pkgs/tools/package-management/nix/default.nix5
-rw-r--r--pkgs/tools/security/opensc/default.nix2
-rw-r--r--pkgs/tools/security/tcpcrypt/default.nix6
-rw-r--r--pkgs/tools/text/platinum-searcher/default.nix5
-rw-r--r--pkgs/tools/text/sgml/opensp/default.nix20
-rw-r--r--pkgs/top-level/all-packages.nix89
-rw-r--r--pkgs/top-level/darwin-packages.nix14
-rw-r--r--pkgs/top-level/perl-packages.nix3
-rw-r--r--pkgs/top-level/release.nix1
196 files changed, 1217 insertions, 3280 deletions
diff --git a/pkgs/applications/audio/fluidsynth/default.nix b/pkgs/applications/audio/fluidsynth/default.nix
index 192670280cc..195431898a6 100644
--- a/pkgs/applications/audio/fluidsynth/default.nix
+++ b/pkgs/applications/audio/fluidsynth/default.nix
@@ -44,5 +44,6 @@ stdenv.mkDerivation  rec {
     license     = licenses.lgpl21Plus;
     maintainers = with maintainers; [ goibhniu lovek323 ];
     platforms   = platforms.unix;
+    badPlatforms = [ "x86_64-darwin" ];
   };
 }
diff --git a/pkgs/applications/editors/emacs/macport.nix b/pkgs/applications/editors/emacs/macport.nix
index 33c5da8642c..7c21c1cae5e 100644
--- a/pkgs/applications/editors/emacs/macport.nix
+++ b/pkgs/applications/editors/emacs/macport.nix
@@ -68,7 +68,7 @@ stdenv.mkDerivation rec {
     "--enable-mac-app=$$out/Applications"
   ];
 
-  CFLAGS = "-O3 -DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_10 -DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_10";
+  CFLAGS = "-O3";
   LDFLAGS = "-O3 -L${ncurses.out}/lib";
 
   postInstall = ''
diff --git a/pkgs/applications/graphics/imgcat/default.nix b/pkgs/applications/graphics/imgcat/default.nix
index a98029dd580..862d3a9dff5 100644
--- a/pkgs/applications/graphics/imgcat/default.nix
+++ b/pkgs/applications/graphics/imgcat/default.nix
@@ -22,6 +22,8 @@ stdenv.mkDerivation rec {
     sha256 = "0m83c33rzxvs0w214njql2c7q3fg06wnyijch3l2s88i7frl121f";
   };
 
+  NIX_CFLAGS_COMPILE = "-Wno-error";
+
   meta = with stdenv.lib; {
     description = "It's like cat, but for images";
     homepage = https://github.com/eddieantonio/imgcat;
diff --git a/pkgs/applications/misc/tthsum/default.nix b/pkgs/applications/misc/tthsum/default.nix
index 66bfcbcf4d9..dbac56abaa1 100644
--- a/pkgs/applications/misc/tthsum/default.nix
+++ b/pkgs/applications/misc/tthsum/default.nix
@@ -15,6 +15,8 @@ stdenv.mkDerivation rec {
     cp obj-unix/tthsum $out/bin
   '';
 
+  doCheck = !stdenv.isDarwin;
+
   meta = with stdenv.lib; {
     description = "An md5sum-alike program that works with Tiger/THEX hashes";
     longDescription = ''
diff --git a/pkgs/applications/networking/browsers/firefox/common.nix b/pkgs/applications/networking/browsers/firefox/common.nix
index 3fae28be2be..c0cfcf412c5 100644
--- a/pkgs/applications/networking/browsers/firefox/common.nix
+++ b/pkgs/applications/networking/browsers/firefox/common.nix
@@ -153,15 +153,9 @@ stdenv.mkDerivation rec {
   ]
   ++ lib.optionals (!isTorBrowserLike) [
     "-I${nss.dev}/include/nss"
-  ]
-  ++ lib.optional stdenv.isDarwin [
-    "-isystem ${llvmPackages.libcxx}/include/c++/v1"
-    "-DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_10"
   ];
 
-  postPatch = lib.optionalString stdenv.isDarwin ''
-    substituteInPlace js/src/jsmath.cpp --replace 'defined(HAVE___SINCOS)' 0
-  '' + lib.optionalString (lib.versionAtLeast ffversion "63.0" && !isTorBrowserLike) ''
+  postPatch = lib.optionalString (lib.versionAtLeast ffversion "63.0" && !isTorBrowserLike) ''
     substituteInPlace third_party/prio/prio/rand.c --replace 'nspr/prinit.h' 'prinit.h'
   '';
 
diff --git a/pkgs/applications/networking/instant-messengers/spectral/default.nix b/pkgs/applications/networking/instant-messengers/spectral/default.nix
index aff3cf82dc9..72069ec81c1 100644
--- a/pkgs/applications/networking/instant-messengers/spectral/default.nix
+++ b/pkgs/applications/networking/instant-messengers/spectral/default.nix
@@ -5,6 +5,7 @@
 # Not mentioned but seems needed
 , qtgraphicaleffects
 , qtdeclarative
+, qtmacextras
 }:
 
 let
@@ -37,7 +38,8 @@ in stdenv.mkDerivation rec {
 
   nativeBuildInputs = [ pkgconfig qmake makeWrapper ];
   buildInputs = [ qtbase qtquickcontrols2 qtmultimedia qtgraphicaleffects qtdeclarative ]
-    ++ stdenv.lib.optional stdenv.hostPlatform.isLinux libpulseaudio;
+    ++ stdenv.lib.optional stdenv.hostPlatform.isLinux libpulseaudio
+    ++ stdenv.lib.optional stdenv.hostPlatform.isDarwin qtmacextras;
 
   meta = with stdenv.lib; {
     description = "A glossy client for Matrix, written in QtQuick Controls 2 and C++";
diff --git a/pkgs/applications/science/astronomy/xplanet/default.nix b/pkgs/applications/science/astronomy/xplanet/default.nix
index 7abd83b6dc1..aae9adfed67 100644
--- a/pkgs/applications/science/astronomy/xplanet/default.nix
+++ b/pkgs/applications/science/astronomy/xplanet/default.nix
@@ -17,6 +17,8 @@ stdenv.mkDerivation rec {
     ./gcc6.patch
   ];
 
+  NIX_CFLAGS_COMPILE = "-Wno-error=c++11-narrowing";
+
   meta = {
     description = "Renders an image of the earth or other planets into the X root window";
     homepage = http://xplanet.sourceforge.net;
diff --git a/pkgs/applications/science/biology/cmtk/default.nix b/pkgs/applications/science/biology/cmtk/default.nix
index ed661db23e0..90766645ecb 100644
--- a/pkgs/applications/science/biology/cmtk/default.nix
+++ b/pkgs/applications/science/biology/cmtk/default.nix
@@ -11,6 +11,8 @@ stdenv.mkDerivation rec {
 
   buildInputs = [cmake];
 
+  NIX_CFLAGS_COMPILE = "-Wno-error=c++11-narrowing";
+
   meta = with stdenv.lib; {
     description     = "Computational Morphometry Toolkit ";
     longDescription = ''A software toolkit for computational morphometry of
diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh
index de36b7ffabd..f4a865e9668 100644
--- a/pkgs/build-support/setup-hooks/patch-shebangs.sh
+++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh
@@ -5,10 +5,32 @@
 # rewritten to /nix/store/<hash>/bin/python.  Interpreters that are
 # already in the store are left untouched.
 
-fixupOutputHooks+=('if [ -z "$dontPatchShebangs" -a -e "$prefix" ]; then patchShebangs "$prefix"; fi')
+fixupOutputHooks+=(patchShebangsAuto)
+
+# Run patch shebangs on a directory.
+# patchShebangs [--build | --host] directory
+
+# Flags:
+# --build : Lookup commands available at build-time
+# --host  : Lookup commands available at runtime
+
+# Example use cases,
+# $ patchShebangs --host /nix/store/...-hello-1.0/bin
+# $ patchShebangs --build configure
 
 patchShebangs() {
+    local pathName
+
+    if [ "$1" = "--host" ]; then
+        pathName=HOST_PATH
+        shift
+    elif [ "$1" = "--build" ]; then
+        pathName=PATH
+        shift
+    fi
+
     local dir="$1"
+
     header "patching script interpreter paths in $dir"
     local f
     local oldPath
@@ -27,6 +49,14 @@ patchShebangs() {
         oldInterpreterLine=$(head -1 "$f" | tail -c+3)
         read -r oldPath arg0 args <<< "$oldInterpreterLine"
 
+        if [ -z "$pathName" ]; then
+            if [ -n "$strictDeps" ] && [[ "$f" = "$NIX_STORE"* ]]; then
+                pathName=HOST_PATH
+            else
+                pathName=PATH
+            fi
+        fi
+
         if $(echo "$oldPath" | grep -q "/bin/env$"); then
             # Check for unsupported 'env' functionality:
             # - options: something starting with a '-'
@@ -35,14 +65,17 @@ patchShebangs() {
                 echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)"
                 exit 1
             fi
-            newPath="$(command -v "$arg0" || true)"
+
+            newPath="$(PATH="${!pathName}" command -v "$arg0" || true)"
         else
             if [ "$oldPath" = "" ]; then
                 # If no interpreter is specified linux will use /bin/sh. Set
                 # oldpath="/bin/sh" so that we get /nix/store/.../sh.
                 oldPath="/bin/sh"
             fi
-            newPath="$(command -v "$(basename "$oldPath")" || true)"
+
+            newPath="$(PATH="${!pathName}" command -v "$(basename "$oldPath")" || true)"
+
             args="$arg0 $args"
         fi
 
@@ -66,3 +99,17 @@ patchShebangs() {
 
     stopNest
 }
+
+patchShebangsAuto () {
+    if [ -z "$dontPatchShebangs" -a -e "$prefix" ]; then
+
+        # Dev output will end up being run on the build platform. An
+        # example case of this is sdl2-config. Otherwise, we can just
+        # use the runtime path (--host).
+        if [ "$output" != out ] && [ "$output" = "$outputDev" ]; then
+            patchShebangs --build "$prefix"
+        else
+            patchShebangs --host "$prefix"
+        fi
+    fi
+}
diff --git a/pkgs/build-support/wrapper-common/utils.bash b/pkgs/build-support/wrapper-common/utils.bash
index 12b596a83e6..4fd57162072 100644
--- a/pkgs/build-support/wrapper-common/utils.bash
+++ b/pkgs/build-support/wrapper-common/utils.bash
@@ -86,9 +86,6 @@ expandResponseParams() {
                 #shellcheck disable=SC2034
                 readarray -d '' params < <("@expandResponseParams@" "$@")
                 return 0
-            else
-                echo "Response files aren't supported during bootstrapping" >&2
-                return 1
             fi
         fi
     done
diff --git a/pkgs/desktops/gnome-3/core/dconf/default.nix b/pkgs/desktops/gnome-3/core/dconf/default.nix
index e20804d9e62..1a9516430d9 100644
--- a/pkgs/desktops/gnome-3/core/dconf/default.nix
+++ b/pkgs/desktops/gnome-3/core/dconf/default.nix
@@ -38,7 +38,7 @@ stdenv.mkDerivation rec {
     "-Dgtk_doc=true"
   ];
 
-  doCheck = !stdenv.isAarch64;
+  doCheck = !stdenv.isAarch64 && !stdenv.isDarwin;
 
   passthru = {
     updateScript = gnome3.updateScript {
diff --git a/pkgs/desktops/gnustep/default.nix b/pkgs/desktops/gnustep/default.nix
index ac324bc89a8..1fdf79ef9ae 100644
--- a/pkgs/desktops/gnustep/default.nix
+++ b/pkgs/desktops/gnustep/default.nix
@@ -1,4 +1,4 @@
-{ pkgs, newScope }:
+{ pkgs, newScope, stdenv, llvmPackages_6 }:
 
 let
   callPackage = newScope self;
@@ -10,7 +10,9 @@ let
     gorm = callPackage ./gorm {};
     projectcenter = callPackage ./projectcenter {};
     system_preferences = callPackage ./systempreferences {};
-    libobjc = callPackage ./libobjc2 {};
+    libobjc = callPackage ./libobjc2 {
+      stdenv = if stdenv.cc.isClang then llvmPackages_6.stdenv else stdenv;
+    };
     make = callPackage ./make {};
     back = callPackage ./back {};
     base = callPackage ./base { giflib = pkgs.giflib_4_1; };
diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix
index b9a24183cde..d03c2b64894 100644
--- a/pkgs/development/compilers/gcc/4.8/default.nix
+++ b/pkgs/development/compilers/gcc/4.8/default.nix
@@ -418,6 +418,7 @@ stdenv.mkDerivation ({
       stdenv.lib.platforms.freebsd ++
       stdenv.lib.platforms.illumos ++
       stdenv.lib.platforms.darwin;
+    badPlatforms = [ "x86_64-darwin" ];
   };
 }
 
diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix
index 36ad5b46b79..3ce5ea1f64c 100644
--- a/pkgs/development/compilers/gcc/4.9/default.nix
+++ b/pkgs/development/compilers/gcc/4.9/default.nix
@@ -430,6 +430,7 @@ stdenv.mkDerivation ({
       stdenv.lib.platforms.freebsd ++
       stdenv.lib.platforms.illumos ++
       stdenv.lib.platforms.darwin;
+    badPlatforms = [ "x86_64-darwin" ];
   };
 }
 
diff --git a/pkgs/development/compilers/gcc/5/default.nix b/pkgs/development/compilers/gcc/5/default.nix
index 2d7ac9497bb..e6115b10481 100644
--- a/pkgs/development/compilers/gcc/5/default.nix
+++ b/pkgs/development/compilers/gcc/5/default.nix
@@ -435,6 +435,7 @@ stdenv.mkDerivation ({
       stdenv.lib.platforms.freebsd ++
       stdenv.lib.platforms.illumos ++
       stdenv.lib.platforms.darwin;
+    badPlatforms = [ "x86_64-darwin" ];
   };
 }
 
diff --git a/pkgs/development/compilers/go/1.10.nix b/pkgs/development/compilers/go/1.10.nix
index 5dce1529a8b..d18d260b505 100644
--- a/pkgs/development/compilers/go/1.10.nix
+++ b/pkgs/development/compilers/go/1.10.nix
@@ -131,11 +131,6 @@ stdenv.mkDerivation rec {
     })
   ];
 
-  postPatch = optionalString stdenv.isDarwin ''
-    echo "substitute hardcoded dsymutil with ${llvm}/bin/llvm-dsymutil"
-    substituteInPlace "src/cmd/link/internal/ld/lib.go" --replace dsymutil ${llvm}/bin/llvm-dsymutil
-  '';
-
   GOOS = if stdenv.isDarwin then "darwin" else "linux";
   GOARCH = if stdenv.isDarwin then "amd64"
            else if stdenv.hostPlatform.system == "i686-linux" then "386"
@@ -187,5 +182,6 @@ stdenv.mkDerivation rec {
     license = licenses.bsd3;
     maintainers = with maintainers; [ cstrahan orivej velovix mic92 ];
     platforms = platforms.linux ++ platforms.darwin;
+    badPlatforms = [ "x86_64-darwin" ];
   };
 }
diff --git a/pkgs/development/compilers/go/1.11.nix b/pkgs/development/compilers/go/1.11.nix
index 1e3a63983f4..eec472fb88e 100644
--- a/pkgs/development/compilers/go/1.11.nix
+++ b/pkgs/development/compilers/go/1.11.nix
@@ -136,11 +136,6 @@ stdenv.mkDerivation rec {
     ./skip-test-extra-files-on-386.patch
   ];
 
-  postPatch = optionalString stdenv.isDarwin ''
-    echo "substitute hardcoded dsymutil with ${llvm}/bin/llvm-dsymutil"
-    substituteInPlace "src/cmd/link/internal/ld/lib.go" --replace dsymutil ${llvm}/bin/llvm-dsymutil
-  '';
-
   GOOS = stdenv.targetPlatform.parsed.kernel.name;
   GOARCH = goarch stdenv.targetPlatform;
   # GOHOSTOS/GOHOSTARCH must match the building system, not the host system.
@@ -188,7 +183,7 @@ stdenv.mkDerivation rec {
     (cd src && ./make.bash)
   '';
 
-  doCheck = stdenv.hostPlatform == stdenv.targetPlatform;
+  doCheck = stdenv.hostPlatform == stdenv.targetPlatform && !stdenv.isDarwin;
 
   checkPhase = ''
     runHook preCheck
diff --git a/pkgs/development/compilers/go/1.12.nix b/pkgs/development/compilers/go/1.12.nix
index 44304006f6b..68f9d1d531f 100644
--- a/pkgs/development/compilers/go/1.12.nix
+++ b/pkgs/development/compilers/go/1.12.nix
@@ -141,9 +141,6 @@ stdenv.mkDerivation rec {
 
   postPatch = ''
     find . -name '*.orig' -exec rm {} ';'
-  '' + optionalString stdenv.isDarwin ''
-    echo "substitute hardcoded dsymutil with ${llvm}/bin/llvm-dsymutil"
-    substituteInPlace "src/cmd/link/internal/ld/lib.go" --replace dsymutil ${llvm}/bin/llvm-dsymutil
   '';
 
   GOOS = stdenv.targetPlatform.parsed.kernel.name;
@@ -193,7 +190,7 @@ stdenv.mkDerivation rec {
     (cd src && ./make.bash)
   '';
 
-  doCheck = stdenv.hostPlatform == stdenv.targetPlatform;
+  doCheck = stdenv.hostPlatform == stdenv.targetPlatform && !stdenv.isDarwin;
 
   checkPhase = ''
     runHook preCheck
diff --git a/pkgs/development/compilers/ldc/default.nix b/pkgs/development/compilers/ldc/default.nix
index 71473be580e..043347889c8 100644
--- a/pkgs/development/compilers/ldc/default.nix
+++ b/pkgs/development/compilers/ldc/default.nix
@@ -150,7 +150,7 @@ stdenv.mkDerivation rec {
   else
     "";
 
-  doCheck = !bootstrapVersion;
+  doCheck = !bootstrapVersion && !stdenv.isDarwin;
 
   checkPhase = stdenv.lib.optionalString doCheck ''
     # Build default lib test runners
diff --git a/pkgs/development/compilers/llvm/3.7/libc++/default.nix b/pkgs/development/compilers/llvm/3.7/libc++/default.nix
index 462e35a483f..7b7ac7297ba 100644
--- a/pkgs/development/compilers/llvm/3.7/libc++/default.nix
+++ b/pkgs/development/compilers/llvm/3.7/libc++/default.nix
@@ -43,5 +43,6 @@ stdenv.mkDerivation rec {
     description = "A new implementation of the C++ standard library, targeting C++11";
     license = with stdenv.lib.licenses; [ ncsa mit ];
     platforms = stdenv.lib.platforms.unix;
+    badPlatforms = [ "x86_64-darwin" ];
   };
 }
diff --git a/pkgs/development/compilers/llvm/4/lld.nix b/pkgs/development/compilers/llvm/4/lld.nix
index 21b0c1c3601..cf6de26a9e8 100644
--- a/pkgs/development/compilers/llvm/4/lld.nix
+++ b/pkgs/development/compilers/llvm/4/lld.nix
@@ -27,5 +27,6 @@ stdenv.mkDerivation {
     homepage    = http://lld.llvm.org/;
     license     = stdenv.lib.licenses.ncsa;
     platforms   = stdenv.lib.platforms.all;
+    badPlatforms = [ "x86_64-darwin" ];
   };
 }
diff --git a/pkgs/development/compilers/llvm/5/lld.nix b/pkgs/development/compilers/llvm/5/lld.nix
index 9a47435cf14..bf23f80ef10 100644
--- a/pkgs/development/compilers/llvm/5/lld.nix
+++ b/pkgs/development/compilers/llvm/5/lld.nix
@@ -27,5 +27,6 @@ stdenv.mkDerivation {
     homepage    = http://lld.llvm.org/;
     license     = stdenv.lib.licenses.ncsa;
     platforms   = stdenv.lib.platforms.all;
+    badPlatforms = [ "x86_64-darwin" ];
   };
 }
diff --git a/pkgs/development/compilers/llvm/7/compiler-rt-clock_gettime.patch b/pkgs/development/compilers/llvm/7/compiler-rt-clock_gettime.patch
deleted file mode 100644
index f9323ed95c0..00000000000
--- a/pkgs/development/compilers/llvm/7/compiler-rt-clock_gettime.patch
+++ /dev/null
@@ -1,74 +0,0 @@
-commit f00c7bccf7955b7dfbb4859fd9019e9eb3349f2d
-Author: Tobias Mayer <tobim@fastmail.fm>
-Date:   Wed Feb 13 12:44:17 2019 +0100
-
-    Provide clock_gettime for xray on macos < 10.12
-
-diff --git a/lib/xray/xray_basic_logging.cc b/lib/xray/xray_basic_logging.cc
-index a46c151af..38aea6932 100644
---- a/lib/xray/xray_basic_logging.cc
-+++ b/lib/xray/xray_basic_logging.cc
-@@ -36,6 +36,29 @@
- #include "xray_tsc.h"
- #include "xray_utils.h"
- 
-+#if __MACH__
-+#include <mach/clock.h>
-+#include <mach/mach.h>
-+enum clockid_t {
-+    CLOCK_MONOTONIC = REALTIME_CLOCK,
-+    CLOCK_REALTIME = REALTIME_CLOCK
-+};
-+
-+int clock_gettime(clockid_t clock_id, struct timespec *ts) {
-+  if (ts != NULL) {
-+      clock_serv_t cclock;
-+      mach_timespec_t mts;
-+      host_get_clock_service(mach_host_self(), clock_id, &cclock);
-+      clock_get_time(cclock, &mts);
-+      mach_port_deallocate(mach_task_self(), cclock);
-+      ts->tv_sec = mts.tv_sec;
-+      ts->tv_nsec = mts.tv_nsec;
-+      return 0;
-+  }
-+  return -1;
-+}
-+#endif
-+
- namespace __xray {
- 
- SpinMutex LogMutex;
-diff --git a/lib/xray/xray_fdr_logging.cc b/lib/xray/xray_fdr_logging.cc
-index 4b308b27f..1d044c8fd 100644
---- a/lib/xray/xray_fdr_logging.cc
-+++ b/lib/xray/xray_fdr_logging.cc
-@@ -38,6 +38,29 @@
- #include "xray_tsc.h"
- #include "xray_utils.h"
- 
-+#if __MACH__
-+#include <mach/clock.h>
-+#include <mach/mach.h>
-+enum clockid_t {
-+    CLOCK_MONOTONIC = REALTIME_CLOCK,
-+    CLOCK_REALTIME = REALTIME_CLOCK
-+};
-+
-+int clock_gettime(clockid_t clock_id, struct timespec *ts) {
-+  if (ts != NULL) {
-+      clock_serv_t cclock;
-+      mach_timespec_t mts;
-+      host_get_clock_service(mach_host_self(), clock_id, &cclock);
-+      clock_get_time(cclock, &mts);
-+      mach_port_deallocate(mach_task_self(), cclock);
-+      ts->tv_sec = mts.tv_sec;
-+      ts->tv_nsec = mts.tv_nsec;
-+      return 0;
-+  }
-+  return -1;
-+}
-+#endif
-+
- namespace __xray {
- 
- atomic_sint32_t LoggingStatus = {XRayLogInitStatus::XRAY_LOG_UNINITIALIZED};
diff --git a/pkgs/development/compilers/llvm/7/compiler-rt.nix b/pkgs/development/compilers/llvm/7/compiler-rt.nix
index ed8e569c60e..989529ff8cc 100644
--- a/pkgs/development/compilers/llvm/7/compiler-rt.nix
+++ b/pkgs/development/compilers/llvm/7/compiler-rt.nix
@@ -26,9 +26,8 @@ stdenv.mkDerivation rec {
 
   patches = [
     ./compiler-rt-codesign.patch # Revert compiler-rt commit that makes codesign mandatory
-  ] ++ stdenv.lib.optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch
-    ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) ./crtbegin-and-end.patch
-    ++ stdenv.lib.optional stdenv.hostPlatform.isDarwin ./compiler-rt-clock_gettime.patch;
+  ] ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) ./crtbegin-and-end.patch
+    ++ stdenv.lib.optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch;
 
   # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks
   # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra
diff --git a/pkgs/development/compilers/llvm/8/compiler-rt-clock_gettime.patch b/pkgs/development/compilers/llvm/8/compiler-rt-clock_gettime.patch
deleted file mode 100644
index f9323ed95c0..00000000000
--- a/pkgs/development/compilers/llvm/8/compiler-rt-clock_gettime.patch
+++ /dev/null
@@ -1,74 +0,0 @@
-commit f00c7bccf7955b7dfbb4859fd9019e9eb3349f2d
-Author: Tobias Mayer <tobim@fastmail.fm>
-Date:   Wed Feb 13 12:44:17 2019 +0100
-
-    Provide clock_gettime for xray on macos < 10.12
-
-diff --git a/lib/xray/xray_basic_logging.cc b/lib/xray/xray_basic_logging.cc
-index a46c151af..38aea6932 100644
---- a/lib/xray/xray_basic_logging.cc
-+++ b/lib/xray/xray_basic_logging.cc
-@@ -36,6 +36,29 @@
- #include "xray_tsc.h"
- #include "xray_utils.h"
- 
-+#if __MACH__
-+#include <mach/clock.h>
-+#include <mach/mach.h>
-+enum clockid_t {
-+    CLOCK_MONOTONIC = REALTIME_CLOCK,
-+    CLOCK_REALTIME = REALTIME_CLOCK
-+};
-+
-+int clock_gettime(clockid_t clock_id, struct timespec *ts) {
-+  if (ts != NULL) {
-+      clock_serv_t cclock;
-+      mach_timespec_t mts;
-+      host_get_clock_service(mach_host_self(), clock_id, &cclock);
-+      clock_get_time(cclock, &mts);
-+      mach_port_deallocate(mach_task_self(), cclock);
-+      ts->tv_sec = mts.tv_sec;
-+      ts->tv_nsec = mts.tv_nsec;
-+      return 0;
-+  }
-+  return -1;
-+}
-+#endif
-+
- namespace __xray {
- 
- SpinMutex LogMutex;
-diff --git a/lib/xray/xray_fdr_logging.cc b/lib/xray/xray_fdr_logging.cc
-index 4b308b27f..1d044c8fd 100644
---- a/lib/xray/xray_fdr_logging.cc
-+++ b/lib/xray/xray_fdr_logging.cc
-@@ -38,6 +38,29 @@
- #include "xray_tsc.h"
- #include "xray_utils.h"
- 
-+#if __MACH__
-+#include <mach/clock.h>
-+#include <mach/mach.h>
-+enum clockid_t {
-+    CLOCK_MONOTONIC = REALTIME_CLOCK,
-+    CLOCK_REALTIME = REALTIME_CLOCK
-+};
-+
-+int clock_gettime(clockid_t clock_id, struct timespec *ts) {
-+  if (ts != NULL) {
-+      clock_serv_t cclock;
-+      mach_timespec_t mts;
-+      host_get_clock_service(mach_host_self(), clock_id, &cclock);
-+      clock_get_time(cclock, &mts);
-+      mach_port_deallocate(mach_task_self(), cclock);
-+      ts->tv_sec = mts.tv_sec;
-+      ts->tv_nsec = mts.tv_nsec;
-+      return 0;
-+  }
-+  return -1;
-+}
-+#endif
-+
- namespace __xray {
- 
- atomic_sint32_t LoggingStatus = {XRayLogInitStatus::XRAY_LOG_UNINITIALIZED};
diff --git a/pkgs/development/compilers/llvm/8/compiler-rt.nix b/pkgs/development/compilers/llvm/8/compiler-rt.nix
index 2b591cc94af..a8bbb1f719b 100644
--- a/pkgs/development/compilers/llvm/8/compiler-rt.nix
+++ b/pkgs/development/compilers/llvm/8/compiler-rt.nix
@@ -34,8 +34,7 @@ stdenv.mkDerivation rec {
   patches = [
     ./compiler-rt-codesign.patch # Revert compiler-rt commit that makes codesign mandatory
   ]# ++ stdenv.lib.optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch
-    ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) ./crtbegin-and-end.patch
-    ++ stdenv.lib.optional stdenv.hostPlatform.isDarwin ./compiler-rt-clock_gettime.patch;
+    ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) ./crtbegin-and-end.patch;
 
   # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks
   # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra
diff --git a/pkgs/development/compilers/rust/default.nix b/pkgs/development/compilers/rust/default.nix
index 47df7e716dc..5c3c0895207 100644
--- a/pkgs/development/compilers/rust/default.nix
+++ b/pkgs/development/compilers/rust/default.nix
@@ -2,6 +2,8 @@
 , buildPackages
 , newScope, callPackage
 , CoreFoundation, Security
+, llvmPackages_5
+, pkgsBuildTarget, pkgsBuildBuild, pkgsBuildHost
 }: rec {
   makeRustPlatform = { rustc, cargo, ... }: {
     rust = {
@@ -48,10 +50,15 @@
       buildRustPackages = buildPackages.rust.packages.stable;
       # Analogous to stdenv
       rustPlatform = makeRustPlatform self.buildRustPackages;
-      rustc = self.callPackage ./rustc.nix {
+      rustc = self.callPackage ./rustc.nix ({
         # Use boot package set to break cycle
         rustPlatform = bootRustPlatform;
-      };
+      } // lib.optionalAttrs (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) {
+        stdenv = llvmPackages_5.stdenv;
+        pkgsBuildBuild = pkgsBuildBuild // { targetPackages.stdenv = llvmPackages_5.stdenv; };
+        pkgsBuildHost = pkgsBuildBuild // { targetPackages.stdenv = llvmPackages_5.stdenv; };
+        pkgsBuildTarget = pkgsBuildTarget // { targetPackages.stdenv = llvmPackages_5.stdenv; };
+      });
       cargo = self.callPackage ./cargo.nix {
         # Use boot package set to break cycle
         rustPlatform = bootRustPlatform;
diff --git a/pkgs/development/haskell-modules/configuration-nix.nix b/pkgs/development/haskell-modules/configuration-nix.nix
index af5bd2220d4..1be90f902e6 100644
--- a/pkgs/development/haskell-modules/configuration-nix.nix
+++ b/pkgs/development/haskell-modules/configuration-nix.nix
@@ -128,25 +128,6 @@ self: super: builtins.intersectAttrs super {
   # the system-fileio tests use canonicalizePath, which fails in the sandbox
   system-fileio = if pkgs.stdenv.isDarwin then dontCheck super.system-fileio else super.system-fileio;
 
-  # Prevents needing to add `security_tool` as a run-time dependency for
-  # everything using x509-system to give access to the `security` executable.
-  x509-system = if pkgs.stdenv.hostPlatform.isDarwin && !pkgs.stdenv.cc.nativeLibc
-    then let inherit (pkgs.darwin) security_tool;
-      in pkgs.lib.overrideDerivation (addBuildDepend super.x509-system security_tool) (drv: {
-        # darwin.security_tool is broken in Mojave (#45042)
-
-        # We will use the system provided security for now.
-        # Beware this WILL break in sandboxes!
-
-        # TODO(matthewbauer): If someone really needs this to work in sandboxes,
-        # I think we can add a propagatedImpureHost dep here, but I’m hoping to
-        # get a proper fix available soonish.
-        postPatch = (drv.postPatch or "") + ''
-          substituteInPlace System/X509/MacOS.hs --replace security /usr/bin/security
-        '';
-      })
-    else super.x509-system;
-
   # https://github.com/NixOS/cabal2nix/issues/136 and https://github.com/NixOS/cabal2nix/issues/216
   gio = disableHardening (addPkgconfigDepend (addBuildTool super.gio self.buildHaskellPackages.gtk2hs-buildtools) pkgs.glib) ["fortify"];
   glib = disableHardening (addPkgconfigDepend (addBuildTool super.glib self.buildHaskellPackages.gtk2hs-buildtools) pkgs.glib) ["fortify"];
diff --git a/pkgs/development/interpreters/guile/2.0.nix b/pkgs/development/interpreters/guile/2.0.nix
index 17ca1d1dcd9..24266d59676 100644
--- a/pkgs/development/interpreters/guile/2.0.nix
+++ b/pkgs/development/interpreters/guile/2.0.nix
@@ -46,7 +46,14 @@
     })
     ./riscv.patch
   ] ++
-    (stdenv.lib.optional (coverageAnalysis != null) ./gcov-file-name.patch);
+    (stdenv.lib.optional (coverageAnalysis != null) ./gcov-file-name.patch)
+    ++ stdenv.lib.optionals stdenv.isDarwin [
+      (fetchpatch {
+        url = "https://gitlab.gnome.org/GNOME/gtk-osx/raw/52898977f165777ad9ef169f7d4818f2d4c9b731/patches/guile-clocktime.patch";
+        sha256 = "12wvwdna9j8795x59ldryv9d84c1j3qdk2iskw09306idfsis207";
+      })
+      ./filter-mkostemp-darwin.patch
+    ];
 
   # Explicitly link against libgcc_s, to work around the infamous
   # "libgcc_s.so.1 must be installed for pthread_cancel to work".
diff --git a/pkgs/development/interpreters/guile/default.nix b/pkgs/development/interpreters/guile/default.nix
index 5e458c6e2cc..fb8e75e8793 100644
--- a/pkgs/development/interpreters/guile/default.nix
+++ b/pkgs/development/interpreters/guile/default.nix
@@ -2,6 +2,7 @@
 , fetchurl, makeWrapper, gawk, pkgconfig
 , libffi, libtool, readline, gmp, boehmgc, libunistring
 , coverageAnalysis ? null
+, fetchpatch
 }:
 
 # Do either a coverage analysis build or a standard build.
@@ -42,8 +43,11 @@
   patches = [
     ./eai_system.patch
     ./riscv.patch
-  ] ++
-    (stdenv.lib.optional (coverageAnalysis != null) ./gcov-file-name.patch);
+  ] ++ stdenv.lib.optional (coverageAnalysis != null) ./gcov-file-name.patch
+    ++ stdenv.lib.optional stdenv.isDarwin (fetchpatch {
+      url = "https://gitlab.gnome.org/GNOME/gtk-osx/raw/52898977f165777ad9ef169f7d4818f2d4c9b731/patches/guile-clocktime.patch";
+      sha256 = "12wvwdna9j8795x59ldryv9d84c1j3qdk2iskw09306idfsis207";
+    });
 
   # Explicitly link against libgcc_s, to work around the infamous
   # "libgcc_s.so.1 must be installed for pthread_cancel to work".
diff --git a/pkgs/development/interpreters/guile/filter-mkostemp-darwin.patch b/pkgs/development/interpreters/guile/filter-mkostemp-darwin.patch
new file mode 100644
index 00000000000..8b9b853fb00
--- /dev/null
+++ b/pkgs/development/interpreters/guile/filter-mkostemp-darwin.patch
@@ -0,0 +1,28 @@
+Filter incompat. mkostemp(3) flags on macOS 10.12
+
+macOS Sierra introduces a mkostemp(3) function which is used when
+present. Contrary to the GNUlib version of mkostemp(3) that was used
+previously, this version fails with 'invalid argument' when flags other
+than from a specified set are passed. From mktemp(3):
+
+| The mkostemp() function is like mkstemp() but allows specifying
+| additional open(2) flags (defined in <fcntl.h>). The permitted flags
+| are O_APPEND, O_SHLOCK, O_EXLOCK and O_CLOEXEC.
+
+Signed-off-by: Clemens Lang <cal@macports.org>
+Upstream-Status: Submitted [https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24862#23]
+--- a/libguile/filesys.c.orig	2017-01-09 00:53:27.000000000 +0100
++++ b/libguile/filesys.c	2017-01-09 00:54:48.000000000 +0100
+@@ -1486,6 +1486,12 @@
+       mode_bits = scm_i_mode_bits (mode);
+     }
+ 
++#ifdef __APPLE__
++  /* macOS starting with 10.12 defines mkostemp(2) which is used if defined,
++   * but only accepts some flags according to its manpage. It fails with
++   * invalid argument when other flags are passed. */
++  open_flags &= O_APPEND | O_SHLOCK | O_EXLOCK | O_CLOEXEC;
++#endif
+   SCM_SYSCALL (rv = mkostemp (c_tmpl, open_flags));
+   if (rv == -1)
+     SCM_SYSERROR;
diff --git a/pkgs/development/libraries/boost/1.67.nix b/pkgs/development/libraries/boost/1.67.nix
index 938892ef355..406e63b9622 100644
--- a/pkgs/development/libraries/boost/1.67.nix
+++ b/pkgs/development/libraries/boost/1.67.nix
@@ -3,11 +3,33 @@
 callPackage ./generic.nix (args // rec {
   version = "1.67.0";
 
-  patches = [ (fetchpatch {
-    url = "https://github.com/boostorg/lockfree/commit/12726cda009a855073b9bedbdce57b6ce7763da2.patch";
-    sha256 = "0x65nkwzv8fdacj8sw5njl3v63jj19dirrpklbwy6qpsncw7fc7h";
-    stripLen = 1;
-  })];
+  patches = [
+    (fetchpatch {
+      url = "https://github.com/boostorg/lockfree/commit/12726cda009a855073b9bedbdce57b6ce7763da2.patch";
+      sha256 = "0x65nkwzv8fdacj8sw5njl3v63jj19dirrpklbwy6qpsncw7fc7h";
+      stripLen = 1;
+    })
+  ] ++ stdenv.lib.optionals stdenv.cc.isClang [
+    # Fixes https://github.com/boostorg/atomic/issues/15
+    (fetchpatch {
+      url = https://github.com/boostorg/atomic/commit/6e14ca24dab50ad4c1fa8c27c7dd6f1cb791b534.patch;
+      sha256 = "102g35ygvv8cxagp9651284xk4vybk93q2fm577y4mdxf5k46b7a";
+      stripLen = 1;
+    })
+
+    # Needed for the next patch
+    (fetchpatch {
+      url = https://github.com/boostorg/asio/commit/38cb19719748ad56b14d73ca1fff5828f36e5894.patch;
+      sha256 = "0cj9cxz9rfbsx8p8f5alxx00dq3r7g0vh23j68bbxbs9gq1arq2n";
+      stripLen = 1;
+    })
+    # Fixes https://github.com/boostorg/asio/pull/91
+    (fetchpatch {
+      url = https://github.com/boostorg/asio/commit/43874d5497414c67655d901e48c939ef01337edb.patch;
+      sha256 = "1c2ds164s2ygvpb4785p4ncv8ywbpm08cphirb99xp4mqvb693is";
+      stripLen = 1;
+    })
+  ];
 
   src = fetchurl {
     url = "mirror://sourceforge/boost/boost_1_67_0.tar.bz2";
diff --git a/pkgs/development/libraries/boost/generic.nix b/pkgs/development/libraries/boost/generic.nix
index 8ce44b878d0..c0c69b0fe70 100644
--- a/pkgs/development/libraries/boost/generic.nix
+++ b/pkgs/development/libraries/boost/generic.nix
@@ -114,8 +114,9 @@ stdenv.mkDerivation {
     description = "Collection of C++ libraries";
     license = stdenv.lib.licenses.boost;
 
-    platforms = (platforms.unix ++ platforms.windows);
-    badPlatforms = stdenv.lib.optional (versionOlder version "1.59") "aarch64-linux";
+    platforms = platforms.unix ++ platforms.windows;
+    badPlatforms = stdenv.lib.optional (versionOlder version "1.59") "aarch64-linux"
+                 ++ stdenv.lib.optional ((versionOlder version "1.57") || version == "1.58") "x86_64-darwin";
     maintainers = with maintainers; [ peti ];
   };
 
diff --git a/pkgs/development/libraries/bullet/default.nix b/pkgs/development/libraries/bullet/default.nix
index fca5e8d70a3..585e2416b99 100644
--- a/pkgs/development/libraries/bullet/default.nix
+++ b/pkgs/development/libraries/bullet/default.nix
@@ -40,6 +40,8 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
+  NIX_CFLAGS_COMPILE = "-Wno-error=argument-outside-range";
+
   meta = with stdenv.lib; {
     description = "A professional free 3D Game Multiphysics Library";
     longDescription = ''
diff --git a/pkgs/development/libraries/clucene-core/2.x.nix b/pkgs/development/libraries/clucene-core/2.x.nix
index 6eb310550bc..03276ce9efd 100644
--- a/pkgs/development/libraries/clucene-core/2.x.nix
+++ b/pkgs/development/libraries/clucene-core/2.x.nix
@@ -36,6 +36,8 @@ stdenv.mkDerivation rec {
   # /build/clucene-core-2.3.3.4/build/bin/cl_test"
   doCheck = false;
 
+  NIX_CFLAGS_COMPILE = "-Wno-error=c++11-narrowing";
+
   meta = with stdenv.lib; {
     description = "Core library for full-featured text search engine";
     longDescription = ''
diff --git a/pkgs/development/libraries/libao/default.nix b/pkgs/development/libraries/libao/default.nix
index 826f72b1f5f..c1cf3215c16 100644
--- a/pkgs/development/libraries/libao/default.nix
+++ b/pkgs/development/libraries/libao/default.nix
@@ -1,5 +1,5 @@
 { stdenv, lib, fetchFromGitHub, autoreconfHook, pkgconfig, libpulseaudio, alsaLib, libcap
-, CoreAudio, CoreServices, AudioUnit
+, CoreAudio, CoreServices, AudioUnit, AudioToolbox
 , usePulseAudio }:
 
 stdenv.mkDerivation rec {
diff --git a/pkgs/development/libraries/libcdio/default.nix b/pkgs/development/libraries/libcdio/default.nix
index 5c50d093243..531ca4102af 100644
--- a/pkgs/development/libraries/libcdio/default.nix
+++ b/pkgs/development/libraries/libcdio/default.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation rec {
   buildInputs = [ libcddb ncurses help2man ]
     ++ stdenv.lib.optionals stdenv.isDarwin [ libiconv Carbon IOKit ];
 
-  doCheck = true;
+  doCheck = !stdenv.isDarwin;
 
   meta = with stdenv.lib; {
     description = "A library for OS-independent CD-ROM and CD image access";
diff --git a/pkgs/development/libraries/libdrm/default.nix b/pkgs/development/libraries/libdrm/default.nix
index a0bd7d86454..a8daf575416 100644
--- a/pkgs/development/libraries/libdrm/default.nix
+++ b/pkgs/development/libraries/libdrm/default.nix
@@ -14,17 +14,12 @@ stdenv.mkDerivation rec {
   buildInputs = [ libpthreadstubs libpciaccess valgrind-light ];
     # libdrm as of 2.4.70 does not actually do anything with udev.
 
-  patches = stdenv.lib.optional stdenv.isDarwin ./libdrm-apple.patch;
-
   postPatch = ''
     for a in */*-symbol-check ; do
       patchShebangs $a
     done
   '';
 
-  preConfigure = stdenv.lib.optionalString stdenv.isDarwin
-    "echo : \\\${ac_cv_func_clock_gettime=\'yes\'} > config.cache";
-
   configureFlags = [ "--enable-install-test-programs" ]
     ++ stdenv.lib.optionals (stdenv.isAarch32 || stdenv.isAarch64)
       [ "--enable-tegra-experimental-api" "--enable-etnaviv-experimental-api" ]
diff --git a/pkgs/development/libraries/libdrm/libdrm-apple.patch b/pkgs/development/libraries/libdrm/libdrm-apple.patch
deleted file mode 100644
index 17b447789c2..00000000000
--- a/pkgs/development/libraries/libdrm/libdrm-apple.patch
+++ /dev/null
@@ -1,88 +0,0 @@
-diff -Naur libdrm-2.4.26-orig/intel/intel_bufmgr_gem.c libdrm-2.4.26/intel/intel_bufmgr_gem.c
---- libdrm-2.4.26-orig/intel/intel_bufmgr_gem.c	2011-04-01 10:30:51.000000000 -0400
-+++ libdrm-2.4.26/intel/intel_bufmgr_gem.c	2011-08-29 02:17:20.000000000 -0400
-@@ -51,6 +51,7 @@
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <stdbool.h>
-+#include <sys/time.h>
- 
- #include "errno.h"
- #include "libdrm_lists.h"
-@@ -987,9 +988,9 @@
- 	if (atomic_dec_and_test(&bo_gem->refcount)) {
- 		drm_intel_bufmgr_gem *bufmgr_gem =
- 		    (drm_intel_bufmgr_gem *) bo->bufmgr;
--		struct timespec time;
-+		struct timeval time;
- 
--		clock_gettime(CLOCK_MONOTONIC, &time);
-+		gettimeofday(&time, NULL);
- 
- 		pthread_mutex_lock(&bufmgr_gem->lock);
- 		drm_intel_gem_bo_unreference_final(bo, time.tv_sec);
-diff -Naur libdrm-2.4.26-orig/xf86drm.c libdrm-2.4.26/xf86drm.c
---- libdrm-2.4.26-orig/xf86drm.c	2011-03-21 09:39:24.000000000 -0400
-+++ libdrm-2.4.26/xf86drm.c	2011-08-29 02:17:49.000000000 -0400
-@@ -51,6 +51,9 @@
- #include <sys/mman.h>
- #include <sys/time.h>
- #include <stdarg.h>
-+#if defined(__APPLE__) && defined(__MACH__)
-+#include <mach/mach_time.h>
-+#endif
- 
- /* Not all systems have MAP_FAILED defined */
- #ifndef MAP_FAILED
-@@ -1941,20 +1944,43 @@
-  */
- int drmWaitVBlank(int fd, drmVBlankPtr vbl)
- {
-+#if defined(__APPLE__) && defined(__MACH__)
-+    uint64_t start, end, elapsed, elapsedNano;
-+    static const uint64_t maxElapsed = 2000000000;
-+    static mach_timebase_info_data_t timebaseInfo;
-+    if ( timebaseInfo.denom == 0 ) {
-+	(void) mach_timebase_info(&timebaseInfo);
-+    }
-+#else
-     struct timespec timeout, cur;
-+#endif
-     int ret;
- 
-+#if defined(__APPLE__) && defined(__MACH__)
-+    start = mach_absolute_time();
-+#else
-     ret = clock_gettime(CLOCK_MONOTONIC, &timeout);
-     if (ret < 0) {
- 	fprintf(stderr, "clock_gettime failed: %s\n", strerror(ret));
- 	goto out;
-     }
-     timeout.tv_sec++;
-+#endif
- 
-     do {
-        ret = ioctl(fd, DRM_IOCTL_WAIT_VBLANK, vbl);
-        vbl->request.type &= ~DRM_VBLANK_RELATIVE;
-        if (ret && errno == EINTR) {
-+#if defined(__APPLE__) && defined(__MACH__)
-+	       end = mach_absolute_time();
-+	       elapsed = end - start;
-+	       elapsedNano = elapsed * timebaseInfo.numer / timebaseInfo.denom;
-+	       if (elapsedNano > maxElapsed) {
-+		   errno = EBUSY;
-+		   ret = -1;
-+		   break;
-+	       }
-+#else
- 	       clock_gettime(CLOCK_MONOTONIC, &cur);
- 	       /* Timeout after 1s */
- 	       if (cur.tv_sec > timeout.tv_sec + 1 ||
-@@ -1964,6 +1990,7 @@
- 		       ret = -1;
- 		       break;
- 	       }
-+#endif
-        }
-     } while (ret && errno == EINTR);
- 
diff --git a/pkgs/development/libraries/libproxy/default.nix b/pkgs/development/libraries/libproxy/default.nix
index 0e0499251eb..3b050c3dc6a 100644
--- a/pkgs/development/libraries/libproxy/default.nix
+++ b/pkgs/development/libraries/libproxy/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, pkgconfig, cmake, zlib
+{ stdenv, fetchFromGitHub, pkgconfig, cmake, zlib, fetchpatch
 , dbus, networkmanager, spidermonkey_38, pcre, python2, python3
 , SystemConfiguration, CoreFoundation, JavaScriptCore }:
 
@@ -30,6 +30,12 @@ stdenv.mkDerivation rec {
     )
   '';
 
+  patches = stdenv.lib.optional stdenv.isDarwin
+    (fetchpatch {
+      url = "https://github.com/libproxy/libproxy/commit/44158f03f8522116758d335688ed840dfcb50ac8.patch";
+      sha256 = "0axfvb6j7gcys6fkwi9dkn006imhvm3kqr83gpwban8419n0q5v1";
+    });
+
   doCheck = false; # fails 1 out of 10 tests
 
   meta = with stdenv.lib; {
diff --git a/pkgs/development/libraries/libsnark/darwin-fix-clock-gettime.patch b/pkgs/development/libraries/libsnark/darwin-fix-clock-gettime.patch
deleted file mode 100644
index 2eee84d1c4b..00000000000
--- a/pkgs/development/libraries/libsnark/darwin-fix-clock-gettime.patch
+++ /dev/null
@@ -1,41 +0,0 @@
-Adapted from https://github.com/zcash/libsnark/pull/10
-
-diff --git a/depends/libff/libff/common/profiling.cpp b/depends/libff/libff/common/profiling.cpp
-index f2a1985..319149c 100755
---- a/depends/libff/libff/common/profiling.cpp
-+++ b/depends/libff/libff/common/profiling.cpp
-@@ -27,6 +27,13 @@
- #include <proc/readproc.h>
- #endif
- 
-+#ifdef __MACH__
-+#include <time.h>
-+#include <sys/time.h>
-+#include <mach/clock.h>
-+#include <mach/mach.h>
-+#endif
-+
- namespace libff {
- 
- long long get_nsec_time()
-@@ -42,10 +49,20 @@ long long get_nsec_cpu_time()
- 	return 0;
- #else
-     ::timespec ts;
-+#ifdef __MACH__
-+    clock_serv_t cclock;
-+    mach_timespec_t mts;
-+    host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
-+    clock_get_time(cclock, &mts);
-+    mach_port_deallocate(mach_task_self(), cclock);
-+    ts.tv_sec = mts.tv_sec;
-+    ts.tv_nsec = mts.tv_nsec;
-+#else
-     if ( ::clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) )
-         throw ::std::runtime_error("clock_gettime(CLOCK_PROCESS_CPUTIME_ID) failed");
-         // If we expected this to work, don't silently ignore failures, because that would hide the problem and incur an unnecessarily system-call overhead. So if we ever observe this exception, we should probably add a suitable #ifdef .
-         //TODO: clock_gettime(CLOCK_PROCESS_CPUTIME_ID) is not supported by native Windows. What about Cygwin? Should we #ifdef on CLOCK_PROCESS_CPUTIME_ID or on __linux__?
-+#endif
-     return ts.tv_sec * 1000000000ll + ts.tv_nsec;
- #endif
- }
diff --git a/pkgs/development/libraries/libsnark/default.nix b/pkgs/development/libraries/libsnark/default.nix
index 4ea2209160f..15d8169f102 100644
--- a/pkgs/development/libraries/libsnark/default.nix
+++ b/pkgs/development/libraries/libsnark/default.nix
@@ -19,8 +19,6 @@ in stdenv.mkDerivation rec {
     fetchSubmodules = true;
   };
 
-  patches = [ ./darwin-fix-clock-gettime.patch ];
-
   enableParallelBuilding = true;
 
   meta = with stdenv.lib; {
diff --git a/pkgs/development/libraries/libtins/default.nix b/pkgs/development/libraries/libtins/default.nix
index 1af7548ac96..483fb56f43b 100644
--- a/pkgs/development/libraries/libtins/default.nix
+++ b/pkgs/development/libraries/libtins/default.nix
@@ -31,7 +31,11 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
   doCheck = true;
-  checkPhase = "make tests && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib make test";
+  preCheck = ''
+    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib
+    export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$PWD/lib
+  '';
+  checkTarget = "tests test";
 
   meta = with stdenv.lib; {
     description = "High-level, multiplatform C++ network packet sniffing and crafting library";
diff --git a/pkgs/development/libraries/mesa/darwin-clock-gettime.patch b/pkgs/development/libraries/mesa/darwin-clock-gettime.patch
deleted file mode 100644
index 94e90a1c587..00000000000
--- a/pkgs/development/libraries/mesa/darwin-clock-gettime.patch
+++ /dev/null
@@ -1,76 +0,0 @@
-diff --git a/include/c11/threads_posix.h b/include/c11/threads_posix.h
-index 45cb6075e6..62937311b9 100644
---- a/include/c11/threads_posix.h
-+++ b/include/c11/threads_posix.h
-@@ -36,6 +36,11 @@
- #include <sched.h>
- #include <stdint.h> /* for intptr_t */
- 
-+#ifdef __MACH__
-+#include <mach/clock.h>
-+#include <mach/mach.h>
-+#endif
-+
- /*
- Configuration macro:
- 
-@@ -383,12 +388,25 @@ tss_set(tss_t key, void *val)
- /*-------------------- 7.25.7 Time functions --------------------*/
- // 7.25.6.1
- #ifndef HAVE_TIMESPEC_GET
-+
- static inline int
- timespec_get(struct timespec *ts, int base)
- {
-     if (!ts) return 0;
-     if (base == TIME_UTC) {
-+#ifdef __MACH__
-+        if (ts != NULL) {
-+            clock_serv_t cclock;
-+            mach_timespec_t mts;
-+            host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
-+            clock_get_time(cclock, &mts);
-+            mach_port_deallocate(mach_task_self(), cclock);
-+            ts->tv_sec = mts.tv_sec;
-+            ts->tv_nsec = mts.tv_nsec;
-+        }
-+#else
-         clock_gettime(CLOCK_REALTIME, ts);
-+#endif
-         return base;
-     }
-     return 0;
-diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
-index 1208ebb315..e1378fb1f0 100644
---- a/src/egl/drivers/dri2/egl_dri2.c
-+++ b/src/egl/drivers/dri2/egl_dri2.c
-@@ -65,6 +65,11 @@
- #include "util/u_vector.h"
- #include "mapi/glapi/glapi.h"
- 
-+#ifdef __MACH__
-+#include <mach/clock.h>
-+#include <mach/mach.h>
-+#endif
-+
- #define NUM_ATTRIBS 12
- 
- static void
-@@ -3092,7 +3097,17 @@ dri2_client_wait_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
- 
-             /* We override the clock to monotonic when creating the condition
-              * variable. */
-+#ifdef __MACH__
-+            clock_serv_t cclock;
-+            mach_timespec_t mts;
-+            host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
-+            clock_get_time(cclock, &mts);
-+            mach_port_deallocate(mach_task_self(), cclock);
-+            current.tv_sec = mts.tv_sec;
-+            current.tv_nsec = mts.tv_nsec;
-+#else
-             clock_gettime(CLOCK_MONOTONIC, &current);
-+#endif
- 
-             /* calculating when to expire */
-             expire.tv_nsec = timeout % 1000000000L;
diff --git a/pkgs/development/libraries/mesa/default.nix b/pkgs/development/libraries/mesa/default.nix
index 5bc1dfaf878..c9ce97849e1 100644
--- a/pkgs/development/libraries/mesa/default.nix
+++ b/pkgs/development/libraries/mesa/default.nix
@@ -93,7 +93,7 @@ let self = stdenv.mkDerivation {
     ./symlink-drivers.patch
     ./missing-includes.patch # dev_t needs sys/stat.h, time_t needs time.h, etc.-- fixes build w/musl
     ./disk_cache-include-dri-driver-path-in-cache-key.patch
-  ] ++ lib.optional stdenv.isDarwin ./darwin-clock-gettime.patch;
+  ];
 
   outputs = [ "out" "dev" "drivers" ]
             ++ lib.optional (elem "swrast" galliumDrivers) "osmesa";
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 8715aaaa44d..de9a656f6ff 100644
--- a/pkgs/development/libraries/qt-4.x/4.8/default.nix
+++ b/pkgs/development/libraries/qt-4.x/4.8/default.nix
@@ -231,5 +231,6 @@ stdenv.mkDerivation rec {
     license     = lib.licenses.lgpl21Plus; # or gpl3
     maintainers = with lib.maintainers; [ orivej lovek323 phreedom sander ];
     platforms   = lib.platforms.unix;
+    badPlatforms = [ "x86_64-darwin" ];
   };
 }
diff --git a/pkgs/development/libraries/qt-5/5.11/default.nix b/pkgs/development/libraries/qt-5/5.11/default.nix
index 379c370e1fc..0014a1452aa 100644
--- a/pkgs/development/libraries/qt-5/5.11/default.nix
+++ b/pkgs/development/libraries/qt-5/5.11/default.nix
@@ -20,7 +20,7 @@ top-level attribute to `top-level/all-packages.nix`.
   stdenv, fetchurl, fetchFromGitHub, makeSetupHook,
   bison, cups ? null, harfbuzz, libGL, perl,
   gstreamer, gst-plugins-base, gtk3, dconf,
-  cf-private,
+  cf-private, llvmPackages_5,
 
   # options
   developerBuild ? false,
@@ -51,34 +51,24 @@ let
   patches = {
     qtbase = [
       ./qtbase.patch
-      ./qtbase-darwin.patch
-      ./qtbase-revert-no-macos10.10.patch
       ./qtbase-fixguicmake.patch
-    ] ++ optionals stdenv.isDarwin [
-      ./qtbase-darwin-nseventtype.patch
-      ./qtbase-darwin-revert-69221.patch
     ];
     qtdeclarative = [ ./qtdeclarative.patch ];
     qtscript = [ ./qtscript.patch ];
     qtserialport = [ ./qtserialport.patch ];
     qttools = [ ./qttools.patch ];
-    qtwebengine = [ ./qtwebengine-no-build-skip.patch ]
-      ++ optional stdenv.cc.isClang ./qtwebengine-clang-fix.patch
-      ++ optionals stdenv.isDarwin [
-        ./qtwebengine-darwin-no-platform-check.patch
-        ./qtwebengine-darwin-sdk-10.10.patch
-        ./qtwebengine-darwin-old-sdk.patch
-      ];
-    qtwebkit = [ ./qtwebkit.patch ]
-      ++ optionals stdenv.isDarwin [
-        ./qtwebkit-darwin-no-readline.patch
-        ./qtwebkit-darwin-no-qos-classes.patch
-      ];
+    qtwebengine = [
+      ./qtwebengine-no-build-skip.patch
+      ./qtwebengine-darwin-no-platform-check.patch
+    ];
+    qtwebkit = [ ./qtwebkit.patch ];
   };
 
   mkDerivation =
-    import ../mkDerivation.nix
-    { inherit stdenv; inherit (stdenv) lib; }
+    import ../mkDerivation.nix {
+      inherit (stdenv) lib;
+      stdenv = if stdenv.cc.isClang then llvmPackages_5.stdenv else stdenv;
+    }
     { inherit debug; };
 
   qtModule =
@@ -109,7 +99,7 @@ let
       qtdoc = callPackage ../modules/qtdoc.nix {};
       qtgraphicaleffects = callPackage ../modules/qtgraphicaleffects.nix {};
       qtimageformats = callPackage ../modules/qtimageformats.nix {};
-      qtlocation = callPackage ../modules/qtlocation.nix {};
+      qtlocation = callPackage ../modules/qtlocation.nix { };
       qtmacextras = callPackage ../modules/qtmacextras.nix {
         inherit cf-private;
       };
diff --git a/pkgs/development/libraries/qt-5/5.11/qtbase-darwin-nseventtype.patch b/pkgs/development/libraries/qt-5/5.11/qtbase-darwin-nseventtype.patch
deleted file mode 100644
index 9ef6e8ef069..00000000000
--- a/pkgs/development/libraries/qt-5/5.11/qtbase-darwin-nseventtype.patch
+++ /dev/null
@@ -1,13 +0,0 @@
---- a/src/plugins/platforms/cocoa/qcocoawindow.mm
-+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
-@@ -404,8 +404,8 @@ void QCocoaWindow::setVisible(bool visible)
-                         removeMonitor();
-                         monitor = [NSEvent addGlobalMonitorForEventsMatchingMask:NSLeftMouseDownMask|NSRightMouseDownMask|NSOtherMouseDownMask|NSMouseMovedMask handler:^(NSEvent *e) {
-                             QPointF localPoint = QCocoaScreen::mapFromNative([NSEvent mouseLocation]);
--                            const auto button = e.type == NSEventTypeMouseMoved ? Qt::NoButton : cocoaButton2QtButton([e buttonNumber]);
--                            const auto eventType = e.type == NSEventTypeMouseMoved ? QEvent::MouseMove : QEvent::MouseButtonPress;
-+                            const auto button = e.type == NSMouseMoved ? Qt::NoButton : cocoaButton2QtButton([e buttonNumber]);
-+                            const auto eventType = e.type == NSMouseMoved ? QEvent::MouseMove : QEvent::MouseButtonPress;
-                             QWindowSystemInterface::handleMouseEvent(window(), window()->mapFromGlobal(localPoint.toPoint()), localPoint,
-                                                                      Qt::MouseButtons(uint(NSEvent.pressedMouseButtons & 0xFFFF)), button, eventType);
-                         }];
diff --git a/pkgs/development/libraries/qt-5/5.11/qtbase-darwin-revert-69221.patch b/pkgs/development/libraries/qt-5/5.11/qtbase-darwin-revert-69221.patch
deleted file mode 100644
index 73eea435f84..00000000000
--- a/pkgs/development/libraries/qt-5/5.11/qtbase-darwin-revert-69221.patch
+++ /dev/null
@@ -1,73 +0,0 @@
-diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
-index 00c3f7c22c..94d35f59d6 100644
---- a/src/plugins/platforms/cocoa/qcocoawindow.mm
-+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
-@@ -1355,15 +1355,6 @@ QCocoaNSWindow *QCocoaWindow::createNSWindow(bool shouldBePanel)
- {
-     QMacAutoReleasePool pool;
- 
--    Qt::WindowType type = window()->type();
--    Qt::WindowFlags flags = window()->flags();
--
--    // Note: The macOS window manager has a bug, where if a screen is rotated, it will not allow
--    // a window to be created within the area of the screen that has a Y coordinate (I quadrant)
--    // higher than the height of the screen  in its non-rotated state, unless the window is
--    // created with the NSWindowStyleMaskBorderless style mask.
--    NSWindowStyleMask styleMask = windowStyleMask(flags);
--
-     QRect rect = geometry();
- 
-     QScreen *targetScreen = nullptr;
-@@ -1375,22 +1366,26 @@ QCocoaNSWindow *QCocoaWindow::createNSWindow(bool shouldBePanel)
-     }
- 
-     if (!targetScreen) {
--        qCWarning(lcQpaCocoaWindow) << "Window position" << rect << "outside any known screen, using primary screen";
-+        qCWarning(lcQpaCocoaWindow) << "Window position outside any known screen, using primary screen";
-         targetScreen = QGuiApplication::primaryScreen();
--        // AppKit will only reposition a window that's outside the target screen area if
--        // the window has a title bar. If left out, the window ends up with no screen.
--        // The style mask will be corrected to the original style mask in setWindowFlags.
--        styleMask |= NSWindowStyleMaskTitled;
-     }
- 
-     rect.translate(-targetScreen->geometry().topLeft());
-     QCocoaScreen *cocoaScreen = static_cast<QCocoaScreen *>(targetScreen->handle());
-     NSRect frame = QCocoaScreen::mapToNative(rect, cocoaScreen);
- 
-+    // Note: The macOS window manager has a bug, where if a screen is rotated, it will not allow
-+    // a window to be created within the area of the screen that has a Y coordinate (I quadrant)
-+    // higher than the height of the screen  in its non-rotated state, unless the window is
-+    // created with the NSWindowStyleMaskBorderless style mask.
-+
-+    Qt::WindowType type = window()->type();
-+    Qt::WindowFlags flags = window()->flags();
-+
-     // Create NSWindow
-     Class windowClass = shouldBePanel ? [QNSPanel class] : [QNSWindow class];
-     QCocoaNSWindow *nsWindow = [[windowClass alloc] initWithContentRect:frame
--        styleMask:styleMask
-+        styleMask:windowStyleMask(flags)
-         // Deferring window creation breaks OpenGL (the GL context is
-         // set up before the window is shown and needs a proper window)
-         backing:NSBackingStoreBuffered defer:NO
-@@ -1399,9 +1394,6 @@ QCocoaNSWindow *QCocoaWindow::createNSWindow(bool shouldBePanel)
-     Q_ASSERT_X(nsWindow.screen == cocoaScreen->nativeScreen(), "QCocoaWindow",
-         "Resulting NSScreen should match the requested NSScreen");
- 
--    if (targetScreen != window()->screen())
--        QWindowSystemInterface::handleWindowScreenChanged(window(), targetScreen);
--
-     nsWindow.delegate = [[QNSWindowDelegate alloc] initWithQCocoaWindow:this];
- 
-     // Prevent Cocoa from releasing the window on close. Qt
-@@ -1421,6 +1413,9 @@ QCocoaNSWindow *QCocoaWindow::createNSWindow(bool shouldBePanel)
-         });
-     }
- 
-+    if (targetScreen != window()->screen())
-+        QWindowSystemInterface::handleWindowScreenChanged(window(), targetScreen);
-+
-     nsWindow.restorable = NO;
-     nsWindow.level = windowLevel(flags);
- 
diff --git a/pkgs/development/libraries/qt-5/5.11/qtbase-darwin.patch b/pkgs/development/libraries/qt-5/5.11/qtbase-darwin.patch
deleted file mode 100644
index f6635175205..00000000000
--- a/pkgs/development/libraries/qt-5/5.11/qtbase-darwin.patch
+++ /dev/null
@@ -1,70 +0,0 @@
-diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm
-index 341d3bccf2..3368234c26 100644
---- a/src/plugins/bearer/corewlan/qcorewlanengine.mm
-+++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm
-@@ -287,7 +287,7 @@ void QScanThread::getUserConfigurations()
-     QMacAutoReleasePool pool;
-     userProfiles.clear();
- 
--    NSArray<NSString *> *wifiInterfaces = [CWWiFiClient interfaceNames];
-+    NSArray *wifiInterfaces = [CWWiFiClient interfaceNames];
-     for (NSString *ifName in wifiInterfaces) {
- 
-         CWInterface *wifiInterface = [[CWWiFiClient sharedWiFiClient] interfaceWithName:ifName];
-@@ -602,7 +602,7 @@ void QCoreWlanEngine::doRequestUpdate()
- 
-     QMacAutoReleasePool pool;
- 
--    NSArray<NSString *> *wifiInterfaces = [CWWiFiClient interfaceNames];
-+    NSArray *wifiInterfaces = [CWWiFiClient interfaceNames];
-     for (NSString *ifName in wifiInterfaces) {
-             scanThread->interfaceName = QString::fromNSString(ifName);
-             scanThread->start();
-diff --git a/src/plugins/platforms/cocoa/qcocoascreen.mm b/src/plugins/platforms/cocoa/qcocoascreen.mm
-index a17a02b629..d76c42fa03 100644
---- a/src/plugins/platforms/cocoa/qcocoascreen.mm
-+++ b/src/plugins/platforms/cocoa/qcocoascreen.mm
-@@ -114,7 +114,7 @@ void QCocoaScreen::updateGeometry()
-         return;
-
-     // The reference screen for the geometry is always the primary screen
--    QRectF primaryScreenGeometry = QRectF::fromCGRect([[NSScreen screens] firstObject].frame);
-+    QRectF primaryScreenGeometry = QRectF::fromCGRect([[[NSScreen screens] firstObject] frame]);
-     m_geometry = qt_mac_flip(QRectF::fromCGRect(nsScreen.frame), primaryScreenGeometry).toRect();
-     m_availableGeometry = qt_mac_flip(QRectF::fromCGRect(nsScreen.visibleFrame), primaryScreenGeometry).toRect();
-
-diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
-index 72f3bc0075..a9c058a850 100644
---- a/src/plugins/platforms/cocoa/qcocoawindow.mm
-+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
-@@ -1676,7 +1676,7 @@ void QCocoaWindow::applyContentBorderThickness(NSWindow *window)
- 
-     if (!m_drawContentBorderGradient) {
-         window.styleMask = window.styleMask & ~NSTexturedBackgroundWindowMask;
--        [window.contentView.superview setNeedsDisplay:YES];
-+        [[window.contentView superview] setNeedsDisplay:YES];
-         window.titlebarAppearsTransparent = NO;
-         return;
-     }
-diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm
-index cb13b7d184..0159d68dca 100644
---- a/src/plugins/platforms/cocoa/qnswindow.mm
-+++ b/src/plugins/platforms/cocoa/qnswindow.mm
-@@ -231,7 +231,7 @@ static bool isMouseEvent(NSEvent *ev)
-     if (pw->frameStrutEventsEnabled() && isMouseEvent(theEvent)) {
-         NSPoint loc = [theEvent locationInWindow];
-         NSRect windowFrame = [self convertRectFromScreen:self.frame];
--        NSRect contentFrame = self.contentView.frame;
-+        NSRect contentFrame = [self.contentView frame];
-         if (NSMouseInRect(loc, windowFrame, NO) && !NSMouseInRect(loc, contentFrame, NO))
-             [qnsview_cast(pw->view()) handleFrameStrutMouseEvent:theEvent];
-     }
-@@ -260,7 +260,7 @@ static bool isMouseEvent(NSEvent *ev)
- + (void)applicationActivationChanged:(NSNotification*)notification
- {
-     const id sender = self;
--    NSEnumerator<NSWindow*> *windowEnumerator = nullptr;
-+    NSEnumerator *windowEnumerator = nullptr;
-     NSApplication *application = [NSApplication sharedApplication];
- 
- #if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_12)
diff --git a/pkgs/development/libraries/qt-5/5.11/qtbase-revert-no-macos10.10.patch b/pkgs/development/libraries/qt-5/5.11/qtbase-revert-no-macos10.10.patch
deleted file mode 100644
index 29776518379..00000000000
--- a/pkgs/development/libraries/qt-5/5.11/qtbase-revert-no-macos10.10.patch
+++ /dev/null
@@ -1,102 +0,0 @@
-Revert "Remove code paths for macOS < 10.11"
-
-This reverts commit 138a65e0cfa80b13fd018a01e7d8b33341a3cfd3.
-
-From 138a65e0cfa80b13fd018a01e7d8b33341a3cfd3 Mon Sep 17 00:00:00 2001
-From: Jake Petroules <jake.petroules@qt.io>
-Date: Thu, 8 Feb 2018 11:05:42 -0800
-Subject: [PATCH] Remove code paths for macOS < 10.11
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-Change-Id: I5ae02d88aa3dcd97d1f2ebf6255a68643e5d6daa
-Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
-Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
----
- .../fontdatabases/mac/qfontengine_coretext.mm            | 16 +++-------------
- src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm    |  6 +-----
- src/plugins/platforms/cocoa/qnswindowdelegate.mm         | 16 ----------------
- 3 files changed, 4 insertions(+), 34 deletions(-)
-
-diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
-index 98b753eff9..489d9cd031 100644
---- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
-+++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
-@@ -47,18 +47,28 @@
- 
- #include <cmath>
- 
--#if defined(Q_OS_MACOS)
-+#if defined(Q_OS_OSX) && !QT_OSX_DEPLOYMENT_TARGET_BELOW(__MAC_10_11)
- #import <AppKit/AppKit.h>
- #endif
- 
--#if defined(QT_PLATFORM_UIKIT)
-+#if defined(QT_PLATFORM_UIKIT) && !QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_8_2)
- #import <UIKit/UIKit.h>
- #endif
- 
- // These are available cross platform, exported as kCTFontWeightXXX from CoreText.framework,
- // but they are not documented and are not in public headers so are private API and exposed
- // only through the NSFontWeightXXX and UIFontWeightXXX aliases in AppKit and UIKit (rdar://26109857)
--#if defined(Q_OS_MACOS)
-+#if QT_MAC_DEPLOYMENT_TARGET_BELOW(__MAC_10_11, __IPHONE_8_2)
-+#define kCTFontWeightUltraLight -0.8
-+#define kCTFontWeightThin -0.6
-+#define kCTFontWeightLight -0.4
-+#define kCTFontWeightRegular 0
-+#define kCTFontWeightMedium 0.23
-+#define kCTFontWeightSemibold 0.3
-+#define kCTFontWeightBold 0.4
-+#define kCTFontWeightHeavy 0.56
-+#define kCTFontWeightBlack 0.62
-+#elif defined(Q_OS_OSX)
- #define kCTFontWeightUltraLight NSFontWeightUltraLight
- #define kCTFontWeightThin NSFontWeightThin
- #define kCTFontWeightLight NSFontWeightLight
-diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
-index 94f2125bad..272cd9f3dc 100644
---- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
-+++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
-@@ -162,7 +162,11 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSOpenSavePanelDelegate);
-     // resetting our mCurrentDir, set the delegate
-     // here to make sure it gets the correct value.
-     [mSavePanel setDelegate:self];
--    mOpenPanel.accessoryViewDisclosed = YES;
-+
-+#if QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_11)
-+    if (__builtin_available(macOS 10.11, *))
-+        mOpenPanel.accessoryViewDisclosed = YES;
-+#endif
- 
-     if (mOptions->isLabelExplicitlySet(QFileDialogOptions::Accept))
-         [mSavePanel setPrompt:[self strip:options->labelText(QFileDialogOptions::Accept)]];
-diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.mm b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
-index 057a4c2943..eb55e50622 100644
---- a/src/plugins/platforms/cocoa/qnswindowdelegate.mm
-+++ b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
-@@ -103,6 +103,22 @@ static QRegExp whitespaceRegex = QRegExp(QStringLiteral("\\s*"));
-     return QCocoaScreen::mapToNative(maximizedFrame);
- }
- 
-+#if QT_MACOS_DEPLOYMENT_TARGET_BELOW(__MAC_10_11)
-+/*
-+    AppKit on OS X 10.10 wrongly calls windowWillUseStandardFrame:defaultFrame
-+    from -[NSWindow _frameForFullScreenMode] when going into fullscreen, resulting
-+    in black bars on top and bottom of the window. By implementing the following
-+    method, AppKit will choose that instead, and resolve the right fullscreen
-+    geometry.
-+*/
-+- (NSSize)window:(NSWindow *)window willUseFullScreenContentSize:(NSSize)proposedSize
-+{
-+    Q_UNUSED(proposedSize);
-+    Q_ASSERT(window == m_cocoaWindow->nativeWindow());
-+    return NSSizeFromCGSize(m_cocoaWindow->screen()->geometry().size().toCGSize());
-+}
-+#endif
-+
- - (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu
- {
-     Q_UNUSED(window);
diff --git a/pkgs/development/libraries/qt-5/5.11/qtwebengine-clang-fix.patch b/pkgs/development/libraries/qt-5/5.11/qtwebengine-clang-fix.patch
deleted file mode 100644
index 8dafd65cd34..00000000000
--- a/pkgs/development/libraries/qt-5/5.11/qtwebengine-clang-fix.patch
+++ /dev/null
@@ -1,30 +0,0 @@
-Fix a following build error:
-
-In file included from ../../3rdparty/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm:7:
-../../3rdparty/chromium/base/bind.h:59:3: error: static_assert failed "Bound argument |i| of type |Arg| cannot be forwarded as |Unwrapped| to the bound functor, which declares it as |Param|."
-  static_assert(
-  ^
-../../3rdparty/chromium/base/bind.h:91:7: note: in instantiation of template class 'base::internal::AssertConstructible<1, long, long, const long &, NSError *>' requested here
-    : AssertConstructible<Ns, Args, std::decay_t<Args>, Unwrapped, Params>... {
-      ^
-../../3rdparty/chromium/base/bind.h:213:27: note: in instantiation of template class 'base::internal::AssertBindArgsValidity<std::__1::integer_sequence<unsigned long, 0, 1>, base::internal::TypeList<base::WeakPtr<device::BluetoothRemoteGattCharacteristicMac>, long>, base::internal::TypeList<device::BluetoothRemoteGattCharacteristicMac *, const long &>, base::internal::TypeList<device::BluetoothRemoteGattCharacteristicMac *, NSError *> >' requested here
-  static_assert(internal::AssertBindArgsValidity<
-                          ^
-../../3rdparty/chromium/base/bind.h:242:16: note: in instantiation of function template specialization 'base::BindRepeating<void (device::BluetoothRemoteGattCharacteristicMac::*)(NSError *), base::WeakPtr<device::BluetoothRemoteGattCharacteristicMac>, long>' requested here
-  return base::BindRepeating(std::forward<Functor>(functor),
-               ^
-../../3rdparty/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm:211:15: note: in instantiation of function template specialization 'base::Bind<void (device::BluetoothRemoteGattCharacteristicMac::*)(NSError *), base::WeakPtr<device::BluetoothRemoteGattCharacteristicMac>, long>' requested here
-        base::Bind(&BluetoothRemoteGattCharacteristicMac::DidWriteValue,
-              ^
-
---- a/src/3rdparty/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm
-+++ b/src/3rdparty/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm
-@@ -209,7 +209,7 @@ void BluetoothRemoteGattCharacteristicMac::WriteRemoteCharacteristic(
-     base::ThreadTaskRunnerHandle::Get()->PostTask(
-         FROM_HERE,
-         base::Bind(&BluetoothRemoteGattCharacteristicMac::DidWriteValue,
--                   weak_ptr_factory_.GetWeakPtr(), nil));
-+                   weak_ptr_factory_.GetWeakPtr(), nullptr));
-   }
- }
- 
diff --git a/pkgs/development/libraries/qt-5/5.11/qtwebengine-darwin-old-sdk.patch b/pkgs/development/libraries/qt-5/5.11/qtwebengine-darwin-old-sdk.patch
deleted file mode 100644
index b065c221101..00000000000
--- a/pkgs/development/libraries/qt-5/5.11/qtwebengine-darwin-old-sdk.patch
+++ /dev/null
@@ -1,21 +0,0 @@
-diff --git a/src/3rdparty/chromium/third_party/webrtc/sdk/objc/Framework/Classes/Common/RTCFieldTrials.mm b/src/3rdparty/chromium/third_party/webrtc/sdk/objc/Framework/Classes/Common/RTCFieldTrials.mm
---- a/src/3rdparty/chromium/third_party/webrtc/sdk/objc/Framework/Classes/Common/RTCFieldTrials.mm
-+++ b/src/3rdparty/chromium/third_party/webrtc/sdk/objc/Framework/Classes/Common/RTCFieldTrials.mm
-@@ -45,7 +45,7 @@ NSString *RTCFieldTrialTrendlineFilterValue(
-   return [NSString stringWithFormat:format, windowSize, smoothingCoeff, thresholdGain];
- }
- 
--void RTCInitFieldTrialDictionary(NSDictionary<NSString *, NSString *> *fieldTrials) {
-+void RTCInitFieldTrialDictionary(NSDictionary *fieldTrials) {
-   if (!fieldTrials) {
-     RTCLogWarning(@"No fieldTrials provided.");
-     return;
-diff --git a/src/3rdparty/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFieldTrials.h b/src/3rdparty/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFieldTrials.h
---- a/src/3rdparty/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFieldTrials.h
-+++ b/src/3rdparty/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFieldTrials.h
-@@ -40,4 +40,4 @@ RTC_EXTERN NSString *RTCFieldTrialTrendlineFilterValue(
-  *  Must be called before any other call into WebRTC. See:
-  *  webrtc/system_wrappers/include/field_trial_default.h
-  */
--RTC_EXTERN void RTCInitFieldTrialDictionary(NSDictionary<NSString *, NSString *> *fieldTrials);
-+RTC_EXTERN void RTCInitFieldTrialDictionary(NSDictionary *fieldTrials);
diff --git a/pkgs/development/libraries/qt-5/5.11/qtwebengine-darwin-sdk-10.10.patch b/pkgs/development/libraries/qt-5/5.11/qtwebengine-darwin-sdk-10.10.patch
deleted file mode 100644
index d43b09b9538..00000000000
--- a/pkgs/development/libraries/qt-5/5.11/qtwebengine-darwin-sdk-10.10.patch
+++ /dev/null
@@ -1,160 +0,0 @@
-Fix build against 10.10 SDK
-
-The SecKey part perhaps could be fixed by implementing a revert to
-https://chromium.googlesource.com/chromium/src.git/+/8418e098b9cbedf884878b61dcd3292c515845cf%5E%21/#F0
-
---- a/src/3rdparty/chromium/content/browser/renderer_host/input/web_input_event_builders_mac.mm
-+++ b/src/3rdparty/chromium/content/browser/renderer_host/input/web_input_event_builders_mac.mm
-@@ -1,3 +1,4 @@
-+#define NSEventTypeScrollWheel 22
- // Copyright 2015 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
---- a/src/3rdparty/chromium/net/ssl/ssl_platform_key_mac.cc
-+++ b/src/3rdparty/chromium/net/ssl/ssl_platform_key_mac.cc
-@@ -48,21 +48,6 @@ namespace net {
- 
- namespace {
- 
--// TODO(davidben): Remove this when we switch to building to the 10.13
--// SDK. https://crbug.com/780980
--#if !defined(MAC_OS_X_VERSION_10_13) || \
--    MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_13
--API_AVAILABLE(macosx(10.13))
--const SecKeyAlgorithm kSecKeyAlgorithmRSASignatureDigestPSSSHA256 =
--    CFSTR("algid:sign:RSA:digest-PSS:SHA256:SHA256:32");
--API_AVAILABLE(macosx(10.13))
--const SecKeyAlgorithm kSecKeyAlgorithmRSASignatureDigestPSSSHA384 =
--    CFSTR("algid:sign:RSA:digest-PSS:SHA384:SHA384:48");
--API_AVAILABLE(macosx(10.13))
--const SecKeyAlgorithm kSecKeyAlgorithmRSASignatureDigestPSSSHA512 =
--    CFSTR("algid:sign:RSA:digest-PSS:SHA512:SHA512:64");
--#endif
--
- class ScopedCSSM_CC_HANDLE {
-  public:
-   ScopedCSSM_CC_HANDLE() : handle_(0) {}
-@@ -187,109 +172,6 @@ class SSLPlatformKeyCSSM : public ThreadedSSLPrivateKey::Delegate {
-   DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyCSSM);
- };
- 
--// Returns the corresponding SecKeyAlgorithm or nullptr if unrecognized.
--API_AVAILABLE(macosx(10.12))
--SecKeyAlgorithm GetSecKeyAlgorithm(uint16_t algorithm) {
--  switch (algorithm) {
--    case SSL_SIGN_RSA_PKCS1_SHA512:
--      return kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA512;
--    case SSL_SIGN_RSA_PKCS1_SHA384:
--      return kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA384;
--    case SSL_SIGN_RSA_PKCS1_SHA256:
--      return kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA256;
--    case SSL_SIGN_RSA_PKCS1_SHA1:
--      return kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA1;
--    case SSL_SIGN_RSA_PKCS1_MD5_SHA1:
--      return kSecKeyAlgorithmRSASignatureDigestPKCS1v15Raw;
--    case SSL_SIGN_ECDSA_SECP521R1_SHA512:
--      return kSecKeyAlgorithmECDSASignatureDigestX962SHA512;
--    case SSL_SIGN_ECDSA_SECP384R1_SHA384:
--      return kSecKeyAlgorithmECDSASignatureDigestX962SHA384;
--    case SSL_SIGN_ECDSA_SECP256R1_SHA256:
--      return kSecKeyAlgorithmECDSASignatureDigestX962SHA256;
--    case SSL_SIGN_ECDSA_SHA1:
--      return kSecKeyAlgorithmECDSASignatureDigestX962SHA1;
--  }
--
--  if (base::mac::IsAtLeastOS10_13()) {
--    switch (algorithm) {
--      case SSL_SIGN_RSA_PSS_SHA512:
--        return kSecKeyAlgorithmRSASignatureDigestPSSSHA512;
--      case SSL_SIGN_RSA_PSS_SHA384:
--        return kSecKeyAlgorithmRSASignatureDigestPSSSHA384;
--      case SSL_SIGN_RSA_PSS_SHA256:
--        return kSecKeyAlgorithmRSASignatureDigestPSSSHA256;
--    }
--  }
--
--  return nullptr;
--}
--
--class API_AVAILABLE(macosx(10.12)) SSLPlatformKeySecKey
--    : public ThreadedSSLPrivateKey::Delegate {
-- public:
--  SSLPlatformKeySecKey(int type, size_t max_length, SecKeyRef key)
--      : key_(key, base::scoped_policy::RETAIN) {
--    // Determine the algorithms supported by the key.
--    for (uint16_t algorithm : SSLPrivateKey::DefaultAlgorithmPreferences(
--             type, true /* include PSS */)) {
--      SecKeyAlgorithm sec_algorithm = GetSecKeyAlgorithm(algorithm);
--      if (sec_algorithm &&
--          SecKeyIsAlgorithmSupported(key_.get(), kSecKeyOperationTypeSign,
--                                     sec_algorithm)) {
--        preferences_.push_back(algorithm);
--      }
--    }
--  }
--
--  ~SSLPlatformKeySecKey() override {}
--
--  std::vector<uint16_t> GetAlgorithmPreferences() override {
--    return preferences_;
--  }
--
--  Error Sign(uint16_t algorithm,
--             base::span<const uint8_t> input,
--             std::vector<uint8_t>* signature) override {
--    SecKeyAlgorithm sec_algorithm = GetSecKeyAlgorithm(algorithm);
--    if (!sec_algorithm) {
--      NOTREACHED();
--      return ERR_FAILED;
--    }
--
--    const EVP_MD* md = SSL_get_signature_algorithm_digest(algorithm);
--    uint8_t digest[EVP_MAX_MD_SIZE];
--    unsigned digest_len;
--    if (!md || !EVP_Digest(input.data(), input.size(), digest, &digest_len, md,
--                           nullptr)) {
--      return ERR_SSL_CLIENT_AUTH_SIGNATURE_FAILED;
--    }
--
--    base::ScopedCFTypeRef<CFDataRef> digest_ref(CFDataCreateWithBytesNoCopy(
--        kCFAllocatorDefault, digest, base::checked_cast<CFIndex>(digest_len),
--        kCFAllocatorNull));
--
--    base::ScopedCFTypeRef<CFErrorRef> error;
--    base::ScopedCFTypeRef<CFDataRef> signature_ref(SecKeyCreateSignature(
--        key_, sec_algorithm, digest_ref, error.InitializeInto()));
--    if (!signature_ref) {
--      LOG(ERROR) << error;
--      return ERR_SSL_CLIENT_AUTH_SIGNATURE_FAILED;
--    }
--
--    signature->assign(
--        CFDataGetBytePtr(signature_ref),
--        CFDataGetBytePtr(signature_ref) + CFDataGetLength(signature_ref));
--    return OK;
--  }
--
-- private:
--  std::vector<uint16_t> preferences_;
--  base::ScopedCFTypeRef<SecKeyRef> key_;
--
--  DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeySecKey);
--};
--
- scoped_refptr<SSLPrivateKey> CreateSSLPrivateKeyForSecKey(
-     const X509Certificate* certificate,
-     SecKeyRef private_key) {
-@@ -298,13 +180,6 @@ scoped_refptr<SSLPrivateKey> CreateSSLPrivateKeyForSecKey(
-   if (!GetClientCertInfo(certificate, &key_type, &max_length))
-     return nullptr;
- 
--  if (base::mac::IsAtLeastOS10_12()) {
--    return base::MakeRefCounted<ThreadedSSLPrivateKey>(
--        std::make_unique<SSLPlatformKeySecKey>(key_type, max_length,
--                                               private_key),
--        GetSSLPlatformKeyTaskRunner());
--  }
--
-   const CSSM_KEY* cssm_key;
-   OSStatus status = SecKeyGetCSSMKey(private_key, &cssm_key);
-   if (status != noErr) {
diff --git a/pkgs/development/libraries/qt-5/5.11/qtwebkit-darwin-no-qos-classes.patch b/pkgs/development/libraries/qt-5/5.11/qtwebkit-darwin-no-qos-classes.patch
deleted file mode 100644
index a7087f51762..00000000000
--- a/pkgs/development/libraries/qt-5/5.11/qtwebkit-darwin-no-qos-classes.patch
+++ /dev/null
@@ -1,11 +0,0 @@
-diff --git a/Source/cmake/OptionsQt.cmake b/Source/cmake/OptionsQt.cmake
---- a/Source/cmake/OptionsQt.cmake
-+++ b/Source/cmake/OptionsQt.cmake
-@@ -683,7 +683,6 @@ if (WIN32 AND COMPILER_IS_GCC_OR_CLANG)
- endif ()
- 
- if (APPLE)
--    SET_AND_EXPOSE_TO_BUILD(HAVE_QOS_CLASSES 1)
- endif ()
- 
- if (ENABLE_MATHML)
diff --git a/pkgs/development/libraries/qt-5/5.11/qtwebkit-darwin-no-readline.patch b/pkgs/development/libraries/qt-5/5.11/qtwebkit-darwin-no-readline.patch
deleted file mode 100644
index 26d189d8601..00000000000
--- a/pkgs/development/libraries/qt-5/5.11/qtwebkit-darwin-no-readline.patch
+++ /dev/null
@@ -1,45 +0,0 @@
-diff --git a/Source/JavaScriptCore/shell/CMakeLists.txt b/Source/JavaScriptCore/shell/CMakeLists.txt
---- a/Source/JavaScriptCore/shell/CMakeLists.txt
-+++ b/Source/JavaScriptCore/shell/CMakeLists.txt
-@@ -9,7 +9,6 @@ set(JSC_LIBRARIES
- )
- 
- if (WTF_OS_MAC_OS_X)
--    list(APPEND JSC_LIBRARIES edit)
- endif ()
- 
- if ("${JavaScriptCore_LIBRARY_TYPE}" MATCHES "STATIC")
-diff --git a/Source/WTF/wtf/Platform.h b/Source/WTF/wtf/Platform.h
---- a/Source/WTF/wtf/Platform.h
-+++ b/Source/WTF/wtf/Platform.h
-@@ -563,7 +563,6 @@
- #if PLATFORM(IOS)
- 
- #define HAVE_NETWORK_EXTENSION 1
--#define HAVE_READLINE 1
- #if USE(APPLE_INTERNAL_SDK)
- #define USE_CFNETWORK 1
- #endif
-@@ -650,7 +649,6 @@
- #define HAVE_MADV_DONTNEED 1
- #define HAVE_MERGESORT 1
- #define HAVE_PTHREAD_SETNAME_NP 1
--#define HAVE_READLINE 1
- #define HAVE_SYS_TIMEB_H 1
- 
- #if !PLATFORM(GTK) && !PLATFORM(QT)
-diff --git a/Source/WTF/wtf/PlatformMac.cmake b/Source/WTF/wtf/PlatformMac.cmake
---- a/Source/WTF/wtf/PlatformMac.cmake
-+++ b/Source/WTF/wtf/PlatformMac.cmake
-@@ -2,11 +2,9 @@ set(WTF_LIBRARY_TYPE SHARED)
- 
- find_library(COCOA_LIBRARY Cocoa)
- find_library(COREFOUNDATION_LIBRARY CoreFoundation)
--find_library(READLINE_LIBRARY Readline)
- list(APPEND WTF_LIBRARIES
-     ${COREFOUNDATION_LIBRARY}
-     ${COCOA_LIBRARY}
--    ${READLINE_LIBRARY}
-     libicucore.dylib
- )
- 
diff --git a/pkgs/development/libraries/qt-5/5.12/default.nix b/pkgs/development/libraries/qt-5/5.12/default.nix
index 6d0e241d7a5..d84596bd054 100644
--- a/pkgs/development/libraries/qt-5/5.12/default.nix
+++ b/pkgs/development/libraries/qt-5/5.12/default.nix
@@ -20,7 +20,7 @@ top-level attribute to `top-level/all-packages.nix`.
   stdenv, fetchurl, fetchFromGitHub, makeSetupHook,
   bison, cups ? null, harfbuzz, libGL, perl,
   gstreamer, gst-plugins-base, gtk3, dconf,
-  cf-private,
+  cf-private, llvmPackages_5,
 
   # options
   developerBuild ? false,
@@ -51,11 +51,7 @@ let
   patches = {
     qtbase = [
       ./qtbase.patch
-      ./qtbase-darwin.patch
-      ./qtbase-revert-no-macos10.10.patch
       ./qtbase-fixguicmake.patch
-    ] ++ optionals stdenv.isDarwin [
-      ./qtbase-darwin-nseventtype.patch
     ];
     qtdeclarative = [ ./qtdeclarative.patch ];
     qtscript = [ ./qtscript.patch ];
@@ -73,8 +69,10 @@ let
   };
 
   mkDerivation =
-    import ../mkDerivation.nix
-    { inherit stdenv; inherit (stdenv) lib; }
+    import ../mkDerivation.nix {
+      inherit (stdenv) lib;
+      stdenv = if stdenv.cc.isClang then llvmPackages_5.stdenv else stdenv;
+    }
     { inherit debug; };
 
   qtModule =
diff --git a/pkgs/development/libraries/qt-5/5.12/qtbase-darwin-nseventtype.patch b/pkgs/development/libraries/qt-5/5.12/qtbase-darwin-nseventtype.patch
deleted file mode 100644
index 9ef6e8ef069..00000000000
--- a/pkgs/development/libraries/qt-5/5.12/qtbase-darwin-nseventtype.patch
+++ /dev/null
@@ -1,13 +0,0 @@
---- a/src/plugins/platforms/cocoa/qcocoawindow.mm
-+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
-@@ -404,8 +404,8 @@ void QCocoaWindow::setVisible(bool visible)
-                         removeMonitor();
-                         monitor = [NSEvent addGlobalMonitorForEventsMatchingMask:NSLeftMouseDownMask|NSRightMouseDownMask|NSOtherMouseDownMask|NSMouseMovedMask handler:^(NSEvent *e) {
-                             QPointF localPoint = QCocoaScreen::mapFromNative([NSEvent mouseLocation]);
--                            const auto button = e.type == NSEventTypeMouseMoved ? Qt::NoButton : cocoaButton2QtButton([e buttonNumber]);
--                            const auto eventType = e.type == NSEventTypeMouseMoved ? QEvent::MouseMove : QEvent::MouseButtonPress;
-+                            const auto button = e.type == NSMouseMoved ? Qt::NoButton : cocoaButton2QtButton([e buttonNumber]);
-+                            const auto eventType = e.type == NSMouseMoved ? QEvent::MouseMove : QEvent::MouseButtonPress;
-                             QWindowSystemInterface::handleMouseEvent(window(), window()->mapFromGlobal(localPoint.toPoint()), localPoint,
-                                                                      Qt::MouseButtons(uint(NSEvent.pressedMouseButtons & 0xFFFF)), button, eventType);
-                         }];
diff --git a/pkgs/development/libraries/qt-5/5.12/qtbase-darwin.patch b/pkgs/development/libraries/qt-5/5.12/qtbase-darwin.patch
deleted file mode 100644
index 7ce27a99758..00000000000
--- a/pkgs/development/libraries/qt-5/5.12/qtbase-darwin.patch
+++ /dev/null
@@ -1,70 +0,0 @@
-diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm
-index c3dd49ff3e..6871399817 100644
---- a/src/plugins/bearer/corewlan/qcorewlanengine.mm
-+++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm
-@@ -283,7 +283,7 @@ void QScanThread::getUserConfigurations()
-     QMacAutoReleasePool pool;
-     userProfiles.clear();
- 
--    NSArray<NSString *> *wifiInterfaces = [CWWiFiClient interfaceNames];
-+    NSArray *wifiInterfaces = [CWWiFiClient interfaceNames];
-     for (NSString *ifName in wifiInterfaces) {
- 
-         CWInterface *wifiInterface = [[CWWiFiClient sharedWiFiClient] interfaceWithName:ifName];
-@@ -598,7 +598,7 @@ void QCoreWlanEngine::doRequestUpdate()
- 
-     QMacAutoReleasePool pool;
- 
--    NSArray<NSString *> *wifiInterfaces = [CWWiFiClient interfaceNames];
-+    NSArray *wifiInterfaces = [CWWiFiClient interfaceNames];
-     for (NSString *ifName in wifiInterfaces) {
-             scanThread->interfaceName = QString::fromNSString(ifName);
-             scanThread->start();
-diff --git a/src/plugins/platforms/cocoa/qcocoascreen.mm b/src/plugins/platforms/cocoa/qcocoascreen.mm
-index afe14e623c..74d69c2fa1 100644
---- a/src/plugins/platforms/cocoa/qcocoascreen.mm
-+++ b/src/plugins/platforms/cocoa/qcocoascreen.mm
-@@ -127,7 +127,7 @@ void QCocoaScreen::updateProperties()
-     const qreal previousRefreshRate = m_refreshRate;
- 
-     // The reference screen for the geometry is always the primary screen
--    QRectF primaryScreenGeometry = QRectF::fromCGRect([[NSScreen screens] firstObject].frame);
-+    QRectF primaryScreenGeometry = QRectF::fromCGRect([[[NSScreen screens] firstObject] frame]);
-     m_geometry = qt_mac_flip(QRectF::fromCGRect(nsScreen.frame), primaryScreenGeometry).toRect();
-     m_availableGeometry = qt_mac_flip(QRectF::fromCGRect(nsScreen.visibleFrame), primaryScreenGeometry).toRect();
- 
-diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
-index df1ad82592..0318a4ff96 100644
---- a/src/plugins/platforms/cocoa/qcocoawindow.mm
-+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
-@@ -1704,7 +1704,7 @@ void QCocoaWindow::applyContentBorderThickness(NSWindow *window)
- 
-     if (!m_drawContentBorderGradient) {
-         window.styleMask = window.styleMask & ~NSWindowStyleMaskTexturedBackground;
--        [window.contentView.superview setNeedsDisplay:YES];
-+        [[window.contentView superview] setNeedsDisplay:YES];
-         window.titlebarAppearsTransparent = NO;
-         return;
-     }
-diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm
-index c17ad47aba..a0f1dd38fb 100644
---- a/src/plugins/platforms/cocoa/qnswindow.mm
-+++ b/src/plugins/platforms/cocoa/qnswindow.mm
-@@ -230,7 +230,7 @@ static bool isMouseEvent(NSEvent *ev)
-     if (pw->frameStrutEventsEnabled() && isMouseEvent(theEvent)) {
-         NSPoint loc = [theEvent locationInWindow];
-         NSRect windowFrame = [self convertRectFromScreen:self.frame];
--        NSRect contentFrame = self.contentView.frame;
-+        NSRect contentFrame = [self.contentView frame];
-         if (NSMouseInRect(loc, windowFrame, NO) && !NSMouseInRect(loc, contentFrame, NO))
-             [qnsview_cast(pw->view()) handleFrameStrutMouseEvent:theEvent];
-     }
-@@ -257,7 +257,7 @@ static bool isMouseEvent(NSEvent *ev)
- + (void)applicationActivationChanged:(NSNotification*)notification
- {
-     const id sender = self;
--    NSEnumerator<NSWindow*> *windowEnumerator = nullptr;
-+    NSEnumerator *windowEnumerator = nullptr;
-     NSApplication *application = [NSApplication sharedApplication];
- 
-     // Unfortunately there's no NSWindowListOrderedBackToFront,
diff --git a/pkgs/development/libraries/qt-5/5.12/qtbase-revert-no-macos10.10.patch b/pkgs/development/libraries/qt-5/5.12/qtbase-revert-no-macos10.10.patch
deleted file mode 100644
index 29776518379..00000000000
--- a/pkgs/development/libraries/qt-5/5.12/qtbase-revert-no-macos10.10.patch
+++ /dev/null
@@ -1,102 +0,0 @@
-Revert "Remove code paths for macOS < 10.11"
-
-This reverts commit 138a65e0cfa80b13fd018a01e7d8b33341a3cfd3.
-
-From 138a65e0cfa80b13fd018a01e7d8b33341a3cfd3 Mon Sep 17 00:00:00 2001
-From: Jake Petroules <jake.petroules@qt.io>
-Date: Thu, 8 Feb 2018 11:05:42 -0800
-Subject: [PATCH] Remove code paths for macOS < 10.11
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-Change-Id: I5ae02d88aa3dcd97d1f2ebf6255a68643e5d6daa
-Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
-Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
----
- .../fontdatabases/mac/qfontengine_coretext.mm            | 16 +++-------------
- src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm    |  6 +-----
- src/plugins/platforms/cocoa/qnswindowdelegate.mm         | 16 ----------------
- 3 files changed, 4 insertions(+), 34 deletions(-)
-
-diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
-index 98b753eff9..489d9cd031 100644
---- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
-+++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
-@@ -47,18 +47,28 @@
- 
- #include <cmath>
- 
--#if defined(Q_OS_MACOS)
-+#if defined(Q_OS_OSX) && !QT_OSX_DEPLOYMENT_TARGET_BELOW(__MAC_10_11)
- #import <AppKit/AppKit.h>
- #endif
- 
--#if defined(QT_PLATFORM_UIKIT)
-+#if defined(QT_PLATFORM_UIKIT) && !QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_8_2)
- #import <UIKit/UIKit.h>
- #endif
- 
- // These are available cross platform, exported as kCTFontWeightXXX from CoreText.framework,
- // but they are not documented and are not in public headers so are private API and exposed
- // only through the NSFontWeightXXX and UIFontWeightXXX aliases in AppKit and UIKit (rdar://26109857)
--#if defined(Q_OS_MACOS)
-+#if QT_MAC_DEPLOYMENT_TARGET_BELOW(__MAC_10_11, __IPHONE_8_2)
-+#define kCTFontWeightUltraLight -0.8
-+#define kCTFontWeightThin -0.6
-+#define kCTFontWeightLight -0.4
-+#define kCTFontWeightRegular 0
-+#define kCTFontWeightMedium 0.23
-+#define kCTFontWeightSemibold 0.3
-+#define kCTFontWeightBold 0.4
-+#define kCTFontWeightHeavy 0.56
-+#define kCTFontWeightBlack 0.62
-+#elif defined(Q_OS_OSX)
- #define kCTFontWeightUltraLight NSFontWeightUltraLight
- #define kCTFontWeightThin NSFontWeightThin
- #define kCTFontWeightLight NSFontWeightLight
-diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
-index 94f2125bad..272cd9f3dc 100644
---- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
-+++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
-@@ -162,7 +162,11 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSOpenSavePanelDelegate);
-     // resetting our mCurrentDir, set the delegate
-     // here to make sure it gets the correct value.
-     [mSavePanel setDelegate:self];
--    mOpenPanel.accessoryViewDisclosed = YES;
-+
-+#if QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_11)
-+    if (__builtin_available(macOS 10.11, *))
-+        mOpenPanel.accessoryViewDisclosed = YES;
-+#endif
- 
-     if (mOptions->isLabelExplicitlySet(QFileDialogOptions::Accept))
-         [mSavePanel setPrompt:[self strip:options->labelText(QFileDialogOptions::Accept)]];
-diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.mm b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
-index 057a4c2943..eb55e50622 100644
---- a/src/plugins/platforms/cocoa/qnswindowdelegate.mm
-+++ b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
-@@ -103,6 +103,22 @@ static QRegExp whitespaceRegex = QRegExp(QStringLiteral("\\s*"));
-     return QCocoaScreen::mapToNative(maximizedFrame);
- }
- 
-+#if QT_MACOS_DEPLOYMENT_TARGET_BELOW(__MAC_10_11)
-+/*
-+    AppKit on OS X 10.10 wrongly calls windowWillUseStandardFrame:defaultFrame
-+    from -[NSWindow _frameForFullScreenMode] when going into fullscreen, resulting
-+    in black bars on top and bottom of the window. By implementing the following
-+    method, AppKit will choose that instead, and resolve the right fullscreen
-+    geometry.
-+*/
-+- (NSSize)window:(NSWindow *)window willUseFullScreenContentSize:(NSSize)proposedSize
-+{
-+    Q_UNUSED(proposedSize);
-+    Q_ASSERT(window == m_cocoaWindow->nativeWindow());
-+    return NSSizeFromCGSize(m_cocoaWindow->screen()->geometry().size().toCGSize());
-+}
-+#endif
-+
- - (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu
- {
-     Q_UNUSED(window);
diff --git a/pkgs/development/libraries/qt-5/5.9/default.nix b/pkgs/development/libraries/qt-5/5.9/default.nix
index be84691e6c3..d1e9af29926 100644
--- a/pkgs/development/libraries/qt-5/5.9/default.nix
+++ b/pkgs/development/libraries/qt-5/5.9/default.nix
@@ -38,7 +38,7 @@ let
   srcs = import ./srcs.nix { inherit fetchurl; inherit mirror; };
 
   patches = {
-    qtbase = [ ./qtbase.patch ./qtbase-fixguicmake.patch ] ++ optional stdenv.isDarwin ./qtbase-darwin.patch;
+    qtbase = [ ./qtbase.patch ./qtbase-fixguicmake.patch ];
     qtdeclarative = [ ./qtdeclarative.patch ];
     qtscript = [ ./qtscript.patch ];
     qtserialport = [ ./qtserialport.patch ];
diff --git a/pkgs/development/libraries/qt-5/5.9/qtbase-darwin.patch b/pkgs/development/libraries/qt-5/5.9/qtbase-darwin.patch
deleted file mode 100644
index 875fba12e2f..00000000000
--- a/pkgs/development/libraries/qt-5/5.9/qtbase-darwin.patch
+++ /dev/null
@@ -1,35 +0,0 @@
-diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm
-index 341d3bc..3368234 100644
---- a/src/plugins/bearer/corewlan/qcorewlanengine.mm
-+++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm
-@@ -287,7 +287,7 @@ void QScanThread::getUserConfigurations()
-     QMacAutoReleasePool pool;
-     userProfiles.clear();
- 
--    NSArray<NSString *> *wifiInterfaces = [CWWiFiClient interfaceNames];
-+    NSArray *wifiInterfaces = [CWWiFiClient interfaceNames];
-     for (NSString *ifName in wifiInterfaces) {
- 
-         CWInterface *wifiInterface = [[CWWiFiClient sharedWiFiClient] interfaceWithName:ifName];
-@@ -602,7 +602,7 @@ void QCoreWlanEngine::doRequestUpdate()
- 
-     QMacAutoReleasePool pool;
- 
--    NSArray<NSString *> *wifiInterfaces = [CWWiFiClient interfaceNames];
-+    NSArray *wifiInterfaces = [CWWiFiClient interfaceNames];
-     for (NSString *ifName in wifiInterfaces) {
-             scanThread->interfaceName = QString::fromNSString(ifName);
-             scanThread->start();
-diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
-index 5cd4beb..84919e6 100644
---- a/src/plugins/platforms/cocoa/qcocoawindow.mm
-+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
-@@ -320,7 +320,7 @@ static void qt_closePopups()
- + (void)applicationActivationChanged:(NSNotification*)notification
- {
-     const id sender = self;
--    NSEnumerator<NSWindow*> *windowEnumerator = nullptr;
-+    NSEnumerator *windowEnumerator = nullptr;
-     NSApplication *application = [NSApplication sharedApplication];
- 
- #if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_12)
diff --git a/pkgs/development/libraries/qt-5/modules/qtbase.nix b/pkgs/development/libraries/qt-5/modules/qtbase.nix
index 92ac8a24201..9ae7b274917 100644
--- a/pkgs/development/libraries/qt-5/modules/qtbase.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtbase.nix
@@ -2,7 +2,7 @@
   stdenv, lib,
   src, patches, version, qtCompatVersion,
 
-  coreutils, bison, flex, gdb, gperf, lndir, patchelf, perl, pkgconfig, python2,
+  coreutils, bison, flex, gdb, gperf, lndir, perl, pkgconfig, python2,
   which,
   # darwin support
   darwin, libiconv,
@@ -78,17 +78,15 @@ stdenv.mkDerivation {
       [ libinput ]
       ++ lib.optional withGtk3 gtk3
     )
-    ++ lib.optional stdenv.isDarwin
-      # Needed for OBJC_CLASS_$_NSDate symbols.
-      [ darwin.cf-private ]
+       # Needed for OBJC_CLASS_$_NSDate symbols.
+    ++ lib.optional stdenv.isDarwin darwin.cf-private
     ++ lib.optional developerBuild gdb
     ++ lib.optional (cups != null) cups
     ++ lib.optional (mysql != null) mysql.connector-c
     ++ lib.optional (postgresql != null) postgresql;
 
   nativeBuildInputs =
-    [ bison flex gperf lndir perl pkgconfig python2 which ]
-    ++ lib.optional (!stdenv.isDarwin) patchelf;
+    [ bison flex gperf lndir perl pkgconfig python2 which ];
 
   propagatedNativeBuildInputs = [ lndir ];
 
@@ -199,26 +197,11 @@ stdenv.mkDerivation {
       ''-DNIXPKGS_LIBXCURSOR="${libXcursor.out}/lib/libXcursor"''
     ]
 
-    ++ (
-      if stdenv.isDarwin
-      then
-        [
-          "-Wno-missing-sysroot"
-          "-D__MAC_OS_X_VERSION_MAX_ALLOWED=1090"
-          "-D__AVAILABILITY_INTERNAL__MAC_10_10=__attribute__((availability(macosx,introduced=10.10)))"
-          # Note that nixpkgs's objc4 is from macOS 10.11 while the SDK is
-          # 10.9 which necessitates the above macro definition that mentions
-          # 10.10
-        ]
-      else
-        lib.optional libGLSupported ''-DNIXPKGS_MESA_GL="${libGL.out}/lib/libGL"''
-        ++ lib.optionals withGtk3
-          [
-            ''-DNIXPKGS_QGTK3_XDG_DATA_DIRS="${gtk3}/share/gsettings-schemas/${gtk3.name}"''
-            ''-DNIXPKGS_QGTK3_GIO_EXTRA_MODULES="${dconf.lib}/lib/gio/modules"''
-          ]
-    )
-
+    ++ lib.optional libGLSupported ''-DNIXPKGS_MESA_GL="${libGL.out}/lib/libGL"''
+    ++ lib.optionals withGtk3 [
+         ''-DNIXPKGS_QGTK3_XDG_DATA_DIRS="${gtk3}/share/gsettings-schemas/${gtk3.name}"''
+         ''-DNIXPKGS_QGTK3_GIO_EXTRA_MODULES="${dconf.lib}/lib/gio/modules"''
+       ]
     ++ lib.optional decryptSslTraffic "-DQT_DECRYPT_SSL_TRAFFIC";
 
   prefixKey = "-prefix ";
@@ -392,6 +375,7 @@ stdenv.mkDerivation {
     license = with licenses; [ fdl13 gpl2 lgpl21 lgpl3 ];
     maintainers = with maintainers; [ qknight ttuegel periklis bkchr ];
     platforms = platforms.unix;
+    broken = stdenv.isDarwin && (compareVersion "5.9.0" < 0);
   };
 
 }
diff --git a/pkgs/development/libraries/qt-5/modules/qtwebengine.nix b/pkgs/development/libraries/qt-5/modules/qtwebengine.nix
index 91b7acf4365..fb838283b1b 100644
--- a/pkgs/development/libraries/qt-5/modules/qtwebengine.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtwebengine.nix
@@ -79,7 +79,7 @@ qtModule {
     cat <<EOF > src/3rdparty/chromium/build/mac/find_sdk.py
 #!/usr/bin/env python
 print("${darwin.apple_sdk.sdk}")
-print("10.10.0")
+print("10.12.0")
 EOF
 
     cat <<EOF > src/3rdparty/chromium/build/config/mac/sdk_info.py
@@ -102,22 +102,6 @@ EOF
       --replace 'libs = [ "sandbox" ]' 'libs = [ "/usr/lib/libsandbox.1.dylib" ]'
     '');
 
-  NIX_CFLAGS_COMPILE =
-    lib.optionalString stdenv.isDarwin [
-      "-DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_10"
-      "-DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_10"
-
-      #
-      # Prevent errors like
-      # /nix/store/xxx-apple-framework-CoreData/Library/Frameworks/CoreData.framework/Headers/NSEntityDescription.h:51:7:
-      # error: pointer to non-const type 'id' with no explicit ownership
-      #     id** _kvcPropertyAccessors;
-      #
-      # TODO remove when new Apple SDK is in
-      #
-      "-fno-objc-arc"
-    ];
-
   preConfigure = ''
     export NINJAFLAGS=-j$NIX_BUILD_CORES
 
diff --git a/pkgs/development/libraries/science/math/fenics/default.nix b/pkgs/development/libraries/science/math/fenics/default.nix
index 6c939d9a3a4..8134cc63eb0 100644
--- a/pkgs/development/libraries/science/math/fenics/default.nix
+++ b/pkgs/development/libraries/science/math/fenics/default.nix
@@ -35,10 +35,15 @@ let
       url = "https://bitbucket.org/fenics-project/dijitso/downloads/dijitso-${version}.tar.gz";
       sha256 = "0mw6mynjmg6yl3l2k33yra2x84s4r6mh44ylhk9znjfk74jra8zg";
     };
-    buildInputs = [ numpy pytest six ];
-    checkPhase = ''
+    buildInputs = [ numpy six ];
+    nativeBuildInputs = [ pytest ];
+    preCheck = ''
       export HOME=$PWD
+    '';
+    checkPhase = ''
+      runHook preCheck
       py.test test/
+      runHook postCheck
     '';
     meta = {
       description = "Distributed just-in-time shared library building";
diff --git a/pkgs/development/libraries/tk/generic.nix b/pkgs/development/libraries/tk/generic.nix
index d5eaff77c11..bd2453aad9a 100644
--- a/pkgs/development/libraries/tk/generic.nix
+++ b/pkgs/development/libraries/tk/generic.nix
@@ -27,8 +27,8 @@ stdenv.mkDerivation {
 
   nativeBuildInputs = [ pkgconfig ];
 
-  propagatedBuildInputs = [ tcl libXft ];
-  buildInputs = lib.optional enableAqua (with darwin; with apple_sdk.frameworks; [
+  propagatedBuildInputs = [ tcl libXft ]
+    ++ lib.optional enableAqua (with darwin; with apple_sdk.frameworks; [
       Cocoa cf-private
     ]);
 
diff --git a/pkgs/development/libraries/wxwidgets/2.9/default.nix b/pkgs/development/libraries/wxwidgets/2.9/default.nix
index 1938b15efbb..18e0cebec85 100644
--- a/pkgs/development/libraries/wxwidgets/2.9/default.nix
+++ b/pkgs/development/libraries/wxwidgets/2.9/default.nix
@@ -74,12 +74,13 @@ stdenv.mkDerivation {
   };
 
   enableParallelBuilding = true;
-  
+
   meta = {
     platforms = with platforms; darwin ++ linux;
     license = licenses.wxWindows;
     homepage = https://www.wxwidgets.org/;
     description = "a C++ library that lets developers create applications for Windows, macOS, Linux and other platforms with a single code base";
     longDescription = "wxWidgets gives you a single, easy-to-use API for writing GUI applications on multiple platforms that still utilize the native platform's controls and utilities. Link with the appropriate library for your platform and compiler, and your application will adopt the look and feel appropriate to that platform. On top of great GUI functionality, wxWidgets gives you: online help, network programming, streams, clipboard and drag and drop, multithreading, image loading and saving in a variety of popular formats, database support, HTML viewing and printing, and much more.";
+    badPlatforms = [ "x86_64-darwin" ];
   };
 }
diff --git a/pkgs/development/libraries/wxwidgets/3.0/default.nix b/pkgs/development/libraries/wxwidgets/3.0/default.nix
index 948b261fe45..a89f132b832 100644
--- a/pkgs/development/libraries/wxwidgets/3.0/default.nix
+++ b/pkgs/development/libraries/wxwidgets/3.0/default.nix
@@ -89,5 +89,6 @@ stdenv.mkDerivation rec {
     homepage = https://www.wxwidgets.org/;
     description = "a C++ library that lets developers create applications for Windows, macOS, Linux and other platforms with a single code base";
     longDescription = "wxWidgets gives you a single, easy-to-use API for writing GUI applications on multiple platforms that still utilize the native platform's controls and utilities. Link with the appropriate library for your platform and compiler, and your application will adopt the look and feel appropriate to that platform. On top of great GUI functionality, wxWidgets gives you: online help, network programming, streams, clipboard and drag and drop, multithreading, image loading and saving in a variety of popular formats, database support, HTML viewing and printing, and much more.";
+    badPlatforms = [ "x86_64-darwin" ];
   };
 }
diff --git a/pkgs/development/libraries/wxwidgets/3.0/mac.nix b/pkgs/development/libraries/wxwidgets/3.0/mac.nix
index 040273e28b9..6e559cfb6a9 100644
--- a/pkgs/development/libraries/wxwidgets/3.0/mac.nix
+++ b/pkgs/development/libraries/wxwidgets/3.0/mac.nix
@@ -71,5 +71,6 @@ stdenv.mkDerivation rec {
     homepage = https://www.wxwidgets.org/;
     description = "a C++ library that lets developers create applications for Windows, macOS, Linux and other platforms with a single code base";
     longDescription = "wxWidgets gives you a single, easy-to-use API for writing GUI applications on multiple platforms that still utilize the native platform's controls and utilities. Link with the appropriate library for your platform and compiler, and your application will adopt the look and feel appropriate to that platform. On top of great GUI functionality, wxWidgets gives you: online help, network programming, streams, clipboard and drag and drop, multithreading, image loading and saving in a variety of popular formats, database support, HTML viewing and printing, and much more.";
+    broken = true;
   };
 }
diff --git a/pkgs/development/python-modules/cffi/default.nix b/pkgs/development/python-modules/cffi/default.nix
index 0265288d3b8..cfabeb16b59 100644
--- a/pkgs/development/python-modules/cffi/default.nix
+++ b/pkgs/development/python-modules/cffi/default.nix
@@ -31,7 +31,7 @@ if isPyPy then null else buildPythonPackage rec {
   # The tests use -Werror but with python3.6 clang detects some unreachable code.
   NIX_CFLAGS_COMPILE = stdenv.lib.optionals stdenv.cc.isClang [ "-Wno-unused-command-line-argument" "-Wno-unreachable-code" ];
 
-  doCheck = !stdenv.hostPlatform.isMusl; # TODO: Investigate
+  doCheck = !stdenv.hostPlatform.isMusl && !stdenv.isDarwin; # TODO: Investigate
   checkPhase = ''
     py.test -k "not test_char_pointer_conversion"
   '';
diff --git a/pkgs/development/python-modules/cryptography/default.nix b/pkgs/development/python-modules/cryptography/default.nix
index 69c9f729294..f40f0bf63d8 100644
--- a/pkgs/development/python-modules/cryptography/default.nix
+++ b/pkgs/development/python-modules/cryptography/default.nix
@@ -53,14 +53,6 @@ buildPythonPackage rec {
     py.test --disable-pytest-warnings tests
   '';
 
-  # The test assumes that if we're on Sierra or higher, that we use `getentropy`, but for binary
-  # compatibility with pre-Sierra for binary caches, we hide that symbol so the library doesn't
-  # use it. This boils down to them checking compatibility with `getentropy` in two different places,
-  # so let's neuter the second test.
-  postPatch = ''
-    substituteInPlace ./tests/hazmat/backends/test_openssl.py --replace '"16.0"' '"99.0"'
-  '';
-
   # IOKit's dependencies are inconsistent between OSX versions, so this is the best we
   # can do until nix 1.11's release
   __impureHostDeps = [ "/usr/lib" ];
diff --git a/pkgs/development/python-modules/matplotlib/2.nix b/pkgs/development/python-modules/matplotlib/2.nix
index 810f37b4b13..5a45b02a240 100644
--- a/pkgs/development/python-modules/matplotlib/2.nix
+++ b/pkgs/development/python-modules/matplotlib/2.nix
@@ -60,7 +60,7 @@ buildPythonPackage rec {
       url = "https://github.com/matplotlib/matplotlib/commit/2980184d092382a40ab21f95b79582ffae6e19d6.patch";
       sha256 = "1c0wj28zy8s5h6qiavx9zzbhlmhjwpzbc3fyyw9039mbnqk0spg2";
     })
-  ] ++ stdenv.lib.optionals stdenv.isDarwin [ ./darwin-stdenv-2.2.3.patch ];
+  ];
 
   # Matplotlib tries to find Tcl/Tk by opening a Tk window and asking the
   # corresponding interpreter object for its library paths. This fails if
diff --git a/pkgs/development/python-modules/matplotlib/darwin-stdenv-2.2.3.patch b/pkgs/development/python-modules/matplotlib/darwin-stdenv-2.2.3.patch
deleted file mode 100644
index ca399b4e684..00000000000
--- a/pkgs/development/python-modules/matplotlib/darwin-stdenv-2.2.3.patch
+++ /dev/null
@@ -1,10 +0,0 @@
---- a/src/_macosx.m	2015-10-30 00:46:20.000000000 +0200
-+++ b/src/_macosx.m	2015-11-01 14:52:25.000000000 +0200
-@@ -6264,6 +6264,7 @@
- 
- static bool verify_framework(void)
- {
-+    return true;  /* nixpkgs darwin stdenv */
- #ifdef COMPILING_FOR_10_6
-     NSRunningApplication* app = [NSRunningApplication currentApplication];
-     NSApplicationActivationPolicy activationPolicy = [app activationPolicy];
diff --git a/pkgs/development/python-modules/matplotlib/darwin-stdenv.patch b/pkgs/development/python-modules/matplotlib/darwin-stdenv.patch
deleted file mode 100644
index 27ed8fc9f96..00000000000
--- a/pkgs/development/python-modules/matplotlib/darwin-stdenv.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-diff -ruN matplotlib-3.0.0/src/_macosx.m matplotlib-3.0.0.patched/src/_macosx.m
---- matplotlib-3.0.0/src/_macosx.m	2018-09-16 00:35:21.000000000 +0200
-+++ matplotlib-3.0.0.patched/src/_macosx.m	2018-11-03 13:14:33.000000000 +0100
-@@ -2577,6 +2577,7 @@
- 
- static bool verify_framework(void)
- {
-+    return true;  /* nixpkgs darwin stdenv */
-     ProcessSerialNumber psn;
-     /* These methods are deprecated, but they don't require the app to
-        have started  */
-
diff --git a/pkgs/development/python-modules/matplotlib/default.nix b/pkgs/development/python-modules/matplotlib/default.nix
index d3ea365082c..cbdd43af811 100644
--- a/pkgs/development/python-modules/matplotlib/default.nix
+++ b/pkgs/development/python-modules/matplotlib/default.nix
@@ -52,8 +52,7 @@ buildPythonPackage rec {
     ++ stdenv.lib.optionals enableQt [ pyqt4 ];
 
   patches =
-    [ ./basedirlist.patch ] ++
-    stdenv.lib.optionals stdenv.isDarwin [ ./darwin-stdenv.patch ];
+    [ ./basedirlist.patch ];
 
   # Matplotlib tries to find Tcl/Tk by opening a Tk window and asking the
   # corresponding interpreter object for its library paths. This fails if
diff --git a/pkgs/development/python-modules/paho-mqtt/default.nix b/pkgs/development/python-modules/paho-mqtt/default.nix
index d58b31ffc04..bf7ebee5657 100644
--- a/pkgs/development/python-modules/paho-mqtt/default.nix
+++ b/pkgs/development/python-modules/paho-mqtt/default.nix
@@ -1,5 +1,5 @@
 { lib, buildPythonPackage, fetchFromGitHub, isPy3k
-, pytestrunner, pytest, mock }:
+, stdenv, pytestrunner, pytest, mock }:
 
 buildPythonPackage rec {
   pname = "paho-mqtt";
@@ -20,6 +20,8 @@ buildPythonPackage rec {
 
   checkInputs = [ pytestrunner pytest ] ++ lib.optional (!isPy3k) mock;
 
+  doCheck = !stdenv.isDarwin;
+
   meta = with lib; {
     homepage = https://eclipse.org/paho;
     description = "MQTT version 3.1.1 client class";
diff --git a/pkgs/development/python-modules/papis/default.nix b/pkgs/development/python-modules/papis/default.nix
index d9be946900c..5a9934d6be6 100644
--- a/pkgs/development/python-modules/papis/default.nix
+++ b/pkgs/development/python-modules/papis/default.nix
@@ -5,6 +5,7 @@
 , prompt_toolkit, pygments
 #, optional, dependencies
 , jinja2, whoosh, pytest
+, stdenv
 }:
 
 buildPythonPackage rec {
@@ -28,6 +29,8 @@ buildPythonPackage rec {
     jinja2 whoosh
   ];
 
+  doCheck = !stdenv.isDarwin;
+
   checkInputs = ([
     pytest
   ]) ++ [
diff --git a/pkgs/development/python-modules/sqlalchemy-migrate/default.nix b/pkgs/development/python-modules/sqlalchemy-migrate/default.nix
index 9daf2a696c2..596f9e47a08 100644
--- a/pkgs/development/python-modules/sqlalchemy-migrate/default.nix
+++ b/pkgs/development/python-modules/sqlalchemy-migrate/default.nix
@@ -21,6 +21,8 @@ buildPythonPackage rec {
   checkInputs = [ unittest2 scripttest pytz mock testtools testrepository ];
   propagatedBuildInputs = [ pbr tempita decorator sqlalchemy six sqlparse ];
 
+  doCheck = !stdenv.isDarwin;
+
   prePatch = ''
     sed -i -e /tempest-lib/d \
            -e /testtools/d \
diff --git a/pkgs/development/python-modules/xlib/default.nix b/pkgs/development/python-modules/xlib/default.nix
index 0b0f60ea16e..1903c3aaca8 100644
--- a/pkgs/development/python-modules/xlib/default.nix
+++ b/pkgs/development/python-modules/xlib/default.nix
@@ -30,6 +30,8 @@ buildPythonPackage rec {
   buildInputs = [ xorg.libX11 ];
   propagatedBuildInputs = [ six ];
 
+  doCheck = !stdenv.isDarwin;
+
   meta = with stdenv.lib; {
     description = "Fully functional X client library for Python programs";
     homepage = http://python-xlib.sourceforge.net/;
diff --git a/pkgs/development/python-modules/xml2rfc/default.nix b/pkgs/development/python-modules/xml2rfc/default.nix
index e86b1b20609..f737cf344b8 100644
--- a/pkgs/development/python-modules/xml2rfc/default.nix
+++ b/pkgs/development/python-modules/xml2rfc/default.nix
@@ -1,5 +1,6 @@
 { lib, fetchPypi, buildPythonPackage, intervaltree, pyflakes, requests, lxml, google-i18n-address
 , pycountry, html5lib, six
+, stdenv
 }:
 
 buildPythonPackage rec {
@@ -26,6 +27,8 @@ buildPythonPackage rec {
     export HOME=$(mktemp -d)
   '';
 
+  doCheck = !stdenv.isDarwin;
+
   meta = with lib; {
     description = "Tool generating IETF RFCs and drafts from XML sources";
     homepage = https://tools.ietf.org/tools/xml2rfc/trac/;
diff --git a/pkgs/development/python-modules/zope_testrunner/default.nix b/pkgs/development/python-modules/zope_testrunner/default.nix
index 25f167b2e94..fd2cf470e6f 100644
--- a/pkgs/development/python-modules/zope_testrunner/default.nix
+++ b/pkgs/development/python-modules/zope_testrunner/default.nix
@@ -19,6 +19,8 @@ buildPythonPackage rec {
 
   propagatedBuildInputs = [ zope_interface zope_exceptions zope_testing six ];
 
+  doCheck = !stdenv.isDarwin;
+
   meta = with stdenv.lib; {
     description = "A flexible test runner with layer support";
     homepage = https://pypi.python.org/pypi/zope.testrunner;
diff --git a/pkgs/development/tools/analysis/valgrind/default.nix b/pkgs/development/tools/analysis/valgrind/default.nix
index 78f40913eb5..9942123a512 100644
--- a/pkgs/development/tools/analysis/valgrind/default.nix
+++ b/pkgs/development/tools/analysis/valgrind/default.nix
@@ -44,14 +44,8 @@ stdenv.mkDerivation rec {
       substituteInPlace coregrind/Makefile.in \
          --replace /usr/include/mach ${xnu}/include/mach
 
-      echo "substitute hardcoded dsymutil with ${llvm}/bin/llvm-dsymutil"
-      find -name "Makefile.in" | while read file; do
-         substituteInPlace "$file" \
-           --replace dsymutil ${llvm}/bin/llvm-dsymutil
-      done
-
       substituteInPlace coregrind/m_debuginfo/readmacho.c \
-         --replace /usr/bin/dsymutil ${llvm}/bin/llvm-dsymutil
+         --replace /usr/bin/dsymutil ${stdenv.cc.bintools.bintools}/bin/dsymutil
 
       echo "substitute hardcoded /usr/bin/ld with ${cctools}/bin/ld"
       substituteInPlace coregrind/link_tool_exe_darwin.in \
diff --git a/pkgs/development/tools/build-managers/cmake/application-services.patch b/pkgs/development/tools/build-managers/cmake/application-services.patch
index 78077f9eaa5..2107dcdfbc6 100644
--- a/pkgs/development/tools/build-managers/cmake/application-services.patch
+++ b/pkgs/development/tools/build-managers/cmake/application-services.patch
@@ -2,16 +2,16 @@ diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
 index 8aff8f6..af1852d 100644
 --- a/Source/CMakeLists.txt
 +++ b/Source/CMakeLists.txt
-@@ -791,12 +791,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "sparc"
+@@ -791,12 +791,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "sparc"
    endif()
  endif()
  
--# On Apple we need CoreFoundation and CoreServices
--if(APPLE)
--  target_link_libraries(CMakeLib "-framework CoreFoundation")
+ # On Apple we need CoreFoundation and CoreServices
+ if(APPLE)
+   target_link_libraries(CMakeLib "-framework CoreFoundation")
 -  target_link_libraries(CMakeLib "-framework CoreServices")
--endif()
--
+ endif()
+ 
  if(WIN32 AND NOT UNIX)
    # We need the rpcrt4 library on Windows.
    # We need the crypt32 library on Windows for crypto/cert APIs.
diff --git a/pkgs/development/tools/build-managers/cmake/default.nix b/pkgs/development/tools/build-managers/cmake/default.nix
index 54fe8e4af5a..721015f0c7c 100644
--- a/pkgs/development/tools/build-managers/cmake/default.nix
+++ b/pkgs/development/tools/build-managers/cmake/default.nix
@@ -2,7 +2,7 @@
 , bzip2, curl, expat, libarchive, xz, zlib, libuv, rhash
 , buildPackages
 # darwin attributes
-, cf-private, ps
+, ps
 , isBootstrap ? false
 , useSharedLibraries ? (!isBootstrap && !stdenv.isCygwin)
 , useNcurses ? false, ncurses
@@ -52,7 +52,6 @@ stdenv.mkDerivation rec {
 
   buildInputs =
     [ setupHook pkgconfig ]
-    ++ optional stdenv.isDarwin cf-private  # needed for CFBundleCopyExecutableURL
     ++ optionals useSharedLibraries [ bzip2 curl expat libarchive xz zlib libuv rhash ]
     ++ optional useNcurses ncurses
     ++ optional useQt4 qt4
diff --git a/pkgs/development/tools/build-managers/dub/default.nix b/pkgs/development/tools/build-managers/dub/default.nix
index 3f733e97eed..7b882926e1f 100644
--- a/pkgs/development/tools/build-managers/dub/default.nix
+++ b/pkgs/development/tools/build-managers/dub/default.nix
@@ -32,7 +32,7 @@ stdenv.mkDerivation rec {
     ./build.sh
   '';
 
-  doCheck = true;
+  doCheck = !stdenv.isDarwin;
 
   checkPhase = ''
     export DUB=$NIX_BUILD_TOP/source/bin/dub
diff --git a/pkgs/stdenv/darwin/darwin-secure-format.patch b/pkgs/development/tools/misc/gnum4/darwin-secure-format.patch
index b14d8be6ef1..b14d8be6ef1 100644
--- a/pkgs/stdenv/darwin/darwin-secure-format.patch
+++ b/pkgs/development/tools/misc/gnum4/darwin-secure-format.patch
diff --git a/pkgs/development/tools/misc/gnum4/default.nix b/pkgs/development/tools/misc/gnum4/default.nix
index f477d42fcf1..afe9b59e012 100644
--- a/pkgs/development/tools/misc/gnum4/default.nix
+++ b/pkgs/development/tools/misc/gnum4/default.nix
@@ -13,7 +13,8 @@ stdenv.mkDerivation rec {
   configureFlags = [ "--with-syscmd-shell=${stdenv.shell}" ];
 
   # Upstream is aware of it; it may be in the next release.
-  patches = [ ./s_isdir.patch ] ++ stdenv.lib.optional stdenv.hostPlatform.isDarwin stdenv.secure-format-patch;
+  patches = [ ./s_isdir.patch ]
+    ++ stdenv.lib.optional stdenv.isDarwin ./darwin-secure-format.patch;
 
   meta = {
     homepage = https://www.gnu.org/software/m4/;
diff --git a/pkgs/development/tools/misc/tokei/default.nix b/pkgs/development/tools/misc/tokei/default.nix
index 65a210ed4b9..f9b4343a63a 100644
--- a/pkgs/development/tools/misc/tokei/default.nix
+++ b/pkgs/development/tools/misc/tokei/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, rustPlatform }:
+{ stdenv, fetchFromGitHub, rustPlatform, libiconv }:
 
 rustPlatform.buildRustPackage rec {
   pname = "tokei";
@@ -13,6 +13,8 @@ rustPlatform.buildRustPackage rec {
 
   cargoSha256 = "1xai3jxvs8r3s3v5d5w40miw6nihnj9gzlzzdrwphmgrkywr88c4";
 
+  buildInputs = [ libiconv ];
+
   meta = with stdenv.lib; {
     description = "Program that displays statistics about your code";
     homepage = https://github.com/XAMPPRocky/tokei;
diff --git a/pkgs/development/tools/xcbuild/toolchains.nix b/pkgs/development/tools/xcbuild/toolchains.nix
index 92ff35ac8b5..e435f0978c5 100644
--- a/pkgs/development/tools/xcbuild/toolchains.nix
+++ b/pkgs/development/tools/xcbuild/toolchains.nix
@@ -67,6 +67,7 @@ runCommand "Toolchains" {} (''
   done
 
   ln -s ${buildPackages.darwin.bootstrap_cmds}/bin/mig $toolchain/bin
+  mkdir -p $toolchain/libexec
   ln -s ${buildPackages.darwin.bootstrap_cmds}/libexec/migcom $toolchain/libexec
   ln -s ${mkdep-darwin-src} $toolchain/bin/mkdep
 '')
diff --git a/pkgs/development/tools/xcbuild/wrapper.nix b/pkgs/development/tools/xcbuild/wrapper.nix
index 959c79405e8..902d2104050 100644
--- a/pkgs/development/tools/xcbuild/wrapper.nix
+++ b/pkgs/development/tools/xcbuild/wrapper.nix
@@ -1,6 +1,6 @@
 { stdenv, lib, buildPackages, makeWrapper, writeText, runCommand
 , CoreServices, ImageIO, CoreGraphics
-, runtimeShell
+, runtimeShell, callPackage
 , xcodePlatform ? stdenv.targetPlatform.xcodePlatform or "MacOSX"
 , xcodeVer ? stdenv.targetPlatform.xcodeVer or "9.4.1"
 , sdkVer ? stdenv.targetPlatform.sdkVer or "10.10" }:
@@ -14,20 +14,20 @@ let
   sdkBuildVersion = "17E189";
   xcodeSelectVersion = "2349";
 
-  xcbuild = buildPackages.callPackage ./default.nix {
-    inherit CoreServices ImageIO CoreGraphics;
+  xcbuild = callPackage ./default.nix {
+    inherit CoreServices ImageIO CoreGraphics stdenv;
   };
 
-  toolchains = buildPackages.callPackage ./toolchains.nix {
-    inherit toolchainName;
+  toolchains = callPackage ./toolchains.nix {
+    inherit toolchainName stdenv;
   };
 
-  sdks = buildPackages.callPackage ./sdks.nix {
+  sdks = callPackage ./sdks.nix {
     inherit toolchainName sdkName xcodePlatform;
     version = sdkVer;
   };
 
-  platforms = buildPackages.callPackage ./platforms.nix {
+  platforms = callPackage ./platforms.nix {
     inherit sdks xcodePlatform;
   };
 
diff --git a/pkgs/games/gargoyle/darwin.patch b/pkgs/games/gargoyle/darwin.patch
deleted file mode 100644
index 6958fe495d2..00000000000
--- a/pkgs/games/gargoyle/darwin.patch
+++ /dev/null
@@ -1,64 +0,0 @@
---- a/garglk/fontmac.m
-+++ b/garglk/fontmac.m
-@@ -167,7 +167,7 @@ static void propfont(char *file, int style)
-     }
- }
- 
--static NSMutableArray<NSURL *> * gli_registered_fonts = nil;
-+static NSMutableArray * gli_registered_fonts = nil;
- static NSDistributedLock * gli_font_lock = nil;
- 
- void fontreplace(char *font, int type)
-@@ -181,7 +181,7 @@ void fontreplace(char *font, int type)
-     NSFontDescriptor * fontFamilyDescriptor =
-         [[NSFontDescriptor fontDescriptorWithFontAttributes: nil] fontDescriptorWithFamily: fontFamily];
- 
--    NSArray<NSFontDescriptor *> * fontMatches =
-+    NSArray * fontMatches =
-         [fontFamilyDescriptor matchingFontDescriptorsWithMandatoryKeys: nil];
- 
-     for (NSFontDescriptor * sysfont in fontMatches)
-@@ -259,7 +259,7 @@ void fontload(void)
- 
-     // obtain a list of all files in the Fonts directory
-     NSString * fontFolder = [[NSString stringWithUTF8String: env] stringByAppendingPathComponent: @"Fonts"];
--    NSArray<NSString *> * fontFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: fontFolder error: nil];
-+    NSArray * fontFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: fontFolder error: nil];
- 
-     // create a collection to hold the registered font URLs
-     gli_registered_fonts = [NSMutableArray new];
---- a/garglk/launchmac.m
-+++ b/garglk/launchmac.m
-@@ -556,7 +556,7 @@ static BOOL isTextbufferEvent(NSEvent * evt)
-                          <GargoyleApp, NSApplicationDelegate, NSWindowDelegate>
- {
-     BOOL openedFirstGame;
--    NSMutableDictionary<NSNumber *, GargoyleWindow *> * windows;
-+    NSMutableDictionary * windows;
-     NSConnection * link;
- }
- - (BOOL) launchFile: (NSString *) file;
---- a/garglk/ttsmac.m
-+++ b/garglk/ttsmac.m
-@@ -30,7 +30,7 @@
- #import "sysmac.h"
- 
- // a queue of phrases to feed to the speech synthesizer
--static NSMutableArray<NSString *> * phraseQueue = nil;
-+static NSMutableArray * phraseQueue = nil;
- static NSRange purgeRange;
- 
- @interface SpeechDelegate : NSObject <NSSpeechSynthesizerDelegate>
-@@ -96,10 +96,10 @@ void gli_initialize_tts(void)
-             NSString * lang = [NSString stringWithCString: gli_conf_speak_language
-                                                  encoding: NSUTF8StringEncoding];
- 
--            NSArray<NSString *> * voices = [NSSpeechSynthesizer availableVoices];
-+            NSArray * voices = [NSSpeechSynthesizer availableVoices];
-             for (NSString * voice in voices)
-             {
--                NSDictionary<NSString *, id> * attr = [NSSpeechSynthesizer attributesForVoice: voice];
-+                NSDictionary * attr = [NSSpeechSynthesizer attributesForVoice: voice];
-                 if ([lang isEqualToString: [attr objectForKey: NSVoiceLocaleIdentifier]])
-                 {
-                     [synth setVoice: voice];
diff --git a/pkgs/games/gargoyle/default.nix b/pkgs/games/gargoyle/default.nix
index e645a40aa75..62ea798e465 100644
--- a/pkgs/games/gargoyle/default.nix
+++ b/pkgs/games/gargoyle/default.nix
@@ -34,8 +34,6 @@ stdenv.mkDerivation {
   buildInputs = [ SDL SDL_mixer SDL_sound gtk2 ]
     ++ stdenv.lib.optionals stdenv.isDarwin [ cf-private smpeg libvorbis ];
 
-  patches = [ ./darwin.patch ];
-
   buildPhase = jamenv + "jam -j$NIX_BUILD_CORES";
 
   installPhase =
diff --git a/pkgs/games/quake2/yquake2/default.nix b/pkgs/games/quake2/yquake2/default.nix
index 1e7032eb05c..1564ba19bd2 100644
--- a/pkgs/games/quake2/yquake2/default.nix
+++ b/pkgs/games/quake2/yquake2/default.nix
@@ -3,6 +3,7 @@
 , oggSupport ? true, libogg, libvorbis
 , openalSupport ? true, openal
 , zipSupport ? true, zlib
+, Cocoa, OpenAL
 }:
 
 let
@@ -28,6 +29,7 @@ let
     nativeBuildInputs = [ cmake ];
 
     buildInputs = [ SDL2 libGL ]
+      ++ lib.optionals stdenv.isDarwin [ Cocoa OpenAL ]
       ++ lib.optionals oggSupport [ libogg libvorbis ]
       ++ lib.optional openalSupport openal
       ++ lib.optional zipSupport zlib;
diff --git a/pkgs/misc/jackaudio/default.nix b/pkgs/misc/jackaudio/default.nix
index 556b66befe6..b37af235d35 100644
--- a/pkgs/misc/jackaudio/default.nix
+++ b/pkgs/misc/jackaudio/default.nix
@@ -76,5 +76,6 @@ stdenv.mkDerivation rec {
     license = licenses.gpl2Plus;
     platforms = platforms.unix;
     maintainers = with maintainers; [ goibhniu ];
+    badPlatforms = [ "x86_64-darwin" ];
   };
 }
diff --git a/pkgs/os-specific/darwin/apple-sdk/default.nix b/pkgs/os-specific/darwin/apple-sdk/default.nix
index c23a2148143..7c3e3e63967 100644
--- a/pkgs/os-specific/darwin/apple-sdk/default.nix
+++ b/pkgs/os-specific/darwin/apple-sdk/default.nix
@@ -1,30 +1,22 @@
-{ stdenv, fetchurl, xar, xz, cpio, pkgs, python, lib }:
+{ stdenv, fetchurl, xar, cpio, pkgs, python, pbzx, lib }:
 
 let
-  # TODO: make this available to other packages and generalize the unpacking a bit
-  # from https://gist.github.com/pudquick/ff412bcb29c9c1fa4b8d
-  # This isn't needed until we get to SDK 10.11, but that presents other challenges
-  # unpbzx = fetchurl {
-  #   url    = "https://gist.githubusercontent.com/pudquick/ff412bcb29c9c1fa4b8d/raw/24b25538ea8df8d0634a2a6189aa581ccc6a5b4b/parse_pbzx2.py";
-  #   sha256 = "0jgp6qbfl36i0jlz7as5zk2w20z4ca8wlrhdw49lwsld6wi3rfhc";
-  # };
-
   # sadly needs to be exported because security_tool needs it
   sdk = stdenv.mkDerivation rec {
-    version = "10.10";
+    version = "10.12";
     name    = "MacOS_SDK-${version}";
 
-    # This URL comes from https://swscan.apple.com/content/catalogs/others/index-10.10.merged-1.sucatalog, which we found by:
+    # This URL comes from https://swscan.apple.com/content/catalogs/others/index-10.12.merged-1.sucatalog, which we found by:
     #  1. Google: site:swscan.apple.com and look for a name that seems appropriate for your version
     #  2. In the resulting file, search for a file called DevSDK ending in .pkg
     #  3. ???
     #  4. Profit
     src = fetchurl {
-      url    = "http://swcdn.apple.com/content/downloads/22/52/031-45139/hcjjv7cm4n6yqk56ict73qqw15ikm5iaql/DevSDK_OSX1010.pkg";
-      sha256 = "08bxa93zw7r4vzs28j9giq2qyk3b68ky6jx1bb9850gflr3nvgq1";
+      url    = "http://swcdn.apple.com/content/downloads/28/09/091-29862/pafhn2u002b9slnrxzy9p86rpedycnjhb5/DevSDK_OSX1012.pkg";
+      sha256 = "1sggc70rypqwcjwr7ciavw8sczwll16cwqxdxrbw7r2qvy3b0nhx";
     };
 
-    buildInputs = [ xar xz cpio python ];
+    buildInputs = [ xar cpio python pbzx ];
 
     phases = [ "unpackPhase" "installPhase" "fixupPhase" ];
     outputs = [ "out" "dev" "man" ];
@@ -37,7 +29,7 @@ let
       start="$(pwd)"
       mkdir -p $out
       cd $out
-      cat $start/Payload | gzip -d | cpio -idm
+      pbzx -n $start/Payload | cpio -idm
 
       mv usr/* .
       rmdir usr
@@ -48,12 +40,6 @@ let
       pushd lib
       ln -s -L /usr/lib/libcups*.dylib .
       popd
-
-      cd Library/Frameworks/QuartzCore.framework/Versions/A/Headers
-      for file in CI*.h; do
-        rm $file
-        ln -s ../Frameworks/CoreImage.framework/Headers/$file
-      done
     '';
 
     meta = with stdenv.lib; {
@@ -88,13 +74,12 @@ let
 
         # Keep track of if this is a child or a child rescue as with
         # ApplicationServices in the 10.9 SDK
-        local isChild
+        local isChild=0
 
         if [ -d "${sdk.out}/Library/Frameworks/$path/Versions/$current/Headers" ]; then
           isChild=1
           cp -R "${sdk.out}/Library/Frameworks/$path/Versions/$current/Headers" .
-        else
-          isChild=0
+        elif [ -d "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" ]; then
           current="$(readlink "/System/Library/Frameworks/$name.framework/Versions/Current")"
           cp -R "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" .
         fi
@@ -111,11 +96,6 @@ let
           pushd "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current" >/dev/null
         fi
         local children=$(echo Frameworks/*.framework)
-        if [ "$name" == "ApplicationServices" ]; then
-          # Fixing up ApplicationServices which is missing
-          # CoreGraphics in the 10.9 SDK
-          children="$children Frameworks/CoreGraphics.framework"
-        fi
         popd >/dev/null
 
         for child in $children; do
diff --git a/pkgs/os-specific/darwin/apple-sdk/frameworks.nix b/pkgs/os-specific/darwin/apple-sdk/frameworks.nix
index aab2852c168..e55abf9dfb6 100644
--- a/pkgs/os-specific/darwin/apple-sdk/frameworks.nix
+++ b/pkgs/os-specific/darwin/apple-sdk/frameworks.nix
@@ -10,12 +10,12 @@ with frameworks; with libs; {
   AVKit                   = [];
   Accounts                = [];
   AddressBook             = [ Carbon CF ];
-  AppKit                  = [ AudioToolbox Foundation QuartzCore ];
+  AppKit                  = [ AudioToolbox AudioUnit Foundation QuartzCore ];
   AppKitScripting         = [];
   AppleScriptKit          = [];
   AppleScriptObjC         = [];
-  AudioToolbox            = [ AudioUnit CoreAudio CF CoreMIDI ];
-  AudioUnit               = [ Carbon CoreAudio CF ];
+  AudioToolbox            = [ CoreAudio CF CoreMIDI ];
+  AudioUnit               = [ AudioToolbox Carbon CoreAudio CF ];
   AudioVideoBridging      = [ Foundation ];
   Automator               = [];
   CFNetwork               = [ CF ];
@@ -29,26 +29,25 @@ with frameworks; with libs; {
   CoreAudioKit            = [ AudioUnit ];
   CoreData                = [];
   CoreGraphics            = [ Accelerate CF IOKit IOSurface SystemConfiguration ];
+  CoreImage               = [ ];
   CoreLocation            = [];
   CoreMIDI                = [ CF ];
   CoreMIDIServer          = [];
-  CoreMedia               = [ ApplicationServices AudioToolbox CoreAudio CF CoreGraphics CoreVideo ];
+  CoreMedia               = [ ApplicationServices AudioToolbox AudioUnit CoreAudio CF CoreGraphics CoreVideo ];
   CoreMediaIO             = [ CF CoreMedia ];
   CoreText                = [ CF CoreGraphics ];
   CoreVideo               = [ ApplicationServices CF CoreGraphics IOSurface OpenGL ];
   CoreWLAN                = [ SecurityFoundation ];
-  DVComponentGlue         = [ CoreServices QuickTime ];
   DVDPlayback             = [];
   DirectoryService        = [ CF ];
   DiscRecording           = [ CF CoreServices IOKit ];
   DiscRecordingUI         = [];
   DiskArbitration         = [ CF IOKit ];
-  DrawSprocket            = [ Carbon ];
   EventKit                = [];
   ExceptionHandling       = [];
   FWAUserLib              = [];
   ForceFeedback           = [ CF IOKit ];
-  Foundation              = [ CF libobjc Security ApplicationServices SystemConfiguration ];
+  Foundation              = [ cf-private libobjc Security ApplicationServices SystemConfiguration ];
   GLKit                   = [ CF ];
   GLUT                    = [ OpenGL ];
   GSS                     = [];
@@ -73,7 +72,8 @@ with frameworks; with libs; {
   LatentSemanticMapping   = [ Carbon CF ];
   MapKit                  = [];
   MediaAccessibility      = [ CF CoreGraphics CoreText QuartzCore ];
-  MediaToolbox            = [ AudioToolbox CF CoreMedia ];
+  MediaToolbox            = [ AudioToolbox AudioUnit CF CoreMedia ];
+  Metal                   = [];
   NetFS                   = [ CF ];
   OSAKit                  = [ Carbon ];
   OpenAL                  = [];
@@ -84,7 +84,6 @@ with frameworks; with libs; {
   PubSub                  = [];
   QTKit                   = [ CoreMediaIO CoreMedia MediaToolbox QuickTime VideoToolbox ];
   QuickLook               = [ ApplicationServices CF ];
-  QuickTime               = [ ApplicationServices AudioUnit Carbon CoreAudio CoreServices OpenGL QuartzCore ];
   SceneKit                = [];
   ScreenSaver             = [];
   Scripting               = [];
@@ -114,7 +113,8 @@ with frameworks; with libs; {
   JavaVM              = [];
   OpenDirectory       = [];
   Quartz              = [ QuickLook QTKit ];
-  QuartzCore          = [ ApplicationServices CF CoreVideo OpenCL ];
+  QuartzCore          = [ ApplicationServices CF CoreVideo OpenCL CoreImage Metal ];
+  QuickTime           = [ ApplicationServices AudioUnit Carbon CoreAudio CoreServices OpenGL QuartzCore ];
 
   vmnet = [];
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/Libc/CrashReporterClient.h b/pkgs/os-specific/darwin/apple-source-releases/Libc/CrashReporterClient.h
new file mode 100644
index 00000000000..a1cbb72b917
--- /dev/null
+++ b/pkgs/os-specific/darwin/apple-source-releases/Libc/CrashReporterClient.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2010 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/***********************************************************************
+ * Not to be installed in /usr/local/include
+ ***********************************************************************/
+
+#ifndef _LIBC_CRASHREPORTERCLIENT_H
+#define _LIBC_CRASHREPORTERCLIENT_H
+
+#include "stdint.h"
+
+/* Fake the CrashReporterClient API */
+#define CRGetCrashLogMessage() 0
+#define CRSetCrashLogMessage(m) true
+
+#define CRASH_REPORTER_CLIENT_HIDDEN __attribute__((visibility("hidden")))
+#define CRASHREPORTER_ANNOTATIONS_VERSION 4
+#define CRASHREPORTER_ANNOTATIONS_SECTION "__crash_info"
+
+struct crashreporter_annotations_t {
+	uint64_t version;		// unsigned long
+	uint64_t message;		// char *
+	uint64_t signature_string;	// char *
+	uint64_t backtrace;		// char *
+	uint64_t message2;		// char *
+	uint64_t thread;		// uint64_t
+	uint64_t dialog_mode;		// unsigned int
+};
+
+#endif
diff --git a/pkgs/os-specific/darwin/apple-source-releases/Libc/default.nix b/pkgs/os-specific/darwin/apple-source-releases/Libc/default.nix
index 542ea20de11..6ebb470145d 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/Libc/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/Libc/default.nix
@@ -11,6 +11,8 @@ appleDerivation {
     export PRIVATE_HEADERS_FOLDER_PATH=include
     bash xcodescripts/headers.sh
 
+    cp ${./CrashReporterClient.h} $out/include/CrashReporterClient.h
+
     cp ${Libc_10-9}/include/NSSystemDirectories.h $out/include
 
     # Ugh Apple stopped releasing this stuff so we need an older one...
diff --git a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix
index 1e27ead69f1..7b19194be96 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix
@@ -1,9 +1,11 @@
-{ stdenv, appleDerivation, cpio, xnu, Libc, Libm, libdispatch, cctools, Libinfo,
-  dyld, Csu, architecture, libclosure, CarbonHeaders, ncurses, CommonCrypto, copyfile,
-  removefile, libresolv, Libnotify, libplatform, libpthread, mDNSResponder, launchd, libutil }:
+{ stdenv, appleDerivation, cpio, xnu, Libc, Libm, libdispatch, cctools, Libinfo
+, dyld, Csu, architecture, libclosure, CarbonHeaders, ncurses, CommonCrypto
+, copyfile, removefile, libresolv, Libnotify, libplatform, libpthread
+, mDNSResponder, launchd, libutil, hfs, darling }:
 
 appleDerivation rec {
-  phases = [ "unpackPhase" "installPhase" ];
+  dontBuild = true;
+  dontFixup = true;
 
   nativeBuildInputs = [ cpio ];
 
@@ -17,19 +19,48 @@ appleDerivation rec {
     cp ${xnu}/Library/Frameworks/Kernel.framework/Versions/A/Headers/Availability*.h $out/include
     cp ${xnu}/Library/Frameworks/Kernel.framework/Versions/A/Headers/stdarg.h        $out/include
 
-    for dep in ${Libc} ${Libm} ${Libinfo} ${dyld} ${architecture} ${libclosure} ${CarbonHeaders} \
-               ${libdispatch} ${ncurses.dev} ${CommonCrypto} ${copyfile} ${removefile} ${libresolv} \
-               ${Libnotify} ${libplatform} ${mDNSResponder} ${launchd} ${libutil} ${libpthread}; do
+    for dep in ${Libc} ${Libm} ${Libinfo} ${dyld} ${architecture} \
+               ${libclosure} ${CarbonHeaders} ${libdispatch} ${ncurses.dev} \
+               ${CommonCrypto} ${copyfile} ${removefile} ${libresolv} \
+               ${Libnotify} ${libplatform} ${mDNSResponder} ${launchd} \
+               ${libutil} ${libpthread} ${hfs}; do
       (cd $dep/include && find . -name '*.h' | cpio -pdm $out/include)
     done
 
-
     (cd ${cctools.dev}/include/mach-o && find . -name '*.h' | cpio -pdm $out/include/mach-o)
 
+    mkdir -p $out/include/os
+
+    cp ${darling.src}/src/libc/os/activity.h $out/include/os
+    cp ${darling.src}/src/libc/os/log.h $out/include/os
+    cp ${darling.src}/src/duct/include/os/trace.h $out/include/os
+
+    cat <<EOF > $out/include/os/availability.h
+    #ifndef __OS_AVAILABILITY__
+    #define __OS_AVAILABILITY__
+    #include <AvailabilityInternal.h>
+
+    #if defined(__has_feature) && defined(__has_attribute) && __has_attribute(availability)
+      #define API_AVAILABLE(...) __API_AVAILABLE_GET_MACRO(__VA_ARGS__, __API_AVAILABLE4, __API_AVAILABLE3, __API_AVAILABLE2, __API_AVAILABLE1)(__VA_ARGS__)
+      #define API_DEPRECATED(...) __API_DEPRECATED_MSG_GET_MACRO(__VA_ARGS__, __API_DEPRECATED_MSG5, __API_DEPRECATED_MSG4, __API_DEPRECATED_MSG3, __API_DEPRECATED_MSG2, __API_DEPRECATED_MSG1)(__VA_ARGS__)
+      #define API_DEPRECATED_WITH_REPLACEMENT(...) __API_DEPRECATED_REP_GET_MACRO(__VA_ARGS__, __API_DEPRECATED_REP5, __API_DEPRECATED_REP4, __API_DEPRECATED_REP3, __API_DEPRECATED_REP2, __API_DEPRECATED_REP1)(__VA_ARGS__)
+      #define API_UNAVAILABLE(...) __API_UNAVAILABLE_GET_MACRO(__VA_ARGS__, __API_UNAVAILABLE3, __API_UNAVAILABLE2, __API_UNAVAILABLE1)(__VA_ARGS__)
+    #else
+
+      #define API_AVAILABLE(...)
+      #define API_DEPRECATED(...)
+      #define API_DEPRECATED_WITH_REPLACEMENT(...)
+      #define API_UNAVAILABLE(...)
+
+    #endif
+    #endif
+    EOF
+
     cat <<EOF > $out/include/TargetConditionals.h
     #ifndef __TARGETCONDITIONALS__
     #define __TARGETCONDITIONALS__
     #define TARGET_OS_MAC           1
+    #define TARGET_OS_OSX           1
     #define TARGET_OS_WIN32         0
     #define TARGET_OS_UNIX          0
     #define TARGET_OS_EMBEDDED      0
diff --git a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/system_c_symbols b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/system_c_symbols
index 4d83c5cfe9b..1ec6c6332cf 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/system_c_symbols
+++ b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/system_c_symbols
@@ -232,6 +232,8 @@ __os_assert_log_ctx
 __os_assumes_log
 __os_assumes_log_ctx
 __os_avoid_tail_call
+__os_crash
+__os_crash_callback
 __os_debug_log
 __os_debug_log_error_str
 __putenvp
@@ -263,6 +265,7 @@ __unsetenvp
 __utmpxname
 _a64l
 _abort
+_abort_report_np
 _abs
 _acl_add_flag_np
 _acl_add_perm
@@ -345,6 +348,7 @@ _backtrace
 _backtrace_symbols
 _backtrace_symbols_fd
 _basename
+_basename_r
 _bcmp
 _bcopy
 _brk
@@ -377,8 +381,12 @@ _chmodx_np
 _clearerr
 _clearerr_unlocked
 _clock
+_clock_getres
+_clock_gettime
+_clock_gettime_nsec_np
 _clock_port
 _clock_sem
+_clock_settime
 _closedir
 _compat_mode
 _confstr
@@ -411,6 +419,7 @@ _digittoint
 _digittoint_l
 _dirfd
 _dirname
+_dirname_r
 _div
 _dprintf
 _dprintf_l
@@ -771,8 +780,12 @@ _mergesort_b
 _mkdirx_np
 _mkdtemp
 _mkfifox_np
+_mkostemp
+_mkostemps
 _mkpath_np
+_mkpathat_np
 _mkstemp
+_mkstemp_dprotected_np
 _mkstemps
 _mktemp
 _mktime
@@ -805,6 +818,7 @@ _nice
 _nl_langinfo
 _nl_langinfo_l
 _nrand48
+_nvis
 _off32
 _off64
 _offtime
@@ -959,6 +973,7 @@ _sleep
 _sleep$NOCANCEL
 _snprintf
 _snprintf_l
+_snvis
 _sockatmark
 _sprintf
 _sprintf_l
@@ -988,6 +1003,7 @@ _strcoll_l
 _strcpy
 _strcspn
 _strdup
+_strenvisx
 _strerror
 _strerror_r
 _strfmon
@@ -1006,14 +1022,23 @@ _strncpy
 _strndup
 _strnlen
 _strnstr
+_strnunvis
+_strnunvisx
+_strnvis
+_strnvisx
 _strpbrk
 _strptime
 _strptime_l
 _strrchr
+_strsenvisx
 _strsep
 _strsignal
+_strsnvis
+_strsnvisx
 _strspn
 _strstr
+_strsvis
+_strsvisx
 _strtod
 _strtod_l
 _strtof
@@ -1046,6 +1071,7 @@ _strvisx
 _strxfrm
 _strxfrm_l
 _suboptarg
+_svis
 _swab
 _swprintf
 _swprintf_l
@@ -1087,6 +1113,7 @@ _timelocal
 _timeoff
 _times
 _timezone
+_timingsafe_bcmp
 _tmpfile
 _tmpnam
 _toascii
diff --git a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/system_kernel_symbols b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/system_kernel_symbols
index 4d1a1f521b0..7c5b90f95ed 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/system_kernel_symbols
+++ b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/system_kernel_symbols
@@ -3,6 +3,7 @@ _____old_semwait_signal_nocancel
 _____sigwait_nocancel
 ____kernelVersionNumber
 ____kernelVersionString
+___abort_with_payload
 ___accept
 ___accept_nocancel
 ___access_extended
@@ -13,6 +14,11 @@ ___bsdthread_ctl
 ___bsdthread_register
 ___bsdthread_terminate
 ___carbon_delete
+___channel_get_info
+___channel_get_opt
+___channel_open
+___channel_set_opt
+___channel_sync
 ___chmod
 ___chmod_extended
 ___close_nocancel
@@ -32,6 +38,7 @@ ___fchmod_extended
 ___fcntl
 ___fcntl_nocancel
 ___fork
+___fs_snapshot
 ___fstat64_extended
 ___fstat_extended
 ___fsync_nocancel
@@ -57,6 +64,8 @@ ___ioctl
 ___iopolicysys
 ___kdebug_trace
 ___kdebug_trace64
+___kdebug_trace_string
+___kdebug_typefilter
 ___kill
 ___lchown
 ___libkernel_init
@@ -79,6 +88,7 @@ ___mac_set_file
 ___mac_set_link
 ___mac_set_proc
 ___mac_syscall
+___microstackshot
 ___mkdir_extended
 ___mkfifo_extended
 ___mmap
@@ -90,6 +100,13 @@ ___msgsys
 ___msync
 ___msync_nocancel
 ___munmap
+___nexus_create
+___nexus_deregister
+___nexus_destroy
+___nexus_get_opt
+___nexus_open
+___nexus_register
+___nexus_set_opt
 ___old_semwait_signal
 ___open
 ___open_dprotected_np
@@ -97,12 +114,17 @@ ___open_extended
 ___open_nocancel
 ___openat
 ___openat_nocancel
+___os_nexus_ifattach
+___os_nexus_ifdetach
+___persona
 ___pipe
 ___poll_nocancel
 ___posix_spawn
 ___pread_nocancel
 ___proc_info
 ___process_policy
+___pselect
+___pselect_nocancel
 ___psynch_cvbroad
 ___psynch_cvclrprepost
 ___psynch_cvsignal
@@ -133,6 +155,7 @@ ___recvmsg
 ___recvmsg_nocancel
 ___rename
 ___renameat
+___renameatx_np
 ___rmdir
 ___sandbox_me
 ___sandbox_mm
@@ -175,6 +198,7 @@ ___sigsuspend
 ___sigsuspend_nocancel
 ___sigwait
 ___socketpair
+___stack_snapshot_with_config
 ___stat64_extended
 ___stat_extended
 ___syscall
@@ -182,8 +206,11 @@ ___syscall_logger
 ___sysctl
 ___sysctlbyname
 ___telemetry
+___terminate_with_payload
 ___thread_selfid
 ___thread_selfusage
+___ulock_wait
+___ulock_wake
 ___umask_extended
 ___unlink
 ___unlinkat
@@ -191,6 +218,7 @@ ___vfork
 ___wait4
 ___wait4_nocancel
 ___waitid_nocancel
+___work_interval_ctl
 ___workq_kernreturn
 ___workq_open
 ___write_nocancel
@@ -202,6 +230,7 @@ __get_cpu_capabilities
 __getprivatesystemidentifier
 __host_page_size
 __init_cpu_capabilities
+__kernelrpc_host_create_mach_voucher
 __kernelrpc_mach_port_allocate
 __kernelrpc_mach_port_allocate_full
 __kernelrpc_mach_port_allocate_name
@@ -257,13 +286,17 @@ __kernelrpc_mach_vm_map
 __kernelrpc_mach_vm_map_trap
 __kernelrpc_mach_vm_protect
 __kernelrpc_mach_vm_protect_trap
+__kernelrpc_mach_vm_purgable_control
+__kernelrpc_mach_vm_purgable_control_trap
 __kernelrpc_mach_vm_read
 __kernelrpc_mach_vm_remap
+__kernelrpc_mach_voucher_extract_attr_recipe
 __kernelrpc_task_set_port_space
 __kernelrpc_thread_policy
 __kernelrpc_thread_policy_set
 __kernelrpc_thread_set_policy
 __kernelrpc_vm_map
+__kernelrpc_vm_purgable_control
 __kernelrpc_vm_read
 __kernelrpc_vm_remap
 __mach_errors
@@ -272,6 +305,9 @@ __mach_snprintf
 __mach_vsnprintf
 __os_alloc_once_table
 __register_gethostuuid_callback
+__thread_set_tsd_base
+_abort_with_payload
+_abort_with_reason
 _accept
 _accept$NOCANCEL
 _access
@@ -312,6 +348,8 @@ _clock_set_attributes
 _clock_set_time
 _clock_sleep
 _clock_sleep_trap
+_clonefile
+_clonefileat
 _close
 _close$NOCANCEL
 _coalition_create
@@ -345,6 +383,7 @@ _fchmod
 _fchmodat
 _fchown
 _fchownat
+_fclonefileat
 _fcntl
 _fcntl$NOCANCEL
 _fdatasync
@@ -358,9 +397,16 @@ _flistxattr
 _flock
 _fpathconf
 _fremovexattr
+_fs_snapshot_create
+_fs_snapshot_delete
+_fs_snapshot_list
+_fs_snapshot_mount
+_fs_snapshot_rename
+_fs_snapshot_revert
 _fsctl
 _fsetattrlist
 _fsetxattr
+_fsgetpath
 _fstat
 _fstat$INODE64
 _fstat64
@@ -384,6 +430,7 @@ _getdirentries
 _getdirentriesattr
 _getdtablesize
 _getegid
+_getentropy
 _geteuid
 _getfh
 _getfsstat
@@ -409,6 +456,7 @@ _getsockopt
 _getuid
 _getwgroups_np
 _getxattr
+_grab_pgo_data
 _guarded_close_np
 _guarded_kqueue_np
 _guarded_open_dprotected_np
@@ -416,14 +464,18 @@ _guarded_open_np
 _guarded_pwrite_np
 _guarded_write_np
 _guarded_writev_np
+_host_check_multiuser_mode
 _host_create_mach_voucher
+_host_create_mach_voucher_trap
 _host_default_memory_manager
 _host_get_UNDServer
+_host_get_atm_diagnostic_flag
 _host_get_boot_info
 _host_get_clock_control
 _host_get_clock_service
 _host_get_exception_ports
 _host_get_io_master
+_host_get_multiuser_config_flags
 _host_get_special_port
 _host_info
 _host_kernel_version
@@ -443,7 +495,9 @@ _host_security_set_task_token
 _host_self
 _host_self_trap
 _host_set_UNDServer
+_host_set_atm_diagnostic_flag
 _host_set_exception_ports
+_host_set_multiuser_config_flags
 _host_set_special_port
 _host_statistics
 _host_statistics64
@@ -456,15 +510,28 @@ _internal_catch_exc_subsystem
 _ioctl
 _issetugid
 _kas_info
+_kdebug_is_enabled
+_kdebug_signpost
+_kdebug_signpost_end
+_kdebug_signpost_start
 _kdebug_trace
+_kdebug_trace_string
+_kdebug_typefilter
 _kevent
 _kevent64
+_kevent_qos
 _kext_request
 _kill
 _kmod_control
 _kmod_create
 _kmod_destroy
 _kmod_get_info
+_kpersona_alloc
+_kpersona_dealloc
+_kpersona_find
+_kpersona_get
+_kpersona_info
+_kpersona_pidinfo
 _kqueue
 _lchown
 _ledger
@@ -487,14 +554,20 @@ _lstat$INODE64
 _lstat64
 _mach_absolute_time
 _mach_approximate_time
+_mach_boottime_usec
+_mach_continuous_approximate_time
+_mach_continuous_time
 _mach_error
 _mach_error_full_diag
 _mach_error_string
 _mach_error_type
+_mach_generate_activity_id
+_mach_get_times
 _mach_host_self
 _mach_init
 _mach_make_memory_entry
 _mach_make_memory_entry_64
+_mach_memory_info
 _mach_memory_object_memory_entry
 _mach_memory_object_memory_entry_64
 _mach_msg
@@ -554,6 +627,7 @@ _mach_task_self
 _mach_task_self_
 _mach_thread_self
 _mach_timebase_info
+_mach_timebase_info_trap
 _mach_vm_allocate
 _mach_vm_behavior_set
 _mach_vm_copy
@@ -580,6 +654,7 @@ _mach_voucher_debug_info
 _mach_voucher_extract_all_attr_recipes
 _mach_voucher_extract_attr_content
 _mach_voucher_extract_attr_recipe
+_mach_voucher_extract_attr_recipe_trap
 _mach_wait_until
 _mach_zone_force_gc
 _mach_zone_info
@@ -598,6 +673,7 @@ _mig_get_reply_port
 _mig_put_reply_port
 _mig_reply_setup
 _mig_strncpy
+_mig_strncpy_zerofill
 _mincore
 _minherit
 _mk_timer_arm
@@ -630,7 +706,10 @@ _msync$NOCANCEL
 _munlock
 _munlockall
 _munmap
+_necp_client_action
 _necp_match_policy
+_necp_open
+_netagent_trigger
 _netname_check_in
 _netname_check_out
 _netname_look_up
@@ -645,6 +724,44 @@ _open_dprotected_np
 _openat
 _openat$NOCANCEL
 _openbyid_np
+_os_channel_advance_slot
+_os_channel_attr_clone
+_os_channel_attr_create
+_os_channel_attr_destroy
+_os_channel_attr_get
+_os_channel_attr_get_key
+_os_channel_attr_set
+_os_channel_attr_set_key
+_os_channel_available_slot_count
+_os_channel_create
+_os_channel_create_extended
+_os_channel_destroy
+_os_channel_get_fd
+_os_channel_get_next_slot
+_os_channel_pending
+_os_channel_read_attr
+_os_channel_read_nexus_extension_info
+_os_channel_ring_id
+_os_channel_rx_ring
+_os_channel_set_slot_properties
+_os_channel_sync
+_os_channel_tx_ring
+_os_channel_write_attr
+_os_nexus_attr_clone
+_os_nexus_attr_create
+_os_nexus_attr_destroy
+_os_nexus_attr_get
+_os_nexus_attr_set
+_os_nexus_controller_alloc_provider_instance
+_os_nexus_controller_bind_provider_instance
+_os_nexus_controller_create
+_os_nexus_controller_deregister_provider
+_os_nexus_controller_destroy
+_os_nexus_controller_free_provider_instance
+_os_nexus_controller_get_fd
+_os_nexus_controller_read_provider_attr
+_os_nexus_controller_register_provider
+_os_nexus_controller_unbind_provider_instance
 _panic
 _panic_init
 _pathconf
@@ -669,6 +786,7 @@ _posix_spawn_file_actions_addopen
 _posix_spawn_file_actions_destroy
 _posix_spawn_file_actions_init
 _posix_spawnattr_destroy
+_posix_spawnattr_get_darwin_role_np
 _posix_spawnattr_get_qos_clamp_np
 _posix_spawnattr_getbinpref_np
 _posix_spawnattr_getcpumonitor
@@ -680,7 +798,12 @@ _posix_spawnattr_getprocesstype_np
 _posix_spawnattr_getsigdefault
 _posix_spawnattr_getsigmask
 _posix_spawnattr_init
+_posix_spawnattr_set_darwin_role_np
 _posix_spawnattr_set_importancewatch_port_np
+_posix_spawnattr_set_persona_gid_np
+_posix_spawnattr_set_persona_groups_np
+_posix_spawnattr_set_persona_np
+_posix_spawnattr_set_persona_uid_np
 _posix_spawnattr_set_qos_clamp_np
 _posix_spawnattr_setauditsessionport_np
 _posix_spawnattr_setbinpref_np
@@ -689,6 +812,7 @@ _posix_spawnattr_setcpumonitor
 _posix_spawnattr_setcpumonitor_default
 _posix_spawnattr_setexceptionports_np
 _posix_spawnattr_setflags
+_posix_spawnattr_setjetsam_ext
 _posix_spawnattr_setmacpolicyinfo_np
 _posix_spawnattr_setpcontrol_np
 _posix_spawnattr_setpgroup
@@ -698,6 +822,7 @@ _posix_spawnattr_setsigmask
 _posix_spawnattr_setspecialport_np
 _pread
 _pread$NOCANCEL
+_proc_clear_cpulimits
 _proc_clear_delayidlesleep
 _proc_clear_dirty
 _proc_clear_vmpressure
@@ -715,8 +840,10 @@ _proc_importance_assertion_begin_with_msg
 _proc_importance_assertion_complete
 _proc_kmsgbuf
 _proc_libversion
+_proc_list_uptrs
 _proc_listallpids
 _proc_listchildpids
+_proc_listcoalitions
 _proc_listpgrppids
 _proc_listpids
 _proc_listpidspath
@@ -728,6 +855,7 @@ _proc_pidinfo
 _proc_pidoriginatorinfo
 _proc_pidpath
 _proc_regionfilename
+_proc_resume_cpumon
 _proc_rlimit_control
 _proc_set_cpumon_defaults
 _proc_set_cpumon_params
@@ -737,6 +865,7 @@ _proc_set_dirty
 _proc_set_owner_vmpressure
 _proc_set_wakemon_defaults
 _proc_set_wakemon_params
+_proc_setcpu_percentage
 _proc_setpcontrol
 _proc_setthread_cpupercent
 _proc_suppress
@@ -790,6 +919,8 @@ _removexattr
 _rename
 _rename_ext
 _renameat
+_renameatx_np
+_renamex_np
 _revoke
 _rmdir
 _searchfs
@@ -876,6 +1007,16 @@ _sigsuspend$NOCANCEL
 _socket
 _socket_delegate
 _socketpair
+_stackshot_capture_with_config
+_stackshot_config_create
+_stackshot_config_dealloc
+_stackshot_config_dealloc_buffer
+_stackshot_config_get_stackshot_buffer
+_stackshot_config_get_stackshot_size
+_stackshot_config_set_delta_timestamp
+_stackshot_config_set_flags
+_stackshot_config_set_pid
+_stackshot_config_set_size_hint
 _stat
 _stat$INODE64
 _stat64
@@ -897,18 +1038,26 @@ _task_assign
 _task_assign_default
 _task_create
 _task_for_pid
+_task_generate_corpse
 _task_get_assignment
+_task_get_dyld_image_infos
 _task_get_emulation_vector
 _task_get_exception_ports
 _task_get_mach_voucher
 _task_get_special_port
 _task_get_state
 _task_info
+_task_map_corpse_info
+_task_map_corpse_info_64
 _task_name_for_pid
 _task_policy
 _task_policy_get
 _task_policy_set
 _task_purgable_info
+_task_register_dyld_get_process_state
+_task_register_dyld_image_infos
+_task_register_dyld_set_dyld_state
+_task_register_dyld_shared_cache_image_info
 _task_resume
 _task_resume2
 _task_sample
@@ -931,7 +1080,10 @@ _task_swap_exception_ports
 _task_swap_mach_voucher
 _task_terminate
 _task_threads
+_task_unregister_dyld_image_infos
 _task_zone_info
+_terminate_with_payload
+_terminate_with_reason
 _thread_abort
 _thread_abort_safely
 _thread_assign
@@ -942,6 +1094,7 @@ _thread_depress_abort
 _thread_get_assignment
 _thread_get_exception_ports
 _thread_get_mach_voucher
+_thread_get_register_pointer_values
 _thread_get_special_port
 _thread_get_state
 _thread_info
@@ -968,6 +1121,7 @@ _undelete
 _unlink
 _unlinkat
 _unmount
+_usrctl
 _utimes
 _vfork
 _vfs_purge
@@ -1008,6 +1162,10 @@ _waitevent
 _waitid
 _waitid$NOCANCEL
 _watchevent
+_work_interval_create
+_work_interval_destroy
+_work_interval_notify
+_work_interval_notify_simple
 _write
 _write$NOCANCEL
 _writev
diff --git a/pkgs/os-specific/darwin/apple-source-releases/Security/boot.nix b/pkgs/os-specific/darwin/apple-source-releases/Security/boot.nix
new file mode 100644
index 00000000000..e04142b8b11
--- /dev/null
+++ b/pkgs/os-specific/darwin/apple-source-releases/Security/boot.nix
@@ -0,0 +1,116 @@
+{ appleDerivation }:
+
+appleDerivation {
+  phases = [ "unpackPhase" "installPhase" ];
+
+  __propagatedImpureHostDeps = [
+    "/System/Library/Frameworks/Security.framework/Security"
+    "/System/Library/Frameworks/Security.framework/Resources"
+    "/System/Library/Frameworks/Security.framework/PlugIns"
+    "/System/Library/Frameworks/Security.framework/XPCServices"
+    "/System/Library/Frameworks/Security.framework/Versions"
+  ];
+
+  installPhase = ''
+    ###### IMPURITIES
+    mkdir -p $out/Library/Frameworks/Security.framework
+    pushd $out/Library/Frameworks/Security.framework
+    ln -s /System/Library/Frameworks/Security.framework/Security
+    ln -s /System/Library/Frameworks/Security.framework/Resources
+    ln -s /System/Library/Frameworks/Security.framework/PlugIns
+    ln -s /System/Library/Frameworks/Security.framework/XPCServices
+    popd
+
+    ###### HEADERS
+
+    export dest=$out/Library/Frameworks/Security.framework/Headers
+    mkdir -p $dest
+
+    cp libsecurity_asn1/lib/SecAsn1Coder.h     $dest
+    cp libsecurity_asn1/lib/SecAsn1Templates.h $dest
+    cp libsecurity_asn1/lib/SecAsn1Types.h     $dest
+    cp libsecurity_asn1/lib/oidsalg.h          $dest
+    cp libsecurity_asn1/lib/oidsattr.h         $dest
+
+    cp libsecurity_authorization/lib/AuthSession.h         $dest
+    cp libsecurity_authorization/lib/Authorization.h       $dest
+    cp libsecurity_authorization/lib/AuthorizationDB.h     $dest
+    cp libsecurity_authorization/lib/AuthorizationPlugin.h $dest
+    cp libsecurity_authorization/lib/AuthorizationTags.h   $dest
+
+    cp libsecurity_cms/lib/CMSDecoder.h $dest
+    cp libsecurity_cms/lib/CMSEncoder.h $dest
+
+    cp libsecurity_codesigning/lib/CSCommon.h       $dest
+    cp libsecurity_codesigning/lib/CodeSigning.h    $dest
+    cp libsecurity_codesigning/lib/SecCode.h        $dest
+    cp libsecurity_codesigning/lib/SecCodeHost.h    $dest
+    cp libsecurity_codesigning/lib/SecRequirement.h $dest
+    cp libsecurity_codesigning/lib/SecStaticCode.h  $dest
+    cp libsecurity_codesigning/lib/SecTask.h        $dest
+
+    cp libsecurity_cssm/lib/certextensions.h $dest
+    cp libsecurity_cssm/lib/cssm.h           $dest
+    cp libsecurity_cssm/lib/cssmaci.h        $dest
+    cp libsecurity_cssm/lib/cssmapi.h        $dest
+    cp libsecurity_cssm/lib/cssmapple.h      $dest
+    cp libsecurity_cssm/lib/cssmcli.h        $dest
+    cp libsecurity_cssm/lib/cssmconfig.h     $dest
+    cp libsecurity_cssm/lib/cssmcspi.h       $dest
+    cp libsecurity_cssm/lib/cssmdli.h        $dest
+    cp libsecurity_cssm/lib/cssmerr.h        $dest
+    cp libsecurity_cssm/lib/cssmkrapi.h      $dest
+    cp libsecurity_cssm/lib/cssmkrspi.h      $dest
+    cp libsecurity_cssm/lib/cssmspi.h        $dest
+    cp libsecurity_cssm/lib/cssmtpi.h        $dest
+    cp libsecurity_cssm/lib/cssmtype.h       $dest
+    cp libsecurity_cssm/lib/eisl.h           $dest
+    cp libsecurity_cssm/lib/emmspi.h         $dest
+    cp libsecurity_cssm/lib/emmtype.h        $dest
+    cp libsecurity_cssm/lib/oidsbase.h       $dest
+    cp libsecurity_cssm/lib/oidscert.h       $dest
+    cp libsecurity_cssm/lib/oidscrl.h        $dest
+    cp libsecurity_cssm/lib/x509defs.h       $dest
+
+    cp libsecurity_keychain/lib/SecACL.h                $dest
+    cp libsecurity_keychain/lib/SecAccess.h             $dest
+    cp libsecurity_keychain/lib/SecBase.h               $dest
+    cp libsecurity_keychain/lib/SecCertificate.h        $dest
+    cp libsecurity_keychain/lib/SecCertificatePriv.h    $dest # Private
+    cp libsecurity_keychain/lib/SecCertificateOIDs.h    $dest
+    cp libsecurity_keychain/lib/SecIdentity.h           $dest
+    cp libsecurity_keychain/lib/SecIdentitySearch.h     $dest
+    cp libsecurity_keychain/lib/SecImportExport.h       $dest
+    cp libsecurity_keychain/lib/SecItem.h               $dest
+    cp libsecurity_keychain/lib/SecKey.h                $dest
+    cp libsecurity_keychain/lib/SecKeychain.h           $dest
+    cp libsecurity_keychain/lib/SecKeychainItem.h       $dest
+    cp libsecurity_keychain/lib/SecKeychainSearch.h     $dest
+    cp libsecurity_keychain/lib/SecPolicy.h             $dest
+    cp libsecurity_keychain/lib/SecPolicySearch.h       $dest
+    cp libsecurity_keychain/lib/SecRandom.h             $dest
+    cp libsecurity_keychain/lib/SecTrust.h              $dest
+    cp libsecurity_keychain/lib/SecTrustSettings.h      $dest
+    cp libsecurity_keychain/lib/SecTrustedApplication.h $dest
+    cp libsecurity_keychain/lib/Security.h              $dest
+
+    cp libsecurity_manifest/lib/SecureDownload.h $dest
+
+    cp libsecurity_mds/lib/mds.h        $dest
+    cp libsecurity_mds/lib/mds_schema.h $dest
+
+    cp libsecurity_ssl/lib/CipherSuite.h     $dest
+    cp libsecurity_ssl/lib/SecureTransport.h $dest
+
+    cp libsecurity_transform/lib/SecCustomTransform.h        $dest
+    cp libsecurity_transform/lib/SecDecodeTransform.h        $dest
+    cp libsecurity_transform/lib/SecDigestTransform.h        $dest
+    cp libsecurity_transform/lib/SecEncodeTransform.h        $dest
+    cp libsecurity_transform/lib/SecEncryptTransform.h       $dest
+    cp libsecurity_transform/lib/SecReadTransform.h          $dest
+    cp libsecurity_transform/lib/SecSignVerifyTransform.h    $dest
+    cp libsecurity_transform/lib/SecTransform.h              $dest
+    cp libsecurity_transform/lib/SecTransformReadTransform.h $dest
+
+  '';
+}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/Security/default.nix b/pkgs/os-specific/darwin/apple-source-releases/Security/default.nix
index e04142b8b11..be744fa8873 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/Security/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/Security/default.nix
@@ -1,116 +1,19 @@
-{ appleDerivation }:
+{ stdenv, appleDerivation, xcbuildHook, Foundation, xpc, darling, dtrace, xnu }:
 
 appleDerivation {
-  phases = [ "unpackPhase" "installPhase" ];
+  nativeBuildInputs = [ xcbuildHook dtrace ];
+  # buildInputs = [ Foundation xpc darling ];
+  buildInputs = [ xpc xnu ];
 
-  __propagatedImpureHostDeps = [
-    "/System/Library/Frameworks/Security.framework/Security"
-    "/System/Library/Frameworks/Security.framework/Resources"
-    "/System/Library/Frameworks/Security.framework/PlugIns"
-    "/System/Library/Frameworks/Security.framework/XPCServices"
-    "/System/Library/Frameworks/Security.framework/Versions"
-  ];
+  xcbuildFlags = "-target Security_frameworks_osx";
 
-  installPhase = ''
-    ###### IMPURITIES
-    mkdir -p $out/Library/Frameworks/Security.framework
-    pushd $out/Library/Frameworks/Security.framework
-    ln -s /System/Library/Frameworks/Security.framework/Security
-    ln -s /System/Library/Frameworks/Security.framework/Resources
-    ln -s /System/Library/Frameworks/Security.framework/PlugIns
-    ln -s /System/Library/Frameworks/Security.framework/XPCServices
-    popd
+  # NIX_CFLAGS_COMPILE = "-Wno-error -I${xnu}/include/libkern -DPRIVATE -I${xnu}/Library/Frameworks/System.framework/Headers";
 
-    ###### HEADERS
-
-    export dest=$out/Library/Frameworks/Security.framework/Headers
-    mkdir -p $dest
-
-    cp libsecurity_asn1/lib/SecAsn1Coder.h     $dest
-    cp libsecurity_asn1/lib/SecAsn1Templates.h $dest
-    cp libsecurity_asn1/lib/SecAsn1Types.h     $dest
-    cp libsecurity_asn1/lib/oidsalg.h          $dest
-    cp libsecurity_asn1/lib/oidsattr.h         $dest
-
-    cp libsecurity_authorization/lib/AuthSession.h         $dest
-    cp libsecurity_authorization/lib/Authorization.h       $dest
-    cp libsecurity_authorization/lib/AuthorizationDB.h     $dest
-    cp libsecurity_authorization/lib/AuthorizationPlugin.h $dest
-    cp libsecurity_authorization/lib/AuthorizationTags.h   $dest
-
-    cp libsecurity_cms/lib/CMSDecoder.h $dest
-    cp libsecurity_cms/lib/CMSEncoder.h $dest
-
-    cp libsecurity_codesigning/lib/CSCommon.h       $dest
-    cp libsecurity_codesigning/lib/CodeSigning.h    $dest
-    cp libsecurity_codesigning/lib/SecCode.h        $dest
-    cp libsecurity_codesigning/lib/SecCodeHost.h    $dest
-    cp libsecurity_codesigning/lib/SecRequirement.h $dest
-    cp libsecurity_codesigning/lib/SecStaticCode.h  $dest
-    cp libsecurity_codesigning/lib/SecTask.h        $dest
-
-    cp libsecurity_cssm/lib/certextensions.h $dest
-    cp libsecurity_cssm/lib/cssm.h           $dest
-    cp libsecurity_cssm/lib/cssmaci.h        $dest
-    cp libsecurity_cssm/lib/cssmapi.h        $dest
-    cp libsecurity_cssm/lib/cssmapple.h      $dest
-    cp libsecurity_cssm/lib/cssmcli.h        $dest
-    cp libsecurity_cssm/lib/cssmconfig.h     $dest
-    cp libsecurity_cssm/lib/cssmcspi.h       $dest
-    cp libsecurity_cssm/lib/cssmdli.h        $dest
-    cp libsecurity_cssm/lib/cssmerr.h        $dest
-    cp libsecurity_cssm/lib/cssmkrapi.h      $dest
-    cp libsecurity_cssm/lib/cssmkrspi.h      $dest
-    cp libsecurity_cssm/lib/cssmspi.h        $dest
-    cp libsecurity_cssm/lib/cssmtpi.h        $dest
-    cp libsecurity_cssm/lib/cssmtype.h       $dest
-    cp libsecurity_cssm/lib/eisl.h           $dest
-    cp libsecurity_cssm/lib/emmspi.h         $dest
-    cp libsecurity_cssm/lib/emmtype.h        $dest
-    cp libsecurity_cssm/lib/oidsbase.h       $dest
-    cp libsecurity_cssm/lib/oidscert.h       $dest
-    cp libsecurity_cssm/lib/oidscrl.h        $dest
-    cp libsecurity_cssm/lib/x509defs.h       $dest
-
-    cp libsecurity_keychain/lib/SecACL.h                $dest
-    cp libsecurity_keychain/lib/SecAccess.h             $dest
-    cp libsecurity_keychain/lib/SecBase.h               $dest
-    cp libsecurity_keychain/lib/SecCertificate.h        $dest
-    cp libsecurity_keychain/lib/SecCertificatePriv.h    $dest # Private
-    cp libsecurity_keychain/lib/SecCertificateOIDs.h    $dest
-    cp libsecurity_keychain/lib/SecIdentity.h           $dest
-    cp libsecurity_keychain/lib/SecIdentitySearch.h     $dest
-    cp libsecurity_keychain/lib/SecImportExport.h       $dest
-    cp libsecurity_keychain/lib/SecItem.h               $dest
-    cp libsecurity_keychain/lib/SecKey.h                $dest
-    cp libsecurity_keychain/lib/SecKeychain.h           $dest
-    cp libsecurity_keychain/lib/SecKeychainItem.h       $dest
-    cp libsecurity_keychain/lib/SecKeychainSearch.h     $dest
-    cp libsecurity_keychain/lib/SecPolicy.h             $dest
-    cp libsecurity_keychain/lib/SecPolicySearch.h       $dest
-    cp libsecurity_keychain/lib/SecRandom.h             $dest
-    cp libsecurity_keychain/lib/SecTrust.h              $dest
-    cp libsecurity_keychain/lib/SecTrustSettings.h      $dest
-    cp libsecurity_keychain/lib/SecTrustedApplication.h $dest
-    cp libsecurity_keychain/lib/Security.h              $dest
-
-    cp libsecurity_manifest/lib/SecureDownload.h $dest
-
-    cp libsecurity_mds/lib/mds.h        $dest
-    cp libsecurity_mds/lib/mds_schema.h $dest
-
-    cp libsecurity_ssl/lib/CipherSuite.h     $dest
-    cp libsecurity_ssl/lib/SecureTransport.h $dest
-
-    cp libsecurity_transform/lib/SecCustomTransform.h        $dest
-    cp libsecurity_transform/lib/SecDecodeTransform.h        $dest
-    cp libsecurity_transform/lib/SecDigestTransform.h        $dest
-    cp libsecurity_transform/lib/SecEncodeTransform.h        $dest
-    cp libsecurity_transform/lib/SecEncryptTransform.h       $dest
-    cp libsecurity_transform/lib/SecReadTransform.h          $dest
-    cp libsecurity_transform/lib/SecSignVerifyTransform.h    $dest
-    cp libsecurity_transform/lib/SecTransform.h              $dest
-    cp libsecurity_transform/lib/SecTransformReadTransform.h $dest
+  preBuild = ''
+    dtrace -h -C -s OSX/libsecurity_utilities/lib/security_utilities.d -o OSX/libsecurity_utilities/lib/utilities_dtrace.h
 
+    xcodebuild SYMROOT=$PWD/Products OBJROOT=$PWD/Intermediates -target copyHeadersToSystem
+    NIX_CFLAGS_COMPILE+=" -F./Products/Release"
+    ln -s $PWD/Products/Release/Security.bundle/Contents $PWD/Products/Release/Security.framework
   '';
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/SmartCardServices/default.nix b/pkgs/os-specific/darwin/apple-source-releases/SmartCardServices/default.nix
deleted file mode 100644
index 6e900335078..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/SmartCardServices/default.nix
+++ /dev/null
@@ -1,42 +0,0 @@
-{ stdenv, appleDerivation, xcbuildHook, gnumake, Security
-, libsecurity_utilities, libsecurity_cdsa_utilities }:
-
-appleDerivation {
-  nativeBuildInputs = [ xcbuildHook ];
-  buildInputs = [ libsecurity_utilities libsecurity_cdsa_utilities ];
-
-  DSTROOT = "$out";
-
-  NIX_CFLAGS_COMPILE = "-I.";
-  preBuild = ''
-    mkdir -p Security
-    cp ${Security}/Library/Frameworks/Security.framework/Headers/*.h Security
-  '';
-
-  patchPhase = ''
-    substituteInPlace SmartCardServices.xcodeproj/project.pbxproj \
-      --replace "/usr/bin/gnumake" "${gnumake}/bin/make"
-    substituteInPlace src/PCSC/PCSC.exp \
-      --replace _PCSCVersionString "" \
-      --replace _PCSCVersionNumber ""
-    substituteInPlace Makefile.installPhase \
-      --replace chown "# chown" \
-      --replace /usr/bin/ ""
-  '';
-
-  installPhase = ''
-    make -f Makefile.installPhase install
-    make -f Makefile-exec.installPhase install
-    mv $out/usr/* $out
-    rmdir $out/usr
-
-    mkdir -p $out/Library/Frameworks
-    cp -r Products/Release/PCSC.bundle $out/Library/Frameworks/PCSC.framework
-  '';
-
-  meta = with stdenv.lib; {
-    maintainers = with maintainers; [ matthewbauer ];
-    platforms   = platforms.darwin;
-    license     = licenses.apsl20;
-  };
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/boot.nix b/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/boot.nix
new file mode 100644
index 00000000000..318e2728fc2
--- /dev/null
+++ b/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/boot.nix
@@ -0,0 +1,91 @@
+{ stdenv, appleDerivation, fetchzip, bsdmake, perl, flex, yacc
+}:
+
+# this derivation sucks
+# locale data was removed after adv_cmds-118, so our base is that because it's easier than
+# replicating the bizarre bsdmake file structure
+#
+# sadly adv_cmds-118 builds a mklocale and colldef that generate files that our libc can no
+# longer understand
+#
+# the more recent adv_cmds release is used for everything else in this package
+
+let recentAdvCmds = fetchzip {
+  url = "http://opensource.apple.com/tarballs/adv_cmds/adv_cmds-158.tar.gz";
+  sha256 = "0z081kcprzg5jcvqivfnwvvv6wfxzkjg2jc2lagsf8c7j7vgm8nn";
+};
+
+in appleDerivation {
+  nativeBuildInputs = [ bsdmake perl yacc flex ];
+  buildInputs = [ flex ];
+
+  patchPhase = ''
+    substituteInPlace BSDmakefile \
+      --replace chgrp true \
+      --replace /Developer/Makefiles/bin/compress-man-pages.pl true \
+      --replace "ps.tproj" "" --replace "gencat.tproj" "" --replace "md.tproj" "" \
+      --replace "tabs.tproj" "" --replace "cap_mkdb.tproj" "" \
+      --replace "!= tconf --test TARGET_OS_EMBEDDED" "= NO"
+
+    substituteInPlace Makefile --replace perl true
+
+    for subproject in colldef mklocale monetdef msgdef numericdef timedef; do
+      substituteInPlace usr-share-locale.tproj/$subproject/BSDmakefile \
+        --replace /usr/share/locale "" \
+        --replace '-o ''${BINOWN} -g ''${BINGRP}' "" \
+        --replace "rsync -a" "cp -r"
+    done
+  '';
+
+  preBuild = ''
+    cp -r --no-preserve=all ${recentAdvCmds}/colldef .
+    pushd colldef
+    mv locale/collate.h .
+    flex -t -8 -i scan.l > scan.c
+    yacc -d parse.y
+    clang *.c -o colldef -lfl
+    popd
+    mv colldef/colldef colldef.tproj/colldef
+
+    cp -r --no-preserve=all ${recentAdvCmds}/mklocale .
+    pushd mklocale
+    flex -t -8 -i lex.l > lex.c
+    yacc -d yacc.y
+    clang *.c -o mklocale -lfl
+    popd
+    mv mklocale/mklocale mklocale.tproj/mklocale
+  '';
+
+  buildPhase = ''
+    runHook preBuild
+
+    bsdmake -C usr-share-locale.tproj
+
+    clang ${recentAdvCmds}/ps/*.c -o ps
+  '';
+
+  installPhase = ''
+    bsdmake -C usr-share-locale.tproj install DESTDIR="$locale/share/locale"
+
+    # need to get rid of runtime dependency on flex
+    # install -d 0755 $locale/bin
+    # install -m 0755 colldef.tproj/colldef $locale/bin
+    # install -m 0755 mklocale.tproj/mklocale $locale/bin
+
+    install -d 0755 $ps/bin
+    install ps $ps/bin/ps
+    touch "$out"
+  '';
+
+  outputs = [
+    "out"
+    "ps"
+    "locale"
+  ];
+  setOutputFlags = false;
+
+  meta = {
+    platforms = stdenv.lib.platforms.darwin;
+    maintainers = with stdenv.lib.maintainers; [ gridaphobe ];
+  };
+}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/default.nix
index 1d8ebac74b0..0cbd7d81b90 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/default.nix
@@ -1,69 +1,36 @@
-{ stdenv, appleDerivation, fetchzip, bsdmake, perl, flex, yacc
-}:
+{ stdenv, appleDerivation, xcbuild, ncurses, libutil }:
 
-# this derivation sucks
-# locale data was removed after adv_cmds-118, so our base is that because it's easier than
-# replicating the bizarre bsdmake file structure
-#
-# sadly adv_cmds-118 builds a mklocale and colldef that generate files that our libc can no
-# longer understand
-#
-# the more recent adv_cmds release is used for everything else in this package
+appleDerivation {
+  # We can't just run the root build, because https://github.com/facebook/xcbuild/issues/264
 
-let recentAdvCmds = fetchzip {
-  url = "https://opensource.apple.com/tarballs/adv_cmds/adv_cmds-158.tar.gz";
-  sha256 = "0z081kcprzg5jcvqivfnwvvv6wfxzkjg2jc2lagsf8c7j7vgm8nn";
-};
-
-in appleDerivation {
-  nativeBuildInputs = [ bsdmake perl yacc flex ];
-  buildInputs = [ flex ];
+  # pkill requires special private headers that are unavailable in
+  # NixPkgs. These ones are needed:
+  #  - xpc/xpxc.h
+  #  - os/base_private.h
+  #  - _simple.h
+  # We disable it here for now. TODO: build pkill inside adv_cmds
 
+  # We also disable locale here because of some issues with a missing
+  # "lstdc++".
   patchPhase = ''
-    substituteInPlace BSDmakefile \
-      --replace chgrp true \
-      --replace /Developer/Makefiles/bin/compress-man-pages.pl true \
-      --replace "ps.tproj" "" --replace "gencat.tproj" "" --replace "md.tproj" "" \
-      --replace "tabs.tproj" "" --replace "cap_mkdb.tproj" "" \
-      --replace "!= tconf --test TARGET_OS_EMBEDDED" "= NO"
-
-    substituteInPlace Makefile --replace perl true
-
-    for subproject in colldef mklocale monetdef msgdef numericdef timedef; do
-      substituteInPlace usr-share-locale.tproj/$subproject/BSDmakefile \
-        --replace /usr/share/locale "" \
-        --replace '-o ''${BINOWN} -g ''${BINGRP}' "" \
-        --replace "rsync -a" "cp -r"
-    done
-  '';
-
-  preBuild = ''
-    cp -r --no-preserve=all ${recentAdvCmds}/colldef .
-    pushd colldef
-    mv locale/collate.h .
-    flex -t -8 -i scan.l > scan.c
-    yacc -d parse.y
-    clang *.c -o colldef -lfl
-    popd
-    mv colldef/colldef colldef.tproj/colldef
-
-    cp -r --no-preserve=all ${recentAdvCmds}/mklocale .
-    pushd mklocale
-    flex -t -8 -i lex.l > lex.c
-    yacc -d yacc.y
-    clang *.c -o mklocale -lfl
-    popd
-    mv mklocale/mklocale mklocale.tproj/mklocale
+    substituteInPlace adv_cmds.xcodeproj/project.pbxproj \
+      --replace "FD201DC214369B4200906237 /* pkill.c in Sources */," "" \
+      --replace "FDF278D60FC6204E00D7A3C6 /* locale.cc in Sources */," "" \
+      --replace '/usr/lib/libtermcap.dylib' 'libncurses.dylib'
   '';
 
   buildPhase = ''
-    runHook preBuild
-
-    bsdmake -C usr-share-locale.tproj
+    targets=$(xcodebuild -list \
+                | awk '/Targets:/{p=1;print;next} p&&/^\s*$/{p=0};p' \
+                | tail -n +2 | sed 's/^[ \t]*//' \
+                | grep -v -e Desktop -e Embedded -e mklocale -e colldef)
 
-    clang ${recentAdvCmds}/ps/*.c -o ps
+    for i in $targets; do
+      xcodebuild SYMROOT=$PWD/Products OBJROOT=$PWD/Intermediates -target $i
+    done
   '';
 
+  # temporary install phase until xcodebuild has "install" support
   installPhase = ''
     for f in Products/Release/*; do
       if [ -f $f ]; then
@@ -71,27 +38,19 @@ in appleDerivation {
       fi
     done
 
-    bsdmake -C usr-share-locale.tproj install DESTDIR="$locale/share/locale"
-
-    # need to get rid of runtime dependency on flex
-    # install -d 0755 $locale/bin
-    # install -m 0755 colldef.tproj/colldef $locale/bin
-    # install -m 0755 mklocale.tproj/mklocale $locale/bin
+    mkdir -p $out/System/Library/LaunchDaemons
+    install fingerd/finger.plist $out/System/Library/LaunchDaemons
 
-    install -d 0755 $ps/bin
-    install ps $ps/bin/ps
-    touch "$out"
+    # from variant_links.sh
+    # ln -s $out/bin/pkill $out/bin/pgrep
+    # ln -s $out/share/man/man1/pkill.1 $out/share/man/man1/pgrep.1
   '';
 
-  outputs = [
-    "out"
-    "ps"
-    "locale"
-  ];
-  setOutputFlags = false;
+  nativeBuildInputs = [ xcbuild ];
+  buildInputs = [ ncurses libutil ];
 
   meta = {
     platforms = stdenv.lib.platforms.darwin;
-    maintainers = with stdenv.lib.maintainers; [ gridaphobe ];
+    maintainers = with stdenv.lib.maintainers; [ matthewbauer ];
   };
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/xcode.nix b/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/xcode.nix
deleted file mode 100644
index 45912041a24..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/xcode.nix
+++ /dev/null
@@ -1,59 +0,0 @@
-{ stdenv, appleDerivation, xcbuild, ncurses, libutil-new }:
-
-appleDerivation {
-  # We can't just run the root build, because https://github.com/facebook/xcbuild/issues/264
-
-  # pkill requires special private headers that are unavailable in
-  # NixPkgs. These ones are needed:
-  #  - xpc/xpxc.h
-  #  - os/base_private.h
-  #  - _simple.h
-  # We disable it here for now. TODO: build pkill inside adv_cmds
-
-  # We also disable locale here because of some issues with a missing
-  # "lstdc++".
-  patchPhase = ''
-    substituteInPlace adv_cmds.xcodeproj/project.pbxproj \
-      --replace "FD201DC214369B4200906237 /* pkill.c in Sources */," "" \
-      --replace "FDF278D60FC6204E00D7A3C6 /* locale.cc in Sources */," "" \
-      --replace '/usr/lib/libtermcap.dylib' 'libncurses.dylib' \
-      --replace 'DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";' ""
-  '';
-
-  buildPhase = ''
-    targets=$(xcodebuild -list \
-                | awk '/Targets:/{p=1;print;next} p&&/^\s*$/{p=0};p' \
-                | tail -n +2 | sed 's/^[ \t]*//' \
-                | grep -v -e Desktop -e Embedded -e mklocale -e colldef)
-
-    for i in $targets; do
-      xcodebuild SYMROOT=$PWD/Products OBJROOT=$PWD/Intermediates -target $i
-    done
-  '';
-
-  # temporary install phase until xcodebuild has "install" support
-  installPhase = ''
-    mkdir -p $out/bin/
-    install Products/Release/* $out/bin/
-
-    for n in 1 8; do
-      mkdir -p $out/share/man/man$n
-      install */*.$n $out/share/man/man$n
-    done
-
-    mkdir -p $out/System/Library/LaunchDaemons
-    install fingerd/finger.plist $out/System/Library/LaunchDaemons
-
-    # from variant_links.sh
-    # ln -s $out/bin/pkill $out/bin/pgrep
-    # ln -s $out/share/man/man1/pkill.1 $out/share/man/man1/pgrep.1
-  '';
-
-  nativeBuildInputs = [ xcbuild ];
-  buildInputs = [ ncurses libutil-new ];
-
-  meta = {
-    platforms = stdenv.lib.platforms.darwin;
-    maintainers = with stdenv.lib.maintainers; [ matthewbauer ];
-  };
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/bootstrap_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/bootstrap_cmds/default.nix
index 591e7bd5230..256781f61b1 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/bootstrap_cmds/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/bootstrap_cmds/default.nix
@@ -32,6 +32,7 @@ appleDerivation {
     chmod +x mig.sh
     cp mig.sh   $out/bin/mig
     cp migcom   $out/libexec
+    ln -s $out/libexec/migcom $out/bin/migcom
     cp mig.1    $out/share/man/man1
     cp migcom.1 $out/share/man/man1
 
diff --git a/pkgs/os-specific/darwin/apple-source-releases/default.nix b/pkgs/os-specific/darwin/apple-source-releases/default.nix
index c9473bca06d..d5094e1f91e 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/default.nix
@@ -6,9 +6,31 @@ let
   # a stdenv out of something like this. With some care we can probably get rid of this, but for
   # now it's staying here.
   versions = {
+    "osx-10.12.6" = {
+      xnu           = "3789.70.16";
+      libiconv      = "50";
+      Libnotify     = "165.20.1";
+      objc4         = "709.1";
+      dyld          = "433.5";
+      CommonCrypto  = "60092.50.5";
+      copyfile      = "138";
+      ppp           = "838.50.1";
+      libclosure    = "67";
+      Libinfo       = "503.50.4";
+      Libsystem     = "1238.60.2";
+      removefile    = "45";
+      libresolv     = "64";
+      libplatform   = "126.50.8";
+      mDNSResponder = "765.50.9";
+      libutil       = "47.30.1";
+      libunwind     = "35.3";
+      Libc          = "1158.50.2";
+      dtrace        = "209.50.12";
+      libpthread    = "218.60.3";
+      hfs           = "366.70.1";
+    };
     "osx-10.11.6" = {
       PowerManagement = "572.50.1";
-      SmartCardServices = "55111";
       dtrace        = "168";
       xnu           = "3248.60.10";
       libpthread    = "138.10.4";
@@ -58,7 +80,6 @@ let
       ICU           = "531.48";
       libdispatch   = "442.1.4";
       Security      = "57031.40.6";
-      security_systemkeychain = "55202";
 
       IOAudioFamily                        = "203.3";
       IOFireWireFamily                     = "458";
@@ -94,28 +115,6 @@ let
     "osx-10.8.4" = {
       IOUSBFamily = "560.4.2";
     };
-    "osx-10.7.5" = {
-      libsecurity_apple_csp      = "55003";
-      libsecurity_apple_cspdl    = "55000";
-      libsecurity_apple_file_dl  = "55000";
-      libsecurity_apple_x509_cl  = "55004";
-      libsecurity_apple_x509_tp  = "55009.3";
-      libsecurity_asn1           = "55000.2";
-      libsecurity_cdsa_client    = "55000";
-      libsecurity_cdsa_plugin    = "55001";
-      libsecurity_cdsa_utilities = "55006";
-      libsecurity_cdsa_utils     = "55000";
-      libsecurity_codesigning    = "55037.15";
-      libsecurity_cssm           = "55005.5";
-      libsecurity_filedb         = "55016.1";
-      libsecurity_keychain       = "55050.9";
-      libsecurity_mds            = "55000";
-      libsecurity_ocspd          = "55010";
-      libsecurity_pkcs12         = "55000";
-      libsecurity_sd_cspdl       = "55003";
-      libsecurity_utilities      = "55030.3";
-      libsecurityd               = "55004";
-    };
     "osx-10.7.4" = {
       Libm = "2026";
     };
@@ -166,10 +165,6 @@ let
       callPackage = pkgs.newScope (packages // pkgs.darwin // { inherit appleDerivation name version; });
     in callPackage (./. + "/${namePath}");
 
-  libsecPackage = pkgs.callPackage ./libsecurity_generic {
-    inherit applePackage appleDerivation_;
-  };
-
   IOKitSpecs = {
     IOAudioFamily                        = fetchApple "osx-10.10.5" "0ggq7za3iq8g02j16rj67prqhrw828jsw3ah3bxq8a1cvr55aqnq";
     IOFireWireFamily                     = fetchApple "osx-10.10.5" "059qa1m668kwvchl90cqcx35b31zaqdg61zi11y1imn5s389y2g1";
@@ -194,60 +189,58 @@ let
 
   IOKitSrcs = stdenv.lib.mapAttrs (name: value: if stdenv.lib.isFunction value then value name else value) IOKitSpecs;
 
-  adv_cmds = applePackage "adv_cmds" "osx-10.5.8" "102ssayxbg9wb35mdmhswbnw0bg7js3pfd8fcbic83c5q3bqa6c6" {};
+  # Only used for bootstrapping. It’s convenient because it was the last version to come with a real makefile.
+  adv_cmds-boot = applePackage "adv_cmds/boot.nix" "osx-10.5.8" "102ssayxbg9wb35mdmhswbnw0bg7js3pfd8fcbic83c5q3bqa6c6" {};
 
   packages = {
-    SmartCardServices = applePackage "SmartCardServices" "osx-10.11.6" "1qqjlbi6j37mw9p3qpfnwf14xh9ff8h5786bmvzwc4kblfglabkm" {};
-
-    inherit (adv_cmds) ps locale;
+    inherit (adv_cmds-boot) ps locale;
     architecture    = applePackage "architecture"      "osx-10.11.6"     "1pbpjcd7is69hn8y29i98ci0byik826if8gnp824ha92h90w0fq3" {};
     bootstrap_cmds  = applePackage "bootstrap_cmds"    "dev-tools-7.0"   "1v5dv2q3af1xwj5kz0a5g54fd5dm6j4c9dd2g66n4kc44ixyrhp3" {};
     bsdmake         = applePackage "bsdmake"           "dev-tools-3.2.6" "11a9kkhz5bfgi1i8kpdkis78lhc6b5vxmhd598fcdgra1jw4iac2" {};
     CarbonHeaders   = applePackage "CarbonHeaders"     "osx-10.6.2"      "1zam29847cxr6y9rnl76zqmkbac53nx0szmqm9w5p469a6wzjqar" {};
-    CommonCrypto    = applePackage "CommonCrypto"      "osx-10.11.6"     "0vllfpb8f4f97wj2vpdd7w5k9ibnsbr6ff1zslpp6q323h01n25y" {};
-    configd         = applePackage "configd"           "osx-10.8.5"      "1gxakahk8gallf16xmhxhprdxkh3prrmzxnmxfvj0slr0939mmr2" {};
-    copyfile        = applePackage "copyfile"          "osx-10.11.6"     "1rkf3iaxmjz5ycgrmf0g971kh90jb2z1zqxg5vlqz001s4y457gs" {};
+    CommonCrypto    = applePackage "CommonCrypto"      "osx-10.12.6"     "0sgsqjcxbdm2g2zfpc50mzmk4b4ldyw7xvvkwiayhpczg1fga4ff" {};
+    configd         = applePackage "configd"           "osx-10.8.5"      "1gxakahk8gallf16xmhxhprdxkh3prrmzxnmxfvj0slr0939mmr2" {
+      Security      = applePackage "Security/boot.nix" "osx-10.9.5"      "1nv0dczf67dhk17hscx52izgdcyacgyy12ag0jh6nl5hmfzsn8yy" {};
+    };
+    copyfile        = applePackage "copyfile"          "osx-10.12.6"     "0a70bvzndkava1a946cdq42lnjhg7i7b5alpii3lap6r5fkvas0n" {};
     Csu             = applePackage "Csu"               "osx-10.11.6"     "0yh5mslyx28xzpv8qww14infkylvc1ssi57imhi471fs91sisagj" {};
-    dtrace          = applePackage "dtrace"            "osx-10.11.6"     "04mi0jy8gy0w59rk9i9dqznysv6fzz1v5mq779s41cp308yi0h1c" {};
-    dtrace-xcode    = applePackage "dtrace/xcode.nix"  "osx-10.11.6"     "04mi0jy8gy0w59rk9i9dqznysv6fzz1v5mq779s41cp308yi0h1c" {};
-    dyld            = applePackage "dyld"              "osx-10.11.6"     "0qkjmjazm2zpgvwqizhandybr9cm3gz9pckx8rmf0py03faafc08" {};
+    dtrace          = applePackage "dtrace"            "osx-10.12.6"     "0hpd6348av463yqf70n3xkygwmf1i5zza8kps4zys52sviqz3a0l" {};
+    dyld            = applePackage "dyld"              "osx-10.12.6"     "0q4jmk78b5ajn33blh4agyq6v2a63lpb3fln78az0dy12bnp1qqk" {};
     eap8021x        = applePackage "eap8021x"          "osx-10.11.6"     "0iw0qdib59hihyx2275rwq507bq2a06gaj8db4a8z1rkaj1frskh" {};
-
-    # Splicing is currently broken in Nixpkgs
-    # cctools need to be specified manually here to handle this
     ICU             = applePackage "ICU"               "osx-10.10.5"     "1qihlp42n5g4dl0sn0f9pc0bkxy1452dxzf0vr6y5gqpshlzy03p" {};
-
     IOKit           = applePackage "IOKit"             "osx-10.11.6"     "0kcbrlyxcyirvg5p95hjd9k8a01k161zg0bsfgfhkb90kh2s8x00" { inherit IOKitSrcs; };
     launchd         = applePackage "launchd"           "osx-10.9.5"      "0w30hvwqq8j5n90s3qyp0fccxflvrmmjnicjri4i1vd2g196jdgj" {};
     libauto         = applePackage "libauto"           "osx-10.9.5"      "17z27yq5d7zfkwr49r7f0vn9pxvj95884sd2k6lq6rfaz9gxqhy3" {};
-    Libc            = applePackage "Libc"              "osx-10.11.5"     "1qv7r0dgz06jy9i5agbqzxgdibb0m8ylki6g5n5pary88lzrawfd" {
+    Libc            = applePackage "Libc"              "osx-10.12.6"     "183wcy1nlj2wkpfsx3k3lyv917mk8r2p72qw8lb89mbjsw3yw0xx" {
       Libc_10-9 = fetchzip {
         url    = "http://www.opensource.apple.com/tarballs/Libc/Libc-997.90.3.tar.gz";
         sha256 = "1xchgxkxg5288r2b9yfrqji2gsgdap92k4wx2dbjwslixws12pq7";
       };
+      Libc_old        = applePackage "Libc/825_40_1.nix" "osx-10.8.5"      "0xsx1im52gwlmcrv4lnhhhn9dyk5ci6g27k6yvibn9vj8fzjxwcf" {};
     };
-    Libc_old        = applePackage "Libc/825_40_1.nix" "osx-10.8.5"      "0xsx1im52gwlmcrv4lnhhhn9dyk5ci6g27k6yvibn9vj8fzjxwcf" {};
     libclosure      = applePackage "libclosure"        "osx-10.11.6"     "1zqy1zvra46cmqv6vsf1mcsz3a76r9bky145phfwh4ab6y15vjpq" {};
     libdispatch     = applePackage "libdispatch"       "osx-10.10.5"     "0jsfbzp87lwk9snlby0hd4zvj7j894p5q3cw0wdx9ny1mcp3kdcj" {};
-    libiconv        = applePackage "libiconv"          "osx-10.11.6"     "11h6lfajydri4widis62q8scyz7z8l6msqyx40ly4ahsdlbl0981" {};
+    libiconv        = applePackage "libiconv"          "osx-10.12.6"     "1gg5h6z8sk851bhv87vyxzs54jmqz6lh57ny8j4s51j7srja0nly" {};
     Libinfo         = applePackage "Libinfo"           "osx-10.11.6"     "0qjgkd4y8sjvwjzv5wwyzkb61pg8wwg95bkp721dgzv119dqhr8x" {};
     Libm            = applePackage "Libm"              "osx-10.7.4"      "02sd82ig2jvvyyfschmb4gpz6psnizri8sh6i982v341x6y4ysl7" {};
-    Libnotify       = applePackage "Libnotify"         "osx-10.11.6"     "0zbcyxlcfhf91jxczhd5bq9qfgvg494gwwp3l7q5ayb2qdihzr8b" {};
-    libplatform     = applePackage "libplatform"       "osx-10.11.6"     "1v4ik6vlklwsi0xb1g5kmhy29j9xk5m2y8xb9zbi1k4ng8x39czk" {};
-    libpthread      = applePackage "libpthread"        "osx-10.11.6"     "1kbw738cmr9pa7pz1igmajs307clfq7gv2vm1sqdzhcnnjxbl28w" {};
-    libresolv       = applePackage "libresolv"         "osx-10.11.6"     "09flfdi3dlzq0yap32sxidacpc4nn4va7z12a6viip21ix2xb2gf" {};
-    Libsystem       = applePackage "Libsystem"         "osx-10.11.6"     "1nfkmbqml587v2s1d1y2s2v8nmr577jvk51y6vqrfvsrhdhc2w94" {};
-    libutil         = applePackage "libutil"           "osx-10.11.6"     "1gmgmcyqdyc684ih7dimdmxdljnq7mzjy5iqbf589wc0pa8h5abm" {};
-    libutil-new     = applePackage "libutil/new.nix"   "osx-10.11.6"     "1gmgmcyqdyc684ih7dimdmxdljnq7mzjy5iqbf589wc0pa8h5abm" {};
-    libunwind       = applePackage "libunwind"         "osx-10.11.6"     "0miffaa41cv0lzf8az5k1j1ng8jvqvxcr4qrlkf3xyj479arbk1b" {};
-    mDNSResponder   = applePackage "mDNSResponder"     "osx-10.11.6"     "069incq28a78yh1bnr17h9cd5if5mwqpq8ahnkyxxx25fkaxgzcf" {};
-    objc4           = applePackage "objc4"             "osx-10.11.6"     "00b7vbgxni8frrqyi69b4njjihlwydzjd9zj9x4z5dbx8jabkvrj" {};
-    ppp             = applePackage "ppp"               "osx-10.11.6"     "1dql6r1v0vbcs04958nn2i6p31yfsxyy51jca63bm5mf0gxalk3f" {};
-    removefile      = applePackage "removefile"        "osx-10.11.6"     "1b6r74ry3k01kypvlaclf33fha15pcm0kzx9zrymlg66wg0s0i3r" {};
-    Security        = applePackage "Security"          "osx-10.9.5"      "1nv0dczf67dhk17hscx52izgdcyacgyy12ag0jh6nl5hmfzsn8yy" {};
-    xnu             = applePackage "xnu"               "osx-10.11.6"     "0yhziq4dqqcbjpf6vyqn8xhwva2zb525gndkx8cp8alzwp76jnr9" {};
+    Libnotify       = applePackage "Libnotify"         "osx-10.12.6"     "0p5qhvalf6j1w6n8xwywhn6dvbpzv74q5wqrgs8rwfpf74wg6s9z" {};
+    libplatform     = applePackage "libplatform"       "osx-10.12.6"     "0rh1f5ybvwz8s0nwfar8s0fh7jbgwqcy903cv2x8m15iq1x599yn" {};
+    libpthread      = applePackage "libpthread"        "osx-10.12.6"     "1j6541rcgjpas1fc77ip5krjgw4bvz6jq7bq7h9q7axb0jv2ns6c" {};
+    libresolv       = applePackage "libresolv"         "osx-10.12.6"     "077j6ljfh7amqpk2146rr7dsz5vasvr3als830mgv5jzl7l6vz88" {};
+    Libsystem       = applePackage "Libsystem"         "osx-10.12.6"     "1082ircc1ggaq3wha218vmfa75jqdaqidsy1bmrc4ckfkbr3bwx2" {
+      libutil = pkgs.darwin.libutil.override { headersOnly = true; };
+      hfs = pkgs.darwin.hfs.override { headersOnly = true; };
+    };
+    libutil         = applePackage "libutil"           "osx-10.12.6"     "0lqdxaj82h8yjbjm856jjz9k2d96k0viimi881akfng08xk1246y" {};
+    libunwind       = applePackage "libunwind"         "osx-10.12.6"     "0miffaa41cv0lzf8az5k1j1ng8jvqvxcr4qrlkf3xyj479arbk1b" {};
+    mDNSResponder   = applePackage "mDNSResponder"     "osx-10.12.6"     "02ms1p8zlgmprzn65jzr7yaqxykh3zxjcrw0c06aayim6h0dsqfy" {};
+    objc4           = applePackage "objc4"             "osx-10.12.6"     "1cj1vhbcs9pkmag2ms8wslagicnq9bxi2qjkszmp3ys7z7ccrbwz" {};
+    ppp             = applePackage "ppp"               "osx-10.12.6"     "1kcc2nc4x1kf8sz0a23i6nfpvxg381kipi0qdisrp8x9z2gbkxb8" {};
+    removefile      = applePackage "removefile"        "osx-10.12.6"     "0jzjxbmxgjzhssqd50z7kq9dlwrv5fsdshh57c0f8mdwcs19bsyx" {};
+    xnu             = applePackage "xnu"               "osx-10.12.6"     "1sjb0i7qzz840v2h4z3s4jyjisad4r5yyi6sg8pakv3wd81i5fg5" {};
+    hfs             = applePackage "hfs"               "osx-10.12.6"     "1mj3xvqpq1mgd80b6kl1s04knqnap7hccr0gz8rjphalq14rbl5g" {};
     Librpcsvc       = applePackage "Librpcsvc"         "osx-10.11.6"     "1zwfwcl9irxl1dlnf2b4v30vdybp0p0r6n6g1pd14zbdci1jcg2k" {};
-    adv_cmds        = applePackage "adv_cmds/xcode.nix" "osx-10.11.6"    "12gbv35i09aij9g90p6b3x2f3ramw43qcb2gjrg8lzkzmwvcyw9q" {};
+    adv_cmds        = applePackage "adv_cmds"          "osx-10.11.6"    "12gbv35i09aij9g90p6b3x2f3ramw43qcb2gjrg8lzkzmwvcyw9q" {};
     basic_cmds      = applePackage "basic_cmds"        "osx-10.11.6"     "0hvab4b1v5q2x134hdkal0rmz5gsdqyki1vb0dbw4py1bqf0yaw9" {};
     developer_cmds  = applePackage "developer_cmds"    "osx-10.11.6"     "1r9c2b6dcl22diqf90x58psvz797d3lxh4r2wppr7lldgbgn24di" {};
     diskdev_cmds    = applePackage "diskdev_cmds"      "osx-10.11.6"     "1ssdyiaq5m1zfy96yy38yyknp682ki6bvabdqd5z18fa0rv3m2ar" {};
@@ -259,28 +252,8 @@ let
     top             = applePackage "top"               "osx-10.11.6"     "0i9120rfwapgwdvjbfg0ya143i29s1m8zbddsxh39pdc59xnsg5l" {};
     PowerManagement = applePackage "PowerManagement"   "osx-10.11.6"     "1llimhvp0gjffd47322lnjq7cqwinx0c5z7ikli04ad5srpa68mh" {};
 
-    security_systemkeychain = applePackage "security_systemkeychain" "osx-10.10.5" "0xviskdgxsail15npi0billyiysvljlmg38mmhnr7qi4ymnnjr90" {};
-
-    libsecurity_apple_csp      = libsecPackage "libsecurity_apple_csp"      "osx-10.7.5" "1ngyn1ik27n4x981px3kfd1z1n8zx7r5w812b6qfjpy5nw4h746w" {};
-    libsecurity_apple_cspdl    = libsecPackage "libsecurity_apple_cspdl"    "osx-10.7.5" "1svqa5fhw7p7njzf8bzg7zgc5776aqjhdbnlhpwmr5hmz5i0x8r7" {};
-    libsecurity_apple_file_dl  = libsecPackage "libsecurity_apple_file_dl"  "osx-10.7.5" "1dfqani3n135i3iqmafc1k9awmz6s0a78zifhk15rx5a8ps870bl" {};
-    libsecurity_apple_x509_cl  = libsecPackage "libsecurity_apple_x509_cl"  "osx-10.7.5" "1gji2i080560s08k1nigsla1zdmi6slyv97xaj5vqxjpxb0g1xf5" {};
-    libsecurity_apple_x509_tp  = libsecPackage "libsecurity_apple_x509_tp"  "osx-10.7.5" "1bsms3nvi62wbvjviwjhjhzhylad8g6vmvlj3ngd0wyd0ywxrs46" {};
-    libsecurity_asn1           = libsecPackage "libsecurity_asn1"           "osx-10.7.5" "0i8aakjxdfj0lqcgqmbip32g7r4h57xhs8w0sxfvfl45q22s782w" {};
-    libsecurity_cdsa_client    = libsecPackage "libsecurity_cdsa_client"    "osx-10.7.5" "127jxnypkycy8zqwicfv333h11318m00gd37jnswbrpg44xd1wdy" {};
-    libsecurity_cdsa_plugin    = libsecPackage "libsecurity_cdsa_plugin"    "osx-10.7.5" "0ifmx85rs51i7zjm015s8kc2dqyrlvbr39lw9xzxgd2ds33i4lfj" {};
-    libsecurity_cdsa_utilities = libsecPackage "libsecurity_cdsa_utilities" "osx-10.7.5" "1kzsl0prvfa8a0m3j3pcxq06aix1csgayd3lzx27iqg84c8mhzan" {};
-    libsecurity_cdsa_utils     = libsecPackage "libsecurity_cdsa_utils"     "osx-10.7.5" "0q55jizav6n0lkj7lcmcr2mjdhnbnnn525fa9ipwgvzbspihw0g6" {};
-    libsecurity_codesigning    = libsecPackage "libsecurity_codesigning"    "osx-10.7.5" "0vf5nj2g383b4hknlp51qll5pm8z4qbf56dnc16n3wm8gj82iasy" {};
-    libsecurity_cssm           = libsecPackage "libsecurity_cssm"           "osx-10.7.5" "0l6ia533bhr8kqp2wa712bnzzzisif3kbn7h3bzzf4nps4wmwzn4" {};
-    libsecurity_filedb         = libsecPackage "libsecurity_filedb"         "osx-10.7.5" "1r0ik95xapdl6l2lhd079vpq41jjgshz2hqb8490gpy5wyc49cxb" {};
-    libsecurity_keychain       = libsecPackage "libsecurity_keychain"       "osx-10.7.5" "15wf2slcgyns61kk7jndgm9h22vidyphh9x15x8viyprra9bkhja" {};
-    libsecurity_mds            = libsecPackage "libsecurity_mds"            "osx-10.7.5" "0vin5hnzvkx2rdzaaj2gxmx38amxlyh6j24a8gc22y09d74p5lzs" {};
-    libsecurity_ocspd          = libsecPackage "libsecurity_ocspd"          "osx-10.7.5" "1bxzpihc6w0ji4x8810a4lfkq83787yhjl60xm24bv1prhqcm73b" {};
-    libsecurity_pkcs12         = libsecPackage "libsecurity_pkcs12"         "osx-10.7.5" "1yq8p2sp39q40fxshb256b7jn9lvmpymgpm8yz9kqrf980xddgsg" {};
-    libsecurity_sd_cspdl       = libsecPackage "libsecurity_sd_cspdl"       "osx-10.7.5" "10v76xycfnvz1n0zqfbwn3yh4w880lbssqhkn23iim3ihxgm5pbd" {};
-    libsecurity_utilities      = libsecPackage "libsecurity_utilities"      "osx-10.7.5" "0ayycfy9jm0n0c7ih9f3m69ynh8hs80v8yicq47aa1h9wclbxg8r" {};
-    libsecurityd               = libsecPackage "libsecurityd"               "osx-10.7.5" "1ywm2qj8l7rhaxy5biwxsyavd0d09d4bzchm03nlvwl313p2747x" {};
-    security_dotmac_tp         = libsecPackage "security_dotmac_tp"         "osx-10.9.5" "1l4fi9qhrghj0pkvywi8da22bh06c5bv3l40a621b5g258na50pl" {};
+    # TODO(matthewbauer):
+    # To be removed, once I figure out how to build a newer Security version.
+    Security      = applePackage "Security/boot.nix" "osx-10.9.5"      "1nv0dczf67dhk17hscx52izgdcyacgyy12ag0jh6nl5hmfzsn8yy" {};
   };
 in packages
diff --git a/pkgs/os-specific/darwin/apple-source-releases/diskdev_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/diskdev_cmds/default.nix
index 08c7a883502..6d3bd103811 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/diskdev_cmds/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/diskdev_cmds/default.nix
@@ -1,9 +1,9 @@
 { stdenv, appleDerivation, xcbuildHook
-, Libc, xnu, libutil-new }:
+, Libc, xnu, libutil }:
 
 appleDerivation {
   nativeBuildInputs = [ xcbuildHook ];
-  buildInputs = [ libutil-new ];
+  buildInputs = [ libutil ];
 
   NIX_CFLAGS_COMPILE = "-I.";
   NIX_LDFLAGS = "-lutil";
diff --git a/pkgs/os-specific/darwin/apple-source-releases/dtrace/default.nix b/pkgs/os-specific/darwin/apple-source-releases/dtrace/default.nix
index fd2c95563b4..8706d22be19 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/dtrace/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/dtrace/default.nix
@@ -1,50 +1,53 @@
-{ appleDerivation, cctools, zlib }:
+{ appleDerivation, xcbuildHook, CoreSymbolication
+, xnu, bison, flex, darling, stdenv, fixDarwinDylibNames }:
 
 appleDerivation {
-  buildInputs = [ cctools zlib ];
-
-  buildPhase = ''
-    export CFLAGS=" -I$PWD/head -I$PWD/sys -I$PWD/libelf -I$PWD/libdwarf"
-
-    pushd libelf
-    for f in *.c; do
-      if [ "$f" != "lintsup.c" ]; then # Apple doesn't use it, so I don't either
-        cc -D_INT64_TYPE -D_LONGLONG_TYPE -D_ILP32 $CFLAGS -c $f
-      fi
-    done
-    libtool -static -o libelf.a *.o
-    popd
+  nativeBuildInputs = [ xcbuildHook flex bison fixDarwinDylibNames ];
+  buildInputs = [ CoreSymbolication darling xnu ];
+  NIX_CFLAGS_COMPILE = "-DCTF_OLD_VERSIONS -DPRIVATE -DYYDEBUG=1 -I${xnu}/Library/Frameworks/System.framework/Headers -Wno-error=implicit-function-declaration";
+  NIX_LDFLAGS = "-L./Products/Release";
+  xcbuildFlags = "-target dtrace_frameworks -target dtrace";
+
+  doCheck = false;
+  checkPhase = "xcodebuild -target dtrace_tests";
+
+  postPatch = ''
+    substituteInPlace dtrace.xcodeproj/project.pbxproj \
+      --replace "/usr/sbin" ""
+    substituteInPlace libdtrace/dt_open.c \
+      --replace /usr/bin/clang ${stdenv.cc.cc}/bin/clang \
+      --replace /usr/bin/ld ${stdenv.cc.bintools.bintools}/bin/ld \
+      --replace /usr/lib/dtrace/dt_cpp.h $out/include/dt_cpp.h \
+      --replace /usr/lib/dtrace $out/lib/dtrace
+  '';
 
-    pushd libdwarf
-    ./configure CFLAGS="$CFLAGS -Icmplrs"
-    make
+  # hack to handle xcbuild's broken lex handling
+  preBuild = ''
+    pushd libdtrace
+    yacc -d dt_grammar.y
+    flex -l -d dt_lex.l
     popd
 
-    cp libelf/libelf.a     tools/ctfconvert
-    cp libdwarf/libdwarf.a tools/ctfconvert
+    substituteInPlace dtrace.xcodeproj/project.pbxproj \
+      --replace '6EBC9800099BFBBF0001019C /* dt_grammar.y */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.yacc; name = dt_grammar.y; path = libdtrace/dt_grammar.y; sourceTree = "<group>"; };' '6EBC9800099BFBBF0001019C /* y.tab.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = y.tab.c; path = libdtrace/y.tab.c; sourceTree = "<group>"; };' \
+      --replace '6EBC9808099BFBBF0001019C /* dt_lex.l */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.lex; name = dt_lex.l; path = libdtrace/dt_lex.l; sourceTree = "<group>"; };' '6EBC9808099BFBBF0001019C /* lex.yy.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lex.yy.c; path = libdtrace/lex.yy.c; sourceTree = "<group>"; };'
+  '';
+
+  # xcbuild doesn't support install
+  installPhase = ''
+    mkdir -p $out
 
-    pushd tools/ctfconvert
-    for f in ../../darwin_shim.c *.c; do
-      cc -DNDEBUG -DNS_BLOCK_ASSERTIONS $CFLAGS -c $f
-    done
+    cp -r Products/Release/usr/include $out/include
+    cp scripts/dt_cpp.h $out/include/dt_cpp.h
 
-    export COMMON="alist.o ctf.o darwin_shim.o hash.o iidesc.o input.o list.o \
-      memory.o output.o stack.o strtab.o symbol.o tdata.o traverse.o util.o"
+    mkdir $out/lib
+    cp Products/Release/*.dylib $out/lib
 
-    export CONVERT="ctfconvert.o dwarf.o merge.o st_bugs.o st_parse.o stabs.o"
-    export MERGE="barrier.o ctfmerge.o dwarf.o fifo.o merge.o st_bugs.o st_parse.o stabs.o utils.o"
-    export DUMP="dump.o fifo.o utils.o"
+    mkdir $out/bin
+    cp Products/Release/dtrace $out/bin
 
-    clang -o ctfconvert $CONVERT $COMMON -L. -lz -lelf -ldwarf
-    clang -o ctfmerge   $MERGE   $COMMON -L. -lz -lelf -ldwarf
-    clang -o ctfdump    $DUMP    $COMMON -L. -lz -lelf
-    popd
-  '';
+    mkdir -p $out/lib/dtrace
 
-  installPhase = ''
-    mkdir -p $out/bin
-    cp tools/ctfconvert/ctfconvert $out/bin
-    cp tools/ctfconvert/ctfmerge   $out/bin
-    cp tools/ctfconvert/ctfdump    $out/bin
+    install_name_tool -change $PWD/Products/Release/libdtrace.dylib $out/lib/libdtrace.dylib $out/bin/dtrace
   '';
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/dtrace/xcode.nix b/pkgs/os-specific/darwin/apple-source-releases/dtrace/xcode.nix
deleted file mode 100644
index f8636403ed5..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/dtrace/xcode.nix
+++ /dev/null
@@ -1,47 +0,0 @@
-{ appleDerivation, xcbuildHook, CoreSymbolication
-, xnu, bison, flex, darling, stdenv }:
-
-appleDerivation {
-  nativeBuildInputs = [ xcbuildHook flex bison ];
-  buildInputs = [ CoreSymbolication darling ];
-  NIX_CFLAGS_COMPILE = "-DCTF_OLD_VERSIONS -DPRIVATE -DYYDEBUG=1 -I${xnu}/Library/Frameworks/System.framework/Headers";
-  NIX_LDFLAGS = "-L./Products/Release";
-  xcbuildFlags = "-target dtrace";
-
-  patchPhase = ''
-    substituteInPlace dtrace.xcodeproj/project.pbxproj --replace "/usr/sbin" ""
-    substituteInPlace libdtrace/dt_open.c \
-      --replace "/usr/bin/clang" "${stdenv.cc}/bin/cpp" \
-      --replace "/usr/bin/ld" "${stdenv.cc}/bin/ld" \
-      --replace "/usr/bin/dtrace" $out/lib/dtrace
-  '';
-
-  # hack to handle xcbuild's broken lex handling
-  preBuild = ''
-    cd libdtrace
-    yacc -d dt_grammar.y
-    flex -l -d dt_lex.l
-    cd ..
-
-    substituteInPlace dtrace.xcodeproj/project.pbxproj \
-      --replace '6EBC9800099BFBBF0001019C /* dt_grammar.y */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.yacc; name = dt_grammar.y; path = libdtrace/dt_grammar.y; sourceTree = "<group>"; };' '6EBC9800099BFBBF0001019C /* y.tab.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = y.tab.c; path = libdtrace/y.tab.c; sourceTree = "<group>"; };' \
-      --replace '6EBC9808099BFBBF0001019C /* dt_lex.l */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.lex; name = dt_lex.l; path = libdtrace/dt_lex.l; sourceTree = "<group>"; };' '6EBC9808099BFBBF0001019C /* lex.yy.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lex.yy.c; path = libdtrace/lex.yy.c; sourceTree = "<group>"; };'
-  '';
-
-  # xcbuild doesn't support install
-  installPhase = ''
-    mkdir -p $out
-
-    cp -r Products/Release/usr $out
-    mv $out/usr/* $out
-    rmdir $out/usr
-
-    mkdir $out/lib
-    cp Products/Release/*.dylib $out/lib
-
-    mkdir $out/bin
-    cp Products/Release/dtrace $out/bin
-
-    mkdir -p $out/lib/dtrace
-  '';
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/file_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/file_cmds/default.nix
index 2f5e4f542d7..f0394a20c2c 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/file_cmds/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/file_cmds/default.nix
@@ -1,8 +1,8 @@
-{ stdenv, appleDerivation, xcbuildHook, zlib, bzip2, lzma, ncurses, libutil-new }:
+{ stdenv, appleDerivation, xcbuildHook, zlib, bzip2, lzma, ncurses, libutil }:
 
 appleDerivation rec {
   nativeBuildInputs = [ xcbuildHook ];
-  buildInputs = [ zlib bzip2 lzma ncurses libutil-new ];
+  buildInputs = [ zlib bzip2 lzma ncurses libutil ];
 
   # some commands not working:
   # mtree: _simple.h not found
diff --git a/pkgs/os-specific/darwin/apple-source-releases/hfs/default.nix b/pkgs/os-specific/darwin/apple-source-releases/hfs/default.nix
new file mode 100644
index 00000000000..ab294b143d3
--- /dev/null
+++ b/pkgs/os-specific/darwin/apple-source-releases/hfs/default.nix
@@ -0,0 +1,8 @@
+{ appleDerivation, lib, headersOnly ? false }:
+
+appleDerivation {
+  installPhase = lib.optionalString headersOnly ''
+    mkdir -p $out/include/hfs
+    cp core/*.h $out/include/hfs
+  '';
+}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_csp/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_csp/GNUmakefile
deleted file mode 100644
index ca263228fde..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_csp/GNUmakefile
+++ /dev/null
@@ -1,11 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_apple_csp
-
-security_apple_csp_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_apple_csp_HEADER_FILES_DIR = lib
-
-security_apple_csp_CC_FILES = $(wildcard lib/*.cpp)
-security_apple_csp_C_FILES = $(wildcard lib/*.c)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_csp/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_csp/default.nix
deleted file mode 100644
index 639d377d1b6..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_csp/default.nix
+++ /dev/null
@@ -1,31 +0,0 @@
-{ appleDerivation, apple_sdk, libsecurity_asn1, libsecurity_cdsa_plugin, libsecurity_cdsa_utilities, libsecurity_cdsa_utils, libsecurity_utilities, CommonCrypto, stdenv }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_cdsa_utilities
-    libsecurity_utilities
-    libsecurity_cdsa_plugin
-    libsecurity_asn1
-    libsecurity_cdsa_utils
-  ];
-  NIX_CFLAGS_COMPILE = "-Iopen_ssl";
-  patchPhase = ''
-    for file in lib/BlockCryptor.h lib/RSA_DSA_signature.h lib/castContext.h \
-      lib/RawSigner.h lib/MD2Object.h lib/HMACSHA1.h lib/bfContext.h lib/rc4Context.h; do
-      substituteInPlace ''$file --replace \
-        '"CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h"' \
-        '"${stdenv.lib.getDev apple_sdk.sdk}/include/MacTypes.h"'
-    done
-
-    for file in lib/castContext.h lib/gladmanContext.h lib/desContext.h lib/rc4Context.h; do
-      substituteInPlace ''$file --replace \
-        '/usr/local/include/CommonCrypto/CommonCryptorSPI.h' \
-        '${CommonCrypto}/include/CommonCrypto/CommonCryptorSPI.h'
-    done
-    
-    substituteInPlace lib/opensshWrap.cpp --replace RSA_DSA_Keys.h RSA_DSA_keys.h
-  '' + stdenv.lib.optionalString (!stdenv.cc.nativeLibc) ''
-    substituteInPlace lib/pbkdf2.c --replace \
-      '<CoreServices/../Frameworks/CarbonCore.framework/Headers/ConditionalMacros.h>' \
-      '"${stdenv.libc}/include/ConditionalMacros.h"'
-  '';
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_cspdl/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_cspdl/GNUmakefile
deleted file mode 100644
index a0d48cf4965..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_cspdl/GNUmakefile
+++ /dev/null
@@ -1,10 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_apple_cspdl
-
-security_apple_cspdl_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_apple_cspdl_HEADER_FILES_DIR = lib
-
-security_apple_cspdl_CC_FILES = $(wildcard lib/*.cpp)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_cspdl/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_cspdl/default.nix
deleted file mode 100644
index b80d4c8aad2..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_cspdl/default.nix
+++ /dev/null
@@ -1,16 +0,0 @@
-{ appleDerivation, libsecurity_cdsa_client, libsecurity_cdsa_plugin, libsecurity_cdsa_utilities, libsecurity_keychain, libsecurity_utilities, libsecurityd }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_cdsa_plugin
-    libsecurity_cdsa_utilities
-    libsecurity_utilities
-    libsecurityd
-    libsecurity_cdsa_client
-    libsecurity_keychain
-  ];
-  patchPhase = ''
-    for file in lib/*; do
-      sed -i 's/#include <\(.*\)>/#include "\1"/' ''$file
-    done
-  '';
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_file_dl/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_file_dl/GNUmakefile
deleted file mode 100644
index f52829c644d..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_file_dl/GNUmakefile
+++ /dev/null
@@ -1,10 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_apple_file_dl
-
-security_apple_file_dl_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_apple_file_dl_HEADER_FILES_DIR = lib
-
-security_apple_file_dl_CC_FILES = $(wildcard lib/*.cpp)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_file_dl/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_file_dl/default.nix
deleted file mode 100644
index 0eb2ee10fd8..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_file_dl/default.nix
+++ /dev/null
@@ -1,17 +0,0 @@
-{ appleDerivation, libsecurity_cdsa_client, libsecurity_cdsa_plugin, libsecurity_cdsa_utilities, libsecurity_filedb, libsecurity_keychain, libsecurity_utilities, libsecurityd }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_cdsa_plugin
-    libsecurity_cdsa_utilities
-    libsecurity_utilities
-    libsecurityd
-    libsecurity_cdsa_client
-    libsecurity_keychain
-    libsecurity_filedb
-  ];
-  patchPhase = ''
-    for file in lib/*; do
-      sed -i 's/#include <\(.*\)>/#include "\1"/' ''$file
-    done
-  '';
-}
\ No newline at end of file
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_cl/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_cl/GNUmakefile
deleted file mode 100644
index c7c9c3d4e79..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_cl/GNUmakefile
+++ /dev/null
@@ -1,10 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_apple_x509_cl
-
-security_apple_x509_cl_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_apple_x509_cl_HEADER_FILES_DIR = lib
-
-security_apple_x509_cl_CC_FILES = $(wildcard lib/*.cpp)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_cl/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_cl/default.nix
deleted file mode 100644
index c5e9418ce91..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_cl/default.nix
+++ /dev/null
@@ -1,18 +0,0 @@
-{ appleDerivation, libsecurity_asn1, libsecurity_cdsa_client, libsecurity_cdsa_plugin, libsecurity_cdsa_utilities, libsecurity_filedb, libsecurity_keychain, libsecurity_utilities, libsecurityd }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_cdsa_plugin
-    libsecurity_cdsa_utilities
-    libsecurity_utilities
-    libsecurityd
-    libsecurity_cdsa_client
-    libsecurity_keychain
-    libsecurity_filedb
-    libsecurity_asn1
-  ];
-  patchPhase = ''
-    for file in lib/*; do
-      sed -i 's/#include <\(.*\)>/#include "\1"/' ''$file
-    done
-  '';
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_tp/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_tp/GNUmakefile
deleted file mode 100644
index 166b4e631c8..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_tp/GNUmakefile
+++ /dev/null
@@ -1,11 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_apple_x509_tp
-
-security_apple_x509_tp_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_apple_x509_tp_HEADER_FILES_DIR = lib
-
-security_apple_x509_tp_C_FILES = $(wildcard lib/*.c)
-security_apple_x509_tp_CC_FILES = $(wildcard lib/*.cpp)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_tp/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_tp/default.nix
deleted file mode 100644
index 6410c134f89..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_apple_x509_tp/default.nix
+++ /dev/null
@@ -1,19 +0,0 @@
-{ appleDerivation, libsecurity_asn1, libsecurity_cdsa_client, libsecurity_cdsa_plugin, libsecurity_cdsa_utilities, libsecurity_filedb, libsecurity_keychain, libsecurity_ocspd, libsecurity_utilities, libsecurityd }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_cdsa_plugin
-    libsecurity_cdsa_utilities
-    libsecurity_utilities
-    libsecurityd
-    libsecurity_cdsa_client
-    libsecurity_keychain
-    libsecurity_filedb
-    libsecurity_asn1
-    libsecurity_ocspd
-  ];
-  patchPhase = ''
-    for file in lib/*; do
-      sed -i 's/#include <\(.*\)>/#include "\1"/' ''$file
-    done
-  '';
-}
\ No newline at end of file
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_asn1/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_asn1/GNUmakefile
deleted file mode 100644
index 1c3c4f0b25b..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_asn1/GNUmakefile
+++ /dev/null
@@ -1,11 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_asn1
-
-security_asn1_C_FILES = $(wildcard lib/*.c)
-security_asn1_CC_FILES = $(wildcard lib/*.cpp)
-
-security_asn1_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_asn1_HEADER_FILES_DIR = lib
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_asn1/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_asn1/default.nix
deleted file mode 100644
index a1c3204c15a..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_asn1/default.nix
+++ /dev/null
@@ -1,14 +0,0 @@
-{ appleDerivation, libsecurity_cdsa_utilities, libsecurity_utilities }:
-appleDerivation {
-  __propagatedImpureHostDeps = [
-    "/System/Library/Frameworks/Security.framework/Security"
-    "/System/Library/Frameworks/Security.framework/Resources"
-    "/System/Library/Frameworks/Security.framework/PlugIns"
-    "/System/Library/Frameworks/Security.framework/XPCServices"
-    "/System/Library/Frameworks/Security.framework/Versions"
-  ];
-  propagatedBuildInputs = [
-    libsecurity_utilities
-    libsecurity_cdsa_utilities
-  ];
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_client/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_client/GNUmakefile
deleted file mode 100644
index 91fb6bb679e..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_client/GNUmakefile
+++ /dev/null
@@ -1,10 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_cdsa_client
-
-security_cdsa_client_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_cdsa_client_HEADER_FILES_DIR = lib
-
-security_cdsa_client_CC_FILES = $(wildcard lib/*.cpp)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_client/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_client/default.nix
deleted file mode 100644
index 2ecad568bf7..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_client/default.nix
+++ /dev/null
@@ -1,8 +0,0 @@
-{ appleDerivation, libsecurity_cdsa_utilities, libsecurity_utilities, libsecurityd }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_utilities
-    libsecurity_cdsa_utilities
-    libsecurityd
-  ];
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_plugin/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_plugin/GNUmakefile
deleted file mode 100644
index 9e1260f9b9c..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_plugin/GNUmakefile
+++ /dev/null
@@ -1,10 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_cdsa_plugin
-
-security_cdsa_plugin_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_cdsa_plugin_HEADER_FILES_DIR = lib
-
-security_cdsa_plugin_CC_FILES = $(wildcard lib/*.cpp)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_plugin/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_plugin/default.nix
deleted file mode 100644
index b2dbb75f297..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_plugin/default.nix
+++ /dev/null
@@ -1,15 +0,0 @@
-{ appleDerivation, libsecurity_cdsa_utilities, libsecurity_cssm, libsecurity_utilities, perl }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_cdsa_utilities
-    libsecurity_utilities
-    perl
-  ];
-  patchPhase = ''
-    unpackFile ${libsecurity_cssm.src}
-    cp libsecurity_cssm*/lib/cssm{dli,aci,cli,cspi,tpi}.h lib
-  '';
-  preBuild = ''
-    perl lib/generator.pl lib lib/generator.cfg lib lib || exit 1
-  '';
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utilities/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utilities/GNUmakefile
deleted file mode 100644
index 24bc1fe7e3a..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utilities/GNUmakefile
+++ /dev/null
@@ -1,13 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_cdsa_utilities
-
-security_cdsa_utilities_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_cdsa_utilities_HEADER_FILES_DIR = lib
-
-security_cdsa_utilities_CC_FILES = $(wildcard lib/*.cpp) lib/Schema.cpp lib/KeySchema.cpp
-
-lib/%.cpp: lib/%.m4
-	m4 $< > $@
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utilities/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utilities/default.nix
deleted file mode 100644
index 26515353b73..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utilities/default.nix
+++ /dev/null
@@ -1,13 +0,0 @@
-{ CommonCrypto, appleDerivation, libsecurity_codesigning, libsecurity_utilities, m4 }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_utilities
-    m4
-  ];
-  patchPhase = ''
-    patch -p1 < ${./handletemplates.patch}
-    unpackFile ${libsecurity_codesigning.src}
-    mv libsecurity_codesigning*/lib security_codesigning
-  '';
-  NIX_CFLAGS_COMPILE = "-I${CommonCrypto}/include/CommonCrypto";
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utilities/handletemplates.patch b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utilities/handletemplates.patch
deleted file mode 100644
index e5a703b2a08..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utilities/handletemplates.patch
+++ /dev/null
@@ -1,19 +0,0 @@
---- a/lib/handletemplates.h  1969-12-31 16:00:01.000000000 -0800
-+++ b/lib/handletemplates.h  1969-12-31 16:00:01.000000000 -0800
-@@ -32,6 +32,7 @@
- #include <security_utilities/threading.h>
- #include <security_utilities/globalizer.h>
- #include <security_cdsa_utilities/cssmerrors.h>
-+#include <vector>
- 
- #if __GNUC__ > 2
- #include <ext/hash_map>
-@@ -129,7 +130,7 @@
-     // @@@  Remove when 4003540 is fixed
-     template <class Subtype>
-     static void findAllRefs(std::vector<_Handle> &refs) {
--        state().findAllRefs<Subtype>(refs);
-+        state().template findAllRefs<Subtype>(refs);
-     }
-     
- protected:
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utils/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utils/GNUmakefile
deleted file mode 100644
index 7b5b7dc186a..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utils/GNUmakefile
+++ /dev/null
@@ -1,13 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_cdsa_utils
-
-security_cdsa_utils_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_cdsa_utils_HEADER_FILES_DIR = lib
-
-security_cdsa_utils_CC_FILES = $(wildcard lib/*.cpp)
-
-lib/%.cpp: lib/%.m4
-	m4 $< > $@
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utils/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utils/default.nix
deleted file mode 100644
index e5637d6db41..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cdsa_utils/default.nix
+++ /dev/null
@@ -1,8 +0,0 @@
-{ appleDerivation, libsecurity_cdsa_utilities, libsecurity_utilities, m4 }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_utilities
-    libsecurity_cdsa_utilities
-    m4
-  ];
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_codesigning/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_codesigning/GNUmakefile
deleted file mode 100644
index e923b962c26..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_codesigning/GNUmakefile
+++ /dev/null
@@ -1,10 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_codesigning
-
-security_codesigning_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_codesigning_HEADER_FILES_DIR = lib
-
-security_codesigning_CC_FILES = $(wildcard lib/*.cpp)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_codesigning/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_codesigning/default.nix
deleted file mode 100644
index f5035a06f1e..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_codesigning/default.nix
+++ /dev/null
@@ -1,33 +0,0 @@
-{ appleDerivation, libsecurity_cdsa_utilities, libsecurity_utilities
-, Security, xnu, xar, antlr, libsecurityd, apple_sdk
-, dtrace-xcode, osx_private_sdk }:
-appleDerivation {
-  buildInputs = [ libsecurity_utilities libsecurity_cdsa_utilities dtrace-xcode
-                  Security xar antlr libsecurityd ];
-  NIX_CFLAGS_COMPILE = "-Iinclude -I${xnu}/Library/Frameworks/System.framework/Headers";
-  patchPhase = ''
-    substituteInPlace lib/policydb.cpp \
-      --replace "new MutableDictionary::MutableDictionary()" NULL
-    substituteInPlace lib/xpcengine.h \
-      --replace "#include <xpc/private.h>" ""
-    substituteInPlace lib/policyengine.cpp \
-      --replace "#include <OpenScriptingUtilPriv.h>" ""
-
-    rm lib/policyengine.cpp lib/quarantine++.cpp lib/codedirectory.cpp lib/xpcengine.cpp
-  '';
-  preBuild = ''
-    mkdir -p include
-    cp ${osx_private_sdk.src}/PrivateSDK10.10.sparse.sdk/usr/include/quarantine.h include
-    mkdir -p include/CoreServices/
-    cp ${osx_private_sdk.src}/PrivateSDK10.10.sparse.sdk/System/Library/Frameworks/CoreServices.framework/PrivateHeaders/*.h include/CoreServices/
-
-    unpackFile ${Security.src}
-    mkdir -p include/securityd_client
-    cp Security-*/libsecurityd/lib/*.h include/securityd_client
-    mkdir -p include/xpc
-    cp ${apple_sdk.sdk.out}/include/xpc/*.h include/xpc
-
-    sed -i '1i #define bool int' lib/security_codesigning.d
-    dtrace -h -C -s lib/security_codesigning.d -o codesigning_dtrace.h
-  '';
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cssm/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cssm/GNUmakefile
deleted file mode 100644
index c7835aaa9b0..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cssm/GNUmakefile
+++ /dev/null
@@ -1,11 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_cssm
-
-security_cssm_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_cssm_HEADER_FILES_DIR = lib
-
-security_cssm_CC_FILES = $(wildcard lib/*.cpp)
-security_cssm_C_FILES = $(wildcard lib/*.c)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cssm/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cssm/default.nix
deleted file mode 100644
index cf9fe411533..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_cssm/default.nix
+++ /dev/null
@@ -1,14 +0,0 @@
-{ appleDerivation, libsecurity_cdsa_client, libsecurity_cdsa_plugin, libsecurity_cdsa_utilities, libsecurity_utilities, perl }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_utilities
-    libsecurity_cdsa_utilities
-    libsecurity_cdsa_client
-    perl
-    libsecurity_cdsa_plugin
-  ];
-  preBuild = ''
-    mkdir derived_src
-    perl lib/generator.pl lib lib/generator.cfg derived_src
-  '';
-}
\ No newline at end of file
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_filedb/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_filedb/GNUmakefile
deleted file mode 100644
index 4359810c56b..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_filedb/GNUmakefile
+++ /dev/null
@@ -1,10 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_filedb
-
-security_filedb_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_filedb_HEADER_FILES_DIR = lib
-
-security_filedb_CC_FILES = $(wildcard lib/*.cpp)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_filedb/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_filedb/default.nix
deleted file mode 100644
index 435cd0f069f..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_filedb/default.nix
+++ /dev/null
@@ -1,13 +0,0 @@
-{ appleDerivation, apple_sdk, libsecurity_cdsa_plugin, libsecurity_cdsa_utilities, libsecurity_utilities, osx_private_sdk, lib }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_utilities
-    libsecurity_cdsa_utilities
-    libsecurity_cdsa_plugin
-  ];
-  patchPhase = ''
-    cp ${osx_private_sdk}/include/sandbox_private.h .
-    substituteInPlace sandbox_private.h --replace '<sandbox.h>' '"${lib.getDev apple_sdk.sdk}/include/sandbox.h"'
-    substituteInPlace lib/AtomicFile.cpp --replace '<sandbox.h>' '"sandbox_private.h"'
-  '';
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_generic/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_generic/default.nix
deleted file mode 100644
index 714524e8da5..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_generic/default.nix
+++ /dev/null
@@ -1,63 +0,0 @@
-{ appleDerivation_, applePackage, pkgs, stdenv }:
-name: version: sha256: args: let
-  n = stdenv.lib.removePrefix "lib" name;
-  makeFile = ../. + "/${name}/GNUmakefile";
-  appleDerivation = appleDerivation_ name version sha256;
-  in applePackage name version sha256 (args // {
-    appleDerivation = a:
-    appleDerivation (stdenv.lib.mergeAttrsConcatenateValues {
-      __impureHostDeps = import ./impure_deps.nix;
-
-      patchPhase = ''
-        # allows including <Security/some-private-header.h>
-        cp -R ${pkgs.darwin.osx_private_sdk}/include/SecurityPrivateHeaders Security
-
-        grep -Rl MacErrors.h . | while read file; do
-          substituteInPlace "''$file" --replace \
-            '<CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>' \
-            '"${pkgs.darwin.apple_sdk.sdk.out}/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Headers/MacErrors.h"'
-        done || true # grep returns 1 if it can't find the string
-
-        grep -Rl MacTypes.h . | while read file; do
-          substituteInPlace "''$file" --replace \
-            '<CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>' \
-            '"${stdenv.lib.getDev pkgs.darwin.apple_sdk.sdk}/include/MacTypes.h"'
-        done || true # grep returns 1 if it can't find the string
-      '';
-      preBuild = ''
-        ln -s lib ${n}
-        makeFlagsArray=(-j$NIX_BUILD_CORES)
-      '';
-      outputs = [ "out" "dev" ];
-      buildInputs = [
-        pkgs.gnustep.make
-        pkgs.darwin.apple_sdk.frameworks.AppKit
-        pkgs.darwin.apple_sdk.frameworks.Foundation
-      ];
-      makeFlags = [
-        "-f${makeFile}"
-        "MAKEFILE_NAME=${makeFile}"
-        "GNUSTEP_ABSOLUTE_INSTALL_PATHS=yes"
-        "GNUSTEP_MAKEFILES=${pkgs.gnustep.make}/share/GNUstep/Makefiles"
-        "LIB_LINK_INSTALL_DIR=\$(out)/lib"
-      ];
-      installFlags = [
-        "${n}_INSTALL_DIR=\$(out)/lib"
-        "${n}_HEADER_FILES_INSTALL_DIR=\$(out)/include/${n}"
-        "GNUSTEP_HEADERS="
-      ];
-      NIX_CFLAGS_COMPILE = [
-        "-isystem lib"
-        "-iframework ${pkgs.darwin.Security}/Library/Frameworks"
-        "-I."
-        "-Wno-deprecated-declarations"
-        "-DNDEBUG"
-      ];
-      NIX_LDFLAGS = with pkgs.darwin; with apple_sdk.frameworks; [
-        "-L${libobjc}/lib"
-        "-F${Foundation}/Library/Frameworks"
-        "-F${AppKit}/Library/Frameworks"
-        "-no_dtrace_dof"
-      ];
-    } a);
-  })
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_generic/impure_deps.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_generic/impure_deps.nix
deleted file mode 100644
index f54d667d6ae..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_generic/impure_deps.nix
+++ /dev/null
@@ -1,128 +0,0 @@
-# generated using a ruby script
-[
-  "/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate"
-  "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vImage.framework/Versions/A/vImage"
-  "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib"
-  "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib"
-  "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLinearAlgebra.dylib"
-  "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvDSP.dylib"
-  "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvMisc.dylib"
-  "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/vecLib"
-  "/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit"
-  "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices"
-  "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/ATS"
-  "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/Resources/libFontParser.dylib"
-  "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/Resources/libFontRegistry.dylib"
-  "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ColorSync.framework/Versions/A/ColorSync"
-  "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/HIServices"
-  "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/LangAnalysis.framework/Versions/A/LangAnalysis"
-  "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/PrintCore"
-  "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/QD.framework/Versions/A/QD"
-  "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/SpeechSynthesis.framework/Versions/A/SpeechSynthesis"
-  "/System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox"
-  "/System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit"
-  "/System/Library/Frameworks/CFNetwork.framework/Versions/A/CFNetwork"
-  "/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/CarbonSound.framework/Versions/A/CarbonSound"
-  "/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox"
-  "/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/Ink.framework/Versions/A/Ink"
-  "/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/SpeechRecognition.framework/Versions/A/SpeechRecognition"
-  "/System/Library/Frameworks/CoreAudio.framework/Versions/A/CoreAudio"
-  "/System/Library/Frameworks/CoreBluetooth.framework/Versions/A/CoreBluetooth"
-  "/System/Library/Frameworks/CoreData.framework/Versions/A/CoreData"
-  "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation"
-  "/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics"
-  "/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices"
-  "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/AE"
-  "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/CarbonCore"
-  "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/DictionaryServices.framework/Versions/A/DictionaryServices"
-  "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versions/A/FSEvents"
-  "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/LaunchServices"
-  "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Metadata"
-  "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Versions/A/OSServices"
-  "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/SearchKit.framework/Versions/A/SearchKit"
-  "/System/Library/Frameworks/CoreText.framework/Versions/A/CoreText"
-  "/System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo"
-  "/System/Library/Frameworks/CoreWLAN.framework/Versions/A/CoreWLAN"
-  "/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration"
-  "/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation"
-  "/System/Library/Frameworks/GSS.framework/Versions/A/GSS"
-  "/System/Library/Frameworks/IOBluetooth.framework/Versions/A/IOBluetooth"
-  "/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit"
-  "/System/Library/Frameworks/IOSurface.framework/Versions/A/IOSurface"
-  "/System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO"
-  "/System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libGIF.dylib"
-  "/System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libJP2.dylib"
-  "/System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libJPEG.dylib"
-  "/System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libPng.dylib"
-  "/System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libRadiance.dylib"
-  "/System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libTIFF.dylib"
-  "/System/Library/Frameworks/Kerberos.framework/Versions/A/Kerberos"
-  "/System/Library/Frameworks/NetFS.framework/Versions/A/NetFS"
-  "/System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL"
-  "/System/Library/Frameworks/OpenDirectory.framework/Versions/A/Frameworks/CFOpenDirectory.framework/Versions/A/CFOpenDirectory"
-  "/System/Library/Frameworks/OpenDirectory.framework/Versions/A/OpenDirectory"
-  "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libCVMSPluginSupport.dylib"
-  "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libCoreVMClient.dylib"
-  "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGFXShared.dylib"
-  "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib"
-  "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLImage.dylib"
-  "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib"
-  "/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL"
-  "/System/Library/Frameworks/QuartzCore.framework/Versions/A/Frameworks/CoreImage.framework/Versions/A/CoreImage"
-  "/System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore"
-  "/System/Library/Frameworks/Security.framework/Versions/A/Security"
-  "/System/Library/Frameworks/SecurityFoundation.framework/Versions/A/SecurityFoundation"
-  "/System/Library/Frameworks/ServiceManagement.framework/Versions/A/ServiceManagement"
-  "/System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration"
-  "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Apple80211"
-  "/System/Library/PrivateFrameworks/AppleJPEG.framework/Versions/A/AppleJPEG"
-  "/System/Library/PrivateFrameworks/AppleVPA.framework/Versions/A/AppleVPA"
-  "/System/Library/PrivateFrameworks/Backup.framework/Versions/A/Backup"
-  "/System/Library/PrivateFrameworks/ChunkingLibrary.framework/Versions/A/ChunkingLibrary"
-  "/System/Library/PrivateFrameworks/CommonAuth.framework/Versions/A/CommonAuth"
-  "/System/Library/PrivateFrameworks/CoreSymbolication.framework/Versions/A/CoreSymbolication"
-  "/System/Library/PrivateFrameworks/CoreUI.framework/Versions/A/CoreUI"
-  "/System/Library/PrivateFrameworks/CoreWiFi.framework/Versions/A/CoreWiFi"
-  "/System/Library/PrivateFrameworks/CrashReporterSupport.framework/Versions/A/CrashReporterSupport"
-  "/System/Library/PrivateFrameworks/DataDetectorsCore.framework/Versions/A/DataDetectorsCore"
-  "/System/Library/PrivateFrameworks/DebugSymbols.framework/Versions/A/DebugSymbols"
-  "/System/Library/PrivateFrameworks/DesktopServicesPriv.framework/Versions/A/DesktopServicesPriv"
-  "/System/Library/PrivateFrameworks/FaceCore.framework/Versions/A/FaceCore"
-  "/System/Library/PrivateFrameworks/GenerationalStorage.framework/Versions/A/GenerationalStorage"
-  "/System/Library/PrivateFrameworks/Heimdal.framework/Versions/A/Heimdal"
-  "/System/Library/PrivateFrameworks/IconServices.framework/Versions/A/IconServices"
-  "/System/Library/PrivateFrameworks/LanguageModeling.framework/Versions/A/LanguageModeling"
-  "/System/Library/PrivateFrameworks/MultitouchSupport.framework/Versions/A/MultitouchSupport"
-  "/System/Library/PrivateFrameworks/NetAuth.framework/Versions/A/NetAuth"
-  "/System/Library/PrivateFrameworks/PerformanceAnalysis.framework/Versions/A/PerformanceAnalysis"
-  "/System/Library/PrivateFrameworks/RemoteViewServices.framework/Versions/A/RemoteViewServices"
-  "/System/Library/PrivateFrameworks/Sharing.framework/Versions/A/Sharing"
-  "/System/Library/PrivateFrameworks/SpeechRecognitionCore.framework/Versions/A/SpeechRecognitionCore"
-  "/System/Library/PrivateFrameworks/Symbolication.framework/Versions/A/Symbolication"
-  "/System/Library/PrivateFrameworks/TCC.framework/Versions/A/TCC"
-  "/System/Library/PrivateFrameworks/UIFoundation.framework/Versions/A/UIFoundation"
-  "/System/Library/PrivateFrameworks/login.framework/Versions/A/Frameworks/loginsupport.framework/Versions/A/loginsupport"
-  "/usr/lib/libCRFSuite.dylib"
-  "/usr/lib/libOpenScriptingUtil.dylib"
-  "/usr/lib/libarchive.2.dylib"
-  "/usr/lib/libbsm.0.dylib"
-  "/usr/lib/libbz2.1.0.dylib"
-  "/usr/lib/libc++.1.dylib"
-  "/usr/lib/libc++abi.dylib"
-  "/usr/lib/libcmph.dylib"
-  "/usr/lib/libcups.2.dylib"
-  "/usr/lib/libextension.dylib"
-  "/usr/lib/libheimdal-asn1.dylib"
-  "/usr/lib/libiconv.2.dylib"
-  "/usr/lib/libicucore.A.dylib"
-  "/usr/lib/liblangid.dylib"
-  "/usr/lib/liblzma.5.dylib"
-  "/usr/lib/libmecabra.dylib"
-  "/usr/lib/libpam.2.dylib"
-  "/usr/lib/libresolv.9.dylib"
-  "/usr/lib/libsqlite3.dylib"
-  "/usr/lib/libxar.1.dylib"
-  "/usr/lib/libxml2.2.dylib"
-  "/usr/lib/libxslt.1.dylib"
-  "/usr/lib/libz.1.dylib"
-]
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_keychain/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_keychain/GNUmakefile
deleted file mode 100644
index 8830006f00e..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_keychain/GNUmakefile
+++ /dev/null
@@ -1,10 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_keychain
-
-security_keychain_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_keychain_HEADER_FILES_DIR = lib
-
-security_keychain_CC_FILES = $(wildcard lib/*.cpp)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_keychain/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_keychain/default.nix
deleted file mode 100644
index 724c4788b6c..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_keychain/default.nix
+++ /dev/null
@@ -1,43 +0,0 @@
-{ CF, appleDerivation, apple_sdk, libsecurity_asn1, libsecurity_cdsa_client, libsecurity_cdsa_utilities, libsecurity_cdsa_utils, libsecurity_ocspd, libsecurity_pkcs12, libsecurity_utilities, libsecurityd, openssl, osx_private_sdk, security_dotmac_tp, lib }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_utilities
-    libsecurity_cdsa_client
-    libsecurity_cdsa_utilities
-    libsecurityd
-    CF
-    libsecurity_asn1
-    libsecurity_pkcs12
-    libsecurity_cdsa_utils
-    openssl
-    libsecurity_ocspd
-    security_dotmac_tp
-  ];
-  patchPhase = ''
-    substituteInPlace lib/Keychains.cpp --replace DLDbListCFPref.h DLDBListCFPref.h
-
-    substituteInPlace lib/SecCertificate.cpp --replace '#include <Security/SecCertificatePriv.h>' ""
-
-    cp ${osx_private_sdk}/include/xpc/private.h xpc
-    cp ${lib.getDev apple_sdk.sdk}/include/xpc/*.h xpc
-    cp ${osx_private_sdk}/include/sandbox_private.h lib/sandbox.h
-
-    substituteInPlace lib/SecItemPriv.h \
-      --replace "extern CFTypeRef kSecAttrAccessGroup" "extern const CFTypeRef kSecAttrAccessGroup" \
-      --replace "extern CFTypeRef kSecAttrIsSensitive" "extern const CFTypeRef kSecAttrIsSensitive" \
-      --replace "extern CFTypeRef kSecAttrIsExtractable" "extern const CFTypeRef kSecAttrIsExtractable"
-
-    substituteInPlace lib/Keychains.cpp --replace \
-      '<CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>' \
-      '"${apple_sdk.sdk.out}/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Headers/MacErrors.h"'
-
-    substituteInPlace lib/CertificateValues.cpp --replace \
-      '#include <Security/SecCertificatePriv.h>' ""
-
-    substituteInPlace lib/DLDBListCFPref.cpp --replace \
-      'dispatch_once_t AppSandboxChecked;' ''$'namespace Security {\ndispatch_once_t AppSandboxChecked;' \
-      --replace 'return mLoginDLDbIdentifier;' 'return mLoginDLDbIdentifier; }' \
-      --replace '_xpc_runtime_is_app_sandboxed()' 'false'
-      # hope that doesn't hurt anything
-  '';
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_mds/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_mds/GNUmakefile
deleted file mode 100644
index 119a43621fb..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_mds/GNUmakefile
+++ /dev/null
@@ -1,10 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_mds
-
-security_mds_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_mds_HEADER_FILES_DIR = lib
-
-security_mds_CC_FILES = $(wildcard lib/*.cpp)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_mds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_mds/default.nix
deleted file mode 100644
index cd691f71e95..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_mds/default.nix
+++ /dev/null
@@ -1,11 +0,0 @@
-{ appleDerivation, libsecurity_cdsa_client, libsecurity_cdsa_plugin, libsecurity_cdsa_utilities, libsecurity_filedb, libsecurity_utilities, libsecurityd }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_cdsa_plugin
-    libsecurity_cdsa_utilities
-    libsecurity_filedb
-    libsecurity_utilities
-    libsecurity_cdsa_client
-    libsecurityd
-  ];
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_ocspd/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_ocspd/GNUmakefile
deleted file mode 100644
index 140c5a909a6..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_ocspd/GNUmakefile
+++ /dev/null
@@ -1,10 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_ocspd
-
-security_ocspd_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_ocspd_HEADER_FILES_DIR = lib
-
-security_ocspd_CC_FILES = $(wildcard lib/*.cpp)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_ocspd/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_ocspd/default.nix
deleted file mode 100644
index 81551e9a76e..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_ocspd/default.nix
+++ /dev/null
@@ -1,20 +0,0 @@
-{ appleDerivation, bootstrap_cmds, libsecurity_cdsa_utilities, libsecurity_utilities }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_utilities
-    libsecurity_cdsa_utilities
-    bootstrap_cmds
-  ];
-  postUnpack = ''
-    pushd libsecurity*
-    ls -lah
-    mkdir -p lib
-    cp common/* lib
-    cp client/* lib
-    popd
-  '';
-  preBuild = ''
-    make -f mig/mig.mk SRCROOT=. BUILT_PRODUCTS_DIR=. || exit 1
-    cp derived_src/* lib
-  '';
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_pkcs12/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_pkcs12/GNUmakefile
deleted file mode 100644
index b2af7e72c41..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_pkcs12/GNUmakefile
+++ /dev/null
@@ -1,11 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_pkcs12
-
-security_pkcs12_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_pkcs12_HEADER_FILES_DIR = lib
-
-security_pkcs12_CC_FILES = $(wildcard lib/*.cpp)
-security_pkcs12_C_FILES = $(wildcard lib/*.c)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_pkcs12/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_pkcs12/default.nix
deleted file mode 100644
index b225d062dc9..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_pkcs12/default.nix
+++ /dev/null
@@ -1,15 +0,0 @@
-{ appleDerivation, libsecurity_asn1, libsecurity_cdsa_client, libsecurity_cdsa_utils, libsecurity_keychain }:
-appleDerivation {
-  patchPhase = ''
-    substituteInPlace lib/pkcsoids.h --replace '#error' '#warning'
-  '';
-  preBuild = ''
-    unpackFile ${libsecurity_keychain.src}
-    mv libsecurity_keychain*/lib security_keychain
-  '';
-  buildInputs = [
-    libsecurity_asn1
-    libsecurity_cdsa_utils
-    libsecurity_cdsa_client
-  ];
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_sd_cspdl/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_sd_cspdl/GNUmakefile
deleted file mode 100644
index 47a1c609d06..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_sd_cspdl/GNUmakefile
+++ /dev/null
@@ -1,10 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_sd_cspdl
-
-security_sd_cspdl_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_sd_cspdl_HEADER_FILES_DIR = lib
-
-security_sd_cspdl_CC_FILES = $(wildcard lib/*.cpp)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_sd_cspdl/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_sd_cspdl/default.nix
deleted file mode 100644
index 22491091661..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_sd_cspdl/default.nix
+++ /dev/null
@@ -1,10 +0,0 @@
-{ appleDerivation, libsecurity_cdsa_client, libsecurity_cdsa_plugin, libsecurity_cdsa_utilities, libsecurity_utilities, libsecurityd }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_cdsa_plugin
-    libsecurity_utilities
-    libsecurity_cdsa_utilities
-    libsecurityd
-    libsecurity_cdsa_client
-  ];
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_utilities/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_utilities/GNUmakefile
deleted file mode 100644
index d3ba09142c9..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_utilities/GNUmakefile
+++ /dev/null
@@ -1,11 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_utilities
-
-security_utilities_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_utilities_HEADER_FILES_DIR = lib
-
-security_utilities_C_FILES = $(wildcard lib/*.c)
-security_utilities_CC_FILES = $(wildcard lib/*.cpp)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_utilities/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurity_utilities/default.nix
deleted file mode 100644
index 1ab950a9233..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurity_utilities/default.nix
+++ /dev/null
@@ -1,28 +0,0 @@
-{ IOKit, appleDerivation, apple_sdk, libauto, libobjc, sqlite, stdenv, osx_private_sdk }:
-appleDerivation {
-  buildInputs = [
-    libauto
-    libobjc
-    IOKit
-  ];
-  propagatedBuildInputs = [
-    sqlite
-    apple_sdk.frameworks.PCSC
-  ];
-  NIX_LDFLAGS = "-framework PCSC";
-  patchPhase = ''
-    substituteInPlace lib/errors.h --replace \
-      '<CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>' \
-      '"MacTypes.h"'
-    substituteInPlace lib/debugging.cpp --replace PATH_MAX 1024
-    substituteInPlace lib/superblob.h --replace 'result->at' 'result->template at'
-    substituteInPlace lib/ccaudit.cpp --replace '<bsm/libbsm.h>' '"bsm/libbsm.h"'
-    substituteInPlace lib/powerwatch.h --replace \
-      '<IOKit/pwr_mgt/IOPMLibPrivate.h>' \
-      '"${IOKit}/Library/Frameworks/IOKit.framework/Headers/pwr_mgt/IOPMLibPrivate.h"'
-    cp -R ${osx_private_sdk}/include/bsm lib
-    cp ${osx_private_sdk}/include/utilities_dtrace.h lib
-  '' + stdenv.lib.optionalString (!stdenv.cc.nativeLibc) ''
-    substituteInPlace lib/vproc++.cpp --replace /usr/local/include/vproc_priv.h ${stdenv.libc}/include/vproc_priv.h
-  '';
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurityd/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/libsecurityd/GNUmakefile
deleted file mode 100644
index 6058043e79f..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurityd/GNUmakefile
+++ /dev/null
@@ -1,11 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = securityd
-
-securityd_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-securityd_HEADER_FILES_DIR = lib
-
-securityd_CC_FILES = $(wildcard lib/*.cpp)
-securityd_C_FILES = $(wildcard lib/*.c)
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurityd/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libsecurityd/default.nix
deleted file mode 100644
index fb3441f7050..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurityd/default.nix
+++ /dev/null
@@ -1,23 +0,0 @@
-{ appleDerivation, bootstrap_cmds, libsecurity_cdsa_client, libsecurity_cdsa_utilities, libsecurity_utilities }:
-appleDerivation {
-  buildInputs = [
-    libsecurity_cdsa_utilities
-    libsecurity_utilities
-    bootstrap_cmds
-  ];
-  patchPhase = ''
-    unpackFile ${libsecurity_cdsa_client.src}
-    mv libsecurity_cdsa_client*/lib security_cdsa_client
-    ln -s lib securityd_client
-
-    patch -p1 < ${./xdr-arity.patch}
-  '';
-  preBuild = ''
-    make -f mig/mig.mk SRCROOT=. BUILT_PRODUCTS_DIR=.
-    cp derived_src/* lib
-    rm lib/ucspClientC.c
-  '';
-  postFixup = ''
-    ln -s $dev/include/securityd $dev/include/securityd_client
-  '';
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libsecurityd/xdr-arity.patch b/pkgs/os-specific/darwin/apple-source-releases/libsecurityd/xdr-arity.patch
deleted file mode 100644
index 5d0328629f1..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libsecurityd/xdr-arity.patch
+++ /dev/null
@@ -1,79 +0,0 @@
-diff --git a/lib/sec_xdr.c b/lib/sec_xdr.c
-index fe5f038..6239b6c 100644
---- a/lib/sec_xdr.c
-+++ b/lib/sec_xdr.c
-@@ -223,7 +223,7 @@ bool_t copyin(void *data, xdrproc_t proc, void** copy, u_int *size)
-     sec_xdrmem_create(&xdr, (char *)xdr_data, length, XDR_ENCODE);
- 
-     // cast to void* - function can go both ways (xdr->x_op) 
--    if (proc(&xdr, data)) {
-+    if (proc(&xdr, data, 0)) {
-         *copy = xdr_data;
-         if (size) *size = length;
-         return (TRUE);
-@@ -261,7 +261,7 @@ bool_t copyout(const void *copy, u_int size, xdrproc_t proc, void **data, u_int
-     if (!sec_xdr_arena_init(&arena, &xdr, length_out ? length_out : length_required, length_out ? *data : NULL))
-         return (FALSE);
- 
--    if (proc(&xdr, data))
-+    if (proc(&xdr, data, 0))
-     {
-         *length = length_required;
-         return (TRUE);
-@@ -284,7 +284,7 @@ bool_t copyout_chunked(const void *copy, u_int size, xdrproc_t proc, void **data
- 
-     void *data_out = NULL;
- 
--    if (proc(&xdr, &data_out))
-+    if (proc(&xdr, &data_out, 0))
-     {
-         *data = data_out;
-         return (TRUE);
-diff --git a/lib/sec_xdr_array.c b/lib/sec_xdr_array.c
-index 152a71b..e5ec1ad 100644
---- a/lib/sec_xdr_array.c
-+++ b/lib/sec_xdr_array.c
-@@ -147,7 +147,7 @@ sec_xdr_array(XDR *xdrs, uint8_t **addrp, u_int *sizep, u_int maxsize, u_int els
-     for (i = 0; (i < c) && stat; i++) {
-         if ((xdrs->x_op == XDR_DECODE) && sizeof_alloc)
-             memset(obj, 0, elsize);
--        stat = (*elproc)(xdrs, target);
-+        stat = (*elproc)(xdrs, target, 0);
-         if ((xdrs->x_op == XDR_ENCODE) || !sizeof_alloc)
-             target += elsize;
-     }
-diff --git a/lib/sec_xdr_reference.c b/lib/sec_xdr_reference.c
-index a66fb37..ab5b4c4 100644
---- a/lib/sec_xdr_reference.c
-+++ b/lib/sec_xdr_reference.c
-@@ -121,7 +121,7 @@ sec_xdr_reference(XDR *xdrs, uint8_t **pp, u_int size, xdrproc_t proc)
-                 break;
-             }
- 
--    stat = (*proc)(xdrs, loc);
-+    stat = (*proc)(xdrs, loc, 0);
- 
-     if (xdrs->x_op == XDR_FREE) {
-         sec_mem_free(xdrs, loc, size);
-diff --git a/lib/sec_xdr_sizeof.c b/lib/sec_xdr_sizeof.c
-index a18bcd0..8c33dbc 100644
---- a/lib/sec_xdr_sizeof.c
-+++ b/lib/sec_xdr_sizeof.c
-@@ -190,7 +190,7 @@ sec_xdr_sizeof_in(func, data)
- 
-     sec_xdr_arena_allocator_t size_alloc;
-     sec_xdr_arena_init_size_alloc(&size_alloc, &x);
--    stat = func(&x, data);
-+    stat = func(&x, data, 0);
-     if (x.x_private)
-         free(x.x_private);
-     return (stat == TRUE ? (unsigned) x.x_handy: 0);
-@@ -210,7 +210,7 @@ sec_xdr_sizeof_out(copy, size, func, data)
- 
-     sec_xdr_arena_allocator_t size_alloc;
-     sec_xdr_arena_init_size_alloc(&size_alloc, &x);
--    stat = func(&x, data);
-+    stat = func(&x, data, 0);
-     if (size_alloc.data)
-         free(size_alloc.data);
-     return (stat == TRUE ? (unsigned long)size_alloc.offset : 0);
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libutil/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libutil/default.nix
index a6f484ba4e8..87211f481d4 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/libutil/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/libutil/default.nix
@@ -1,13 +1,33 @@
-{ stdenv, appleDerivation }:
+{ stdenv, lib, appleDerivation, xcbuildHook
+
+# headersOnly is true when building for libSystem
+, headersOnly ? false }:
 
-# all symbols are located in libSystem
 appleDerivation {
+  nativeBuildInputs = lib.optional (!headersOnly) xcbuildHook;
+
+  prePatch = ''
+    substituteInPlace tzlink.c \
+      --replace '#include <xpc/xpc.h>' ""
+  '';
+
+  xcbuildFlags = "-target util";
+
   installPhase = ''
     mkdir -p $out/include
+  '' + lib.optionalString headersOnly ''
     cp *.h $out/include
+  '' + lib.optionalString (!headersOnly)''
+    mkdir -p $out/lib $out/include
+
+    cp Products/Release/*.dylib $out/lib
+    cp Products/Release/*.h $out/include
+
+    # TODO: figure out how to get this to be right the first time around
+    install_name_tool -id $out/lib/libutil.dylib $out/lib/libutil.dylib
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     maintainers = with maintainers; [ copumpkin ];
     platforms   = platforms.darwin;
     license     = licenses.apsl20;
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libutil/new.nix b/pkgs/os-specific/darwin/apple-source-releases/libutil/new.nix
deleted file mode 100644
index 0115ce537e2..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/libutil/new.nix
+++ /dev/null
@@ -1,29 +0,0 @@
-{ stdenv, appleDerivation, xcbuildHook }:
-
-# TODO: make this the official libutil expression once we've integrated xcbuild in the bootstrap
-appleDerivation {
-  nativeBuildInputs = [ xcbuildHook ];
-
-  prePatch = ''
-    substituteInPlace tzlink.c \
-      --replace '#include <xpc/xpc.h>' ""
-  '';
-
-  xcbuildFlags = "-target util";
-
-  installPhase = ''
-    mkdir -p $out/lib $out/include
-
-    cp Products/Release/*.dylib $out/lib
-    cp Products/Release/*.h $out/include
-
-    # TODO: figure out how to get this to be right the first time around
-    install_name_tool -id $out/lib/libutil.dylib $out/lib/libutil.dylib
-  '';
-
-  meta = with stdenv.lib; {
-    maintainers = with maintainers; [ copumpkin ];
-    platforms   = platforms.darwin;
-    license     = licenses.apsl20;
-  };
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/security_dotmac_tp/GNUmakefile b/pkgs/os-specific/darwin/apple-source-releases/security_dotmac_tp/GNUmakefile
deleted file mode 100644
index 6f6a50bd57a..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/security_dotmac_tp/GNUmakefile
+++ /dev/null
@@ -1,8 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-LIBRARY_NAME = security_dotmac_tp
-
-security_dotmac_tp_HEADER_FILES = $(notdir $(wildcard lib/*.h))
-security_dotmac_tp_HEADER_FILES_DIR = lib
-
-include $(GNUSTEP_MAKEFILES)/library.make
diff --git a/pkgs/os-specific/darwin/apple-source-releases/security_dotmac_tp/default.nix b/pkgs/os-specific/darwin/apple-source-releases/security_dotmac_tp/default.nix
deleted file mode 100644
index bfbfb945957..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/security_dotmac_tp/default.nix
+++ /dev/null
@@ -1,4 +0,0 @@
-{ appleDerivation }:
-
-appleDerivation {
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/security_systemkeychain/default.nix b/pkgs/os-specific/darwin/apple-source-releases/security_systemkeychain/default.nix
deleted file mode 100644
index d5bc3483c38..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/security_systemkeychain/default.nix
+++ /dev/null
@@ -1,32 +0,0 @@
-{ appleDerivation, xcbuildHook, Security
-, libsecurity_codesigning, libsecurity_utilities, libsecurity_cdsa_utilities
-, xnu, osx_private_sdk, pcsclite}:
-
-appleDerivation {
-  nativeBuildInputs = [ xcbuildHook ];
-  buildInputs = [ Security libsecurity_utilities
-                  libsecurity_cdsa_utilities libsecurity_codesigning
-                  pcsclite ];
-
-  NIX_LDFLAGS = "-lpcsclite";
-
-  # can't build the whole thing
-  xcbuildFlags = "-target codesign";
-
-  preBuild = ''
-    mkdir -p include/Security
-    cp ${osx_private_sdk.src}/PrivateSDK10.10.sparse.sdk/System/Library/Frameworks/Security.framework/PrivateHeaders/*.h include/Security
-    cp ${osx_private_sdk.src}/PrivateSDK10.10.sparse.sdk/System/Library/Frameworks/Security.framework/Headers/*.h include/Security
-
-    unpackFile ${xnu.src}
-    mkdir -p include/sys
-    cp -r xnu-*/bsd/sys/codesign.h include/sys/codesign.h
-  '';
-
-  NIX_CFLAGS_COMPILE = "-Iinclude";
-
-  installPhase = ''
-    mkdir -p $out/bin
-    cp Products/Release/codesign $out/bin/codesign
-  '';
-}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/top/default.nix b/pkgs/os-specific/darwin/apple-source-releases/top/default.nix
index 3513cb2e172..a2f912ca578 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/top/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/top/default.nix
@@ -1,8 +1,8 @@
-{xcbuildHook, appleDerivation, apple_sdk, ncurses, libutil-new, lib}:
+{xcbuildHook, appleDerivation, apple_sdk, ncurses, libutil, lib}:
 
 appleDerivation {
   nativeBuildInputs = [ xcbuildHook ];
-  buildInputs = [ apple_sdk.frameworks.IOKit ncurses libutil-new ];
+  buildInputs = [ apple_sdk.frameworks.IOKit ncurses libutil ];
   NIX_LDFLAGS = "-lutil";
   installPhase = ''
     install -D Products/Release/libtop.a $out/lib/libtop.a
diff --git a/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix b/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix
index 74c9f254348..aaa3a1ebe32 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix
@@ -1,11 +1,11 @@
-{ appleDerivation, bootstrap_cmds, bison, flex, gnum4, unifdef, perl, python }:
+{ appleDerivation, lib, bootstrap_cmds, bison, flex
+, gnum4, unifdef, perl, python
+, headersOnly ? true }:
 
-appleDerivation {
-  phases = [ "unpackPhase" "patchPhase" "installPhase" ];
+appleDerivation ({
+  nativeBuildInputs = [ bootstrap_cmds bison flex gnum4 unifdef perl python ];
 
-  buildInputs = [ bootstrap_cmds bison flex gnum4 unifdef perl python ];
-
-  patchPhase = ''
+  postPatch = ''
     substituteInPlace Makefile \
       --replace "/bin/" "" \
       --replace "MAKEJOBS := " '# MAKEJOBS := '
@@ -40,7 +40,27 @@ appleDerivation {
     patchShebangs .
   '';
 
-  installPhase = ''
+  PLATFORM = "MacOSX";
+  SDKVERSION = "10.11";
+  CC = "cc";
+  CXX = "c++";
+  MIG = "mig";
+  MIGCOM = "migcom";
+  STRIP = "strip";
+  NM = "nm";
+  UNIFDEF = "unifdef";
+  DSYMUTIL = "dsymutil";
+  HOST_OS_VERSION = "10.10";
+  HOST_CC = "cc";
+  HOST_FLEX = "flex";
+  HOST_BISON = "bison";
+  HOST_GM4 = "m4";
+  MIGCC = "cc";
+  ARCHS = "x86_64";
+
+  NIX_CFLAGS_COMPILE = "-Wno-error";
+
+  preBuild = ''
     # This is a bit of a hack...
     mkdir -p sdk/usr/local/libexec
 
@@ -56,49 +76,27 @@ appleDerivation {
 
     export SDKROOT_RESOLVED=$PWD/sdk
     export HOST_SDKROOT_RESOLVED=$PWD/sdk
-    export PLATFORM=MacOSX
-    export SDKVERSION=10.11
-
-    export CC=cc
-    export CXX=c++
-    export MIG=${bootstrap_cmds}/bin/mig
-    export MIGCOM=${bootstrap_cmds}/libexec/migcom
-    export STRIP=sentinel-missing
-    export LIPO=sentinel-missing
-    export LIBTOOL=sentinel-missing
-    export NM=sentinel-missing
-    export UNIFDEF=${unifdef}/bin/unifdef
-    export DSYMUTIL=sentinel-missing
-    export CTFCONVERT=sentinel-missing
-    export CTFMERGE=sentinel-missing
-    export CTFINSERT=sentinel-missing
-    export NMEDIT=sentinel-missing
-
-    export HOST_OS_VERSION=10.7
-    export HOST_CC=cc
-    export HOST_FLEX=${flex}/bin/flex
-    export HOST_BISON=${bison}/bin/bison
-    export HOST_GM4=${gnum4}/bin/m4
-    export HOST_CODESIGN='echo dummy_codesign'
-    export HOST_CODESIGN_ALLOCATE=echo
 
     export BUILT_PRODUCTS_DIR=.
-
     export DSTROOT=$out
-    make installhdrs
+  '';
 
+  buildFlags = lib.optionalString headersOnly "exporthdrs";
+  installTargets = lib.optionalString headersOnly "installhdrs";
+
+  postInstall = lib.optionalString headersOnly ''
     mv $out/usr/include $out
 
+    (cd BUILD/obj/EXPORT_HDRS && find -type f -exec install -D \{} $out/include/\{} \;)
+
     # TODO: figure out why I need to do this
     cp libsyscall/wrappers/*.h $out/include
-    mkdir -p $out/include/os
-    cp libsyscall/os/tsd.h $out/include/os/tsd.h
+    install -D libsyscall/os/tsd.h $out/include/os/tsd.h
     cp EXTERNAL_HEADERS/AssertMacros.h $out/include
     cp EXTERNAL_HEADERS/Availability*.h $out/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/
+    cp -r EXTERNAL_HEADERS/corecrypto $out/include
 
     # Build the mach headers we crave
-    export MIGCC=cc
-    export ARCHS="x86_64"
     export SRCROOT=$PWD/libsyscall
     export DERIVED_SOURCES_DIR=$out/include
     export SDKROOT=$out
@@ -108,14 +106,13 @@ appleDerivation {
 
     # Get rid of the System prefix
     mv $out/System/* $out/
+    rmdir $out/System
 
     # TODO: do I need this?
     mv $out/internal_hdr/include/mach/*.h $out/include/mach
 
     # Get rid of some junk lying around
-    rm -rf $out/internal_hdr
-    rm -rf $out/usr
-    rm -rf $out/local
+    rm -rf $out/internal_hdr $out/usr $out/local
 
     # Add some symlinks
     ln -s $out/Library/Frameworks/System.framework/Versions/B \
@@ -123,8 +120,18 @@ appleDerivation {
     ln -s $out/Library/Frameworks/System.framework/Versions/Current/PrivateHeaders \
           $out/Library/Frameworks/System.framework/Headers
 
-    # IOKit (and possibly the others) is incomplete, so let's not make it visible from here...
+    # IOKit (and possibly the others) is incomplete,
+    # so let's not make it visible from here...
     mkdir $out/Library/PrivateFrameworks
     mv $out/Library/Frameworks/IOKit.framework $out/Library/PrivateFrameworks
   '';
-}
+} // lib.optionalAttrs headersOnly {
+  HOST_CODESIGN = "echo";
+  HOST_CODESIGN_ALLOCATE = "echo";
+  LIPO = "echo";
+  LIBTOOL = "echo";
+  CTFCONVERT = "echo";
+  CTFMERGE = "echo";
+  CTFINSERT = "echo";
+  NMEDIT = "echo";
+})
diff --git a/pkgs/os-specific/darwin/binutils/default.nix b/pkgs/os-specific/darwin/binutils/default.nix
index 3b5e8f1207a..9f9a0c74724 100644
--- a/pkgs/os-specific/darwin/binutils/default.nix
+++ b/pkgs/os-specific/darwin/binutils/default.nix
@@ -35,7 +35,7 @@ stdenv.mkDerivation {
       ln -sf "${cctools}/bin/$i" "$out/bin/$i"
     done
 
-    ln -s ${llvm}/bin/llvm-dsymutil $out/bin/dsymutil
+    ln -s ${llvm}/bin/dsymutil $out/bin/dsymutil
 
     ln -s ${binutils-unwrapped.out}/share $out/share
 
diff --git a/pkgs/os-specific/darwin/cctools/apfs.patch b/pkgs/os-specific/darwin/cctools/apfs.patch
new file mode 100644
index 00000000000..8c6b3c0d273
--- /dev/null
+++ b/pkgs/os-specific/darwin/cctools/apfs.patch
@@ -0,0 +1,22 @@
+diff --git a/cctools/ld64/src/ld/OutputFile.cpp b/cctools/ld64/src/ld/OutputFile.cpp
+index 8859882..158c7d2 100644
+--- a/cctools/ld64/src/ld/OutputFile.cpp
++++ b/cctools/ld64/src/ld/OutputFile.cpp
+@@ -2786,7 +2786,7 @@ void OutputFile::writeOutputFile(ld::Internal& state)
+ #ifdef __APPLE__ // ld64-port
+ 			struct statfs fsInfo;
+ 			if ( statfs(_options.outputFilePath(), &fsInfo) != -1 ) {
+-				if ( strcmp(fsInfo.f_fstypename, "hfs") == 0) {
++				if ( (strcmp(fsInfo.f_fstypename, "hfs") == 0) || (strcmp(fsInfo.f_fstypename, "apfs") == 0) ) {
+ 					(void)unlink(_options.outputFilePath());
+ 					outputIsMappableFile = true;
+ 				}
+@@ -2814,7 +2814,7 @@ void OutputFile::writeOutputFile(ld::Internal& state)
+ #ifdef __APPLE__ // ld64-port
+ 			struct statfs fsInfo;
+ 			if ( statfs(dirPath, &fsInfo) != -1 ) {
+-				if ( strcmp(fsInfo.f_fstypename, "hfs") == 0) {
++				if ( (strcmp(fsInfo.f_fstypename, "hfs") == 0) || (strcmp(fsInfo.f_fstypename, "apfs") == 0) ) {
+ 					outputIsMappableFile = true;
+ 				}
+ 			}
diff --git a/pkgs/os-specific/darwin/cctools/ld-tbd-v2.patch b/pkgs/os-specific/darwin/cctools/ld-tbd-v2.patch
deleted file mode 100644
index 9aae2be1d03..00000000000
--- a/pkgs/os-specific/darwin/cctools/ld-tbd-v2.patch
+++ /dev/null
@@ -1,98 +0,0 @@
-diff --git a/cctools/ld64/src/ld/parsers/textstub_dylib_file.cpp b/cctools/ld64/src/ld/parsers/textstub_dylib_file.cpp
-index 09c0e12..ac6b085 100644
---- a/cctools/ld64/src/ld/parsers/textstub_dylib_file.cpp
-+++ b/cctools/ld64/src/ld/parsers/textstub_dylib_file.cpp
-@@ -187,6 +187,7 @@ struct DynamicLibrary {
- 	ld::File::ObjcConstraint _objcConstraint;
- 	Options::Platform _platform;
- 	std::vector<Token> _allowedClients;
-+	std::vector<Token> _allowableClients;
- 	std::vector<Token> _reexportedLibraries;
- 	std::vector<Token> _symbols;
- 	std::vector<Token> _classes;
-@@ -246,6 +247,14 @@ class TBDFile {
- 		});
- 	}
- 
-+	void parseAllowableClients(DynamicLibrary& lib) {
-+		if ( !hasOptionalToken("allowable-clients") )
-+			return;
-+		parseFlowSequence([&](Token name) {
-+			lib._allowableClients.emplace_back(name);
-+		});
-+	}
-+
- 	void parseReexportedDylibs(DynamicLibrary& lib) {
- 		if ( !hasOptionalToken("re-exports") )
- 			return;
-@@ -306,6 +315,21 @@ class TBDFile {
- 		return false;
- 	}
- 
-+	void skipUUIDs(DynamicLibrary& lib) {
-+		expectToken("uuids");
-+		while ( true ) {
-+			auto token = next();
-+			if ( token == "]" )
-+				break;
-+		}
-+	}
-+
-+	void skipParentUmbrella(DynamicLibrary& lib) {
-+		if (!hasOptionalToken("parent-umbrella"))
-+			return;
-+		next();
-+	}
-+
- 	void parsePlatform(DynamicLibrary& lib) {
- 		expectToken("platform");
- 
-@@ -410,6 +434,7 @@ class TBDFile {
- 			}
- 
- 			parseAllowedClients(lib);
-+			parseAllowableClients(lib);
- 			parseReexportedDylibs(lib);
- 			parseSymbols(lib);
- 			if ( !hasOptionalToken("-") )
-@@ -455,17 +480,21 @@ class TBDFile {
- 			return result.front();
- 	}
- 
--	void parseDocument(DynamicLibrary& lib, std::string &requestedArchName) {
-+	void parseDocument(DynamicLibrary& lib, std::string &requestedArchName, bool isTbdV2) {
- 		auto selectedArchName = parseAndSelectArchitecture(requestedArchName);
- 		if (selectedArchName.empty())
- 			throwf("invalid arch");
- 
-+		if(isTbdV2)
-+			skipUUIDs(lib);
- 		parsePlatform(lib);
- 		parseInstallName(lib);
- 		parseCurrentVersion(lib);
- 		parseCompatibilityVersion(lib);
- 		parseSwiftVersion(lib);
- 		parseObjCConstraint(lib);
-+		if(isTbdV2)
-+			skipParentUmbrella(lib);
- 		parseExportsBlock(lib, selectedArchName);
- 	}
- 
-@@ -476,7 +505,8 @@ public:
- 		_tokenizer.reset();
- 		DynamicLibrary lib;
- 		expectToken("---");
--		parseDocument(lib, requestedArchName);
-+		auto isTbdV2 = hasOptionalToken("!tapi-tbd-v2");
-+		parseDocument(lib, requestedArchName, isTbdV2);
- 		expectToken("...");
- 		return lib;
- 	}
-@@ -486,6 +516,7 @@ public:
- 		auto token = next();
- 		if ( token != "---" )
- 			return false;
-+		hasOptionalToken("!tapi-tbd-v2");
- 		return !parseAndSelectArchitecture(requestedArchName).empty();
- 	}
- 
diff --git a/pkgs/os-specific/darwin/cctools/port.nix b/pkgs/os-specific/darwin/cctools/port.nix
index caf85b227be..43a9495c3ab 100644
--- a/pkgs/os-specific/darwin/cctools/port.nix
+++ b/pkgs/os-specific/darwin/cctools/port.nix
@@ -1,18 +1,11 @@
-{ stdenv, fetchFromGitHub, autoconf, automake, libtool_2, autoreconfHook
+{ stdenv, fetchFromGitHub, autoconf, automake, libtool, autoreconfHook
 , libcxxabi, libuuid, llvm
 , libobjc ? null, maloader ? null
-, enableDumpNormalizedLibArgs ? false
+, enableTapiSupport ? true, libtapi
 }:
 
 let
 
-  # We need to use an old version of cctools-port to support linking TBD files
-  # in the iOS SDK. Note that this only provides support for SDK versions up to
-  # 10.x. For 11.0 and higher we will need to upgrade to a newer cctools than the
-  # default version here, which can support the new TBD format via Apple's
-  # libtapi.
-  useOld = stdenv.targetPlatform.isiOS;
-
   # The targetPrefix prepended to binary names to allow multiple binuntils on the
   # PATH to both be usable.
   targetPrefix = stdenv.lib.optionalString
@@ -23,47 +16,28 @@ in
 # Non-Darwin alternatives
 assert (!stdenv.hostPlatform.isDarwin) -> maloader != null;
 
-assert enableDumpNormalizedLibArgs -> (!useOld);
-
 let
   baseParams = rec {
     name = "${targetPrefix}cctools-port-${version}";
-    version = if useOld then "886" else "895";
+    version = "895";
 
-    src = fetchFromGitHub (if enableDumpNormalizedLibArgs then {
-      owner  = "tpoechtrager";
-      repo   = "cctools-port";
-      # master with https://github.com/tpoechtrager/cctools-port/pull/34
-      rev    = "8395d4b2c3350356e2fb02f5e04f4f463c7388df";
-      sha256 = "10vbf1cfzx02q8chc77s84fp2kydjpx2y682mr6mrbb7sq5rwh8f";
-    } else if useOld then {
-      owner  = "tpoechtrager";
-      repo   = "cctools-port";
-      rev    = "02f0b8ecd87a3951653d838a321ae744815e21a5";
-      sha256 = "0bzyabzr5dvbxglr74d0kbrk2ij5x7s5qcamqi1v546q1had1wz1";
-    } else {
+    src = fetchFromGitHub {
       owner  = "tpoechtrager";
       repo   = "cctools-port";
-      rev    = "2e569d765440b8cd6414a695637617521aa2375b"; # From branch 895-ld64-274.2
-      sha256 = "0l45mvyags56jfi24rawms8j2ihbc45mq7v13pkrrwppghqrdn52";
-    });
+      rev    = "07619027f8311fa61b4a549c75994b88739a82d8";
+      sha256 = "12g94hhz5v5bmy2w0zb6fb4bjlmn992gygc60h9nai15kshj2spi";
+    };
 
     outputs = [ "out" "dev" ];
 
-    nativeBuildInputs = [ autoconf automake libtool_2 autoreconfHook ];
+    nativeBuildInputs = [ autoconf automake libtool autoreconfHook ];
     buildInputs = [ libuuid ]
-      ++ stdenv.lib.optionals stdenv.isDarwin [ libcxxabi libobjc ];
-
-    patches = [
-      ./ld-rpath-nonfinal.patch ./ld-ignore-rpath-link.patch
-    ] ++ stdenv.lib.optionals useOld [
-      # See https://github.com/tpoechtrager/cctools-port/issues/24. Remove when that's fixed.
-      ./undo-unknown-triple.patch
-      ./ld-tbd-v2.patch
-      ./support-ios.patch
-    ];
+      ++ stdenv.lib.optionals stdenv.isDarwin [ libcxxabi libobjc ]
+      ++ stdenv.lib.optional enableTapiSupport libtapi;
 
-    __propagatedImpureHostDeps = stdenv.lib.optionals (!useOld) [
+    patches = [ ./ld-rpath-nonfinal.patch ./ld-ignore-rpath-link.patch ./apfs.patch ];
+
+    __propagatedImpureHostDeps = [
       # As far as I can tell, otool from cctools is the only thing that depends on these two, and we should fix them
       "/usr/lib/libobjc.A.dylib"
       "/usr/lib/libobjc.dylib"
@@ -74,9 +48,15 @@ let
     # TODO(@Ericson2314): Always pass "--target" and always targetPrefix.
     configurePlatforms = [ "build" "host" ]
       ++ stdenv.lib.optional (stdenv.targetPlatform != stdenv.hostPlatform) "target";
-    configureFlags = [ "--disable-clang-as" ];
-
-    postPatch = ''
+    configureFlags = [ "--disable-clang-as" ]
+      ++ stdenv.lib.optionals enableTapiSupport [
+        "--enable-tapi-support"
+        "--with-libtapi=${libtapi}"
+      ];
+
+    postPatch = stdenv.lib.optionalString stdenv.hostPlatform.isDarwin ''
+      substituteInPlace cctools/Makefile.am --replace libobjc2 ""
+    '' + ''
       sed -i -e 's/addStandardLibraryDirectories = true/addStandardLibraryDirectories = false/' cctools/ld64/src/ld/Options.cpp
 
       # FIXME: there are far more absolute path references that I don't want to fix right now
diff --git a/pkgs/os-specific/darwin/cctools/support-ios.patch b/pkgs/os-specific/darwin/cctools/support-ios.patch
deleted file mode 100644
index f78c6b63ac8..00000000000
--- a/pkgs/os-specific/darwin/cctools/support-ios.patch
+++ /dev/null
@@ -1,13 +0,0 @@
-diff --git a/cctools/configure.ac b/cctools/configure.ac
-index 56e8f24..0b4b3ff 100644
---- a/cctools/configure.ac
-+++ b/cctools/configure.ac
-@@ -39,7 +39,7 @@ EXTRACXXFLAGS=""
- WARNINGS=""
- 
- case $host_os in
--  darwin* )
-+  darwin* | ios*)
-     isdarwin=yes
-     AM_CONDITIONAL([ISDARWIN], [true])
-   ;;
diff --git a/pkgs/os-specific/darwin/cctools/undo-unknown-triple.patch b/pkgs/os-specific/darwin/cctools/undo-unknown-triple.patch
deleted file mode 100644
index 7df9bdd16da..00000000000
--- a/pkgs/os-specific/darwin/cctools/undo-unknown-triple.patch
+++ /dev/null
@@ -1,17 +0,0 @@
-diff --git a/cctools/as/driver.c b/cctools/as/driver.c
-index b06d085..c03397a 100644
---- a/cctools/as/driver.c
-+++ b/cctools/as/driver.c
-@@ -363,12 +363,6 @@ char **envp)
- 	    /* Add -c or clang will run ld(1). */
- 	    new_argv[j] = "-c";
- 	    j++;
--	    /* cctools-port start */
--	    new_argv[j] = "-target";
--	    j++;
--	    new_argv[j] = "unknown-apple-darwin";
--	    j++;
--	    /* cctools-port end */
- 	    new_argv[j] = NULL;
- 	    if(execute(new_argv, verbose))
- 		exit(0);
diff --git a/pkgs/os-specific/darwin/cf-private/default.nix b/pkgs/os-specific/darwin/cf-private/default.nix
index dc1b0112a21..eb5f651a1a0 100644
--- a/pkgs/os-specific/darwin/cf-private/default.nix
+++ b/pkgs/os-specific/darwin/cf-private/default.nix
@@ -1,4 +1,4 @@
-{ CF, apple_sdk, osx_private_sdk }:
+{ CF, apple_sdk }:
 
 # cf-private is a bit weird, but boils down to CF with a weird setup-hook that
 # makes a build link against the system CoreFoundation rather than our pure one.
@@ -38,10 +38,7 @@ CF.overrideAttrs (orig: {
   # this is watchman, who can almost certainly switch to the pure CF once the header
   # and functionality is merged in.
   installPhase = orig.installPhase + ''
-    # Copy or overwrite private headers, some of these might already
-    # exist in CF but the private versions have more information.
     basepath="Library/Frameworks/CoreFoundation.framework/Headers"
-    cp -Lfv --no-preserve mode ${osx_private_sdk}/include/CoreFoundationPrivateHeaders/* "$out/$basepath"
 
     # Append the include at top level or nobody will notice the header we're about to add
     sed -i '/CFNotificationCenter.h/a #include <CoreFoundation/CFFileDescriptor.h>' \
diff --git a/pkgs/os-specific/darwin/darling/default.nix b/pkgs/os-specific/darwin/darling/default.nix
index 6ed3b28eccc..846831d0a87 100644
--- a/pkgs/os-specific/darwin/darling/default.nix
+++ b/pkgs/os-specific/darwin/darling/default.nix
@@ -26,6 +26,9 @@ stdenv.mkDerivation rec {
     mkdir -p $out/lib
     cp -rL src/sandbox/include/ $out/
     cp libsystem_sandbox.dylib $out/lib/
+
+    mkdir -p $out/include
+    cp src/libaks/include/* $out/include
   '';
 
   # buildInputs = [ cmake bison flex ];
diff --git a/pkgs/os-specific/darwin/libtapi/default.nix b/pkgs/os-specific/darwin/libtapi/default.nix
new file mode 100644
index 00000000000..e68e77f55af
--- /dev/null
+++ b/pkgs/os-specific/darwin/libtapi/default.nix
@@ -0,0 +1,29 @@
+{ lib, stdenv, fetchFromGitHub, cmake, python }:
+
+stdenv.mkDerivation {
+  name = "libtapi";
+  src = fetchFromGitHub {
+    owner = "tpoechtrager";
+    repo = "apple-libtapi";
+    rev = "e56673694db395e25b31808b4fbb9a7005e6875f";
+    sha256 = "1lnl1af9sszp9wxfk0wljrpdmwcx83j0w5c0y4qw4pqrdkdgwks7";
+  };
+
+  nativeBuildInputs = [ cmake python ];
+
+  preConfigure = ''
+    cd src/apple-llvm/src
+  '';
+
+  cmakeFlags = [ "-DLLVM_INCLUDE_TESTS=OFF" ];
+
+  buildFlags = "libtapi";
+
+  installTarget = "install-libtapi";
+
+  meta = with lib; {
+    license = licenses.apsl20;
+    maintainers = with maintainers; [ matthewbauer ];
+  };
+
+}
diff --git a/pkgs/os-specific/darwin/osx-private-sdk/default.nix b/pkgs/os-specific/darwin/osx-private-sdk/default.nix
deleted file mode 100644
index 115512a6feb..00000000000
--- a/pkgs/os-specific/darwin/osx-private-sdk/default.nix
+++ /dev/null
@@ -1,27 +0,0 @@
-{ stdenv, fetchFromGitHub }:
-
-stdenv.mkDerivation {
-  name = "OSXPrivateSDK";
-
-  src = fetchFromGitHub {
-    owner = "samdmarshall";
-    repo = "OSXPrivateSDK";
-    rev = "f4d52b60e86b496abfaffa119a7d299562d99783";
-    sha256 = "0bv0884yxpvk2ishxj8gdy1w6wb0gwfq55q5qjp0s8z0z7f63zqh";
-  };
-
-  # NOTE: we install only headers that are really needed to keep closure size
-  # reasonable.
-  installPhase = ''
-    mkdir -p $out/include
-    sdk10=PrivateSDK10.10.sparse.sdk
-    sdk=PrivateSDK10.9.sparse.sdk
-    cp $sdk/usr/local/include/sandbox_private.h $out/include/sandbox_private.h
-    # this can be removed once we dtrace binary
-    cp $sdk/usr/local/include/security_utilities/utilities_dtrace.h $out/include/utilities_dtrace.h
-    cp -RL $sdk/usr/include/xpc $out/include/xpc
-    cp -RL $sdk/usr/local/include/bsm $out/include/bsm
-    cp -RL $sdk/System/Library/Frameworks/Security.framework/Versions/A/PrivateHeaders $out/include/SecurityPrivateHeaders
-    cp -RL $sdk10/System/Library/Frameworks/CoreFoundation.framework/Headers $out/include/CoreFoundationPrivateHeaders
-  '';
-}
diff --git a/pkgs/os-specific/darwin/security-tool/GNUmakefile b/pkgs/os-specific/darwin/security-tool/GNUmakefile
deleted file mode 100644
index ae25f6a67c0..00000000000
--- a/pkgs/os-specific/darwin/security-tool/GNUmakefile
+++ /dev/null
@@ -1,14 +0,0 @@
-include $(GNUSTEP_MAKEFILES)/common.make
-
-TOOL_NAME = security
-security_C_FILES = $(wildcard *.c)
-security_CC_FILES = $(wildcard *.cpp)
-
-security_LDFLAGS = \
-	-lsecurity_cdsa_utilities -lsecurity_cdsa_utils -lsecurity_keychain -lsecurity_cssm \
-	-lsecurity_cdsa_client -lsecurity_utilities -lsecurity_asn1 -lsecurity_mds \
-	-lsecurity_cdsa_plugin -lsecurity_pkcs12 -lsecurity_apple_csp -lsecurity_apple_cspdl \
-	-lsecurity_apple_file_dl -lsecurity_apple_x509_cl -lsecurity_apple_x509_tp \
-	-lsecurity_sd_cspdl -lsecurity_filedb -lsecurityd -framework Security -framework PCSC
-
-include $(GNUSTEP_MAKEFILES)/tool.make
diff --git a/pkgs/os-specific/darwin/security-tool/default.nix b/pkgs/os-specific/darwin/security-tool/default.nix
deleted file mode 100644
index f161a7a88e1..00000000000
--- a/pkgs/os-specific/darwin/security-tool/default.nix
+++ /dev/null
@@ -1,101 +0,0 @@
-{ Foundation, PCSC, Security, GSS, Kerberos, makeWrapper, apple_sdk,
-fetchurl, gnustep, libobjc, libsecurity_apple_csp, libsecurity_apple_cspdl,
-libsecurity_apple_file_dl, libsecurity_apple_x509_cl, libsecurity_apple_x509_tp,
-libsecurity_asn1, libsecurity_cdsa_client, libsecurity_cdsa_plugin,
-libsecurity_cdsa_utilities, libsecurity_cdsa_utils, libsecurity_cssm, libsecurity_filedb,
-libsecurity_keychain, libsecurity_mds, libsecurity_pkcs12, libsecurity_sd_cspdl,
-libsecurity_utilities, libsecurityd, osx_private_sdk, Security-framework, stdenv }:
-
-stdenv.mkDerivation rec {
-  version = "55115";
-  name = "SecurityTool-${version}";
-
-  src = fetchurl {
-    url = "http://opensource.apple.com/tarballs/SecurityTool/SecurityTool-${version}.tar.gz";
-    sha256 = "0apcz4vy2z5645jhrs60wj3w27mncjjqv42h5lln36g6qs2n9113";
-  };
-
-  disallowedRequisites = [ apple_sdk.sdk  ];
-
-  patchPhase = ''
-    # copied from libsecurity_generic
-    cp -R ${osx_private_sdk}/include/SecurityPrivateHeaders Security
-
-    substituteInPlace cmsutil.c --replace \
-      '<CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>' \
-      '"${apple_sdk.sdk.out}/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Headers/MacErrors.h"'
-    substituteInPlace createFVMaster.c --replace \
-      '<CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>' \
-      '"${apple_sdk.sdk.out}/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Headers/MacErrors.h"'
-  '';
-
-  postUnpack = ''
-    unpackFile ${Security.src}
-    cp Security-*/utilities/src/fileIo.c SecurityTool*
-    cp Security-*/utilities/src/fileIo.h SecurityTool*
-  '';
-
-  preBuild = ''
-    makeFlagsArray=(-j$NIX_BUILD_CORES)
-  '';
-
-  NIX_LDFLAGS = "-no_dtrace_dof";
-
-  makeFlags = [
-    "-f ${./GNUmakefile}"
-    "MAKEFILE_NAME=${./GNUmakefile}"
-    "GNUSTEP_MAKEFILES=${gnustep.make}/share/GNUstep/Makefiles"
-  ];
-
-  installFlags = [
-    "security_INSTALL_DIR=\$(out)/bin"
-  ];
-
-  propagatedBuildInputs = [ GSS Kerberos Security-framework PCSC Foundation ];
-
-  __propagatedImpureHostDeps = [ "/System/Library/Keychains" ];
-
-  buildInputs = [
-    gnustep.make
-    libsecurity_asn1
-    libsecurity_utilities
-    libsecurity_cdsa_utilities
-    libobjc
-    libsecurity_cdsa_client
-    libsecurity_keychain
-    libsecurity_cssm
-    libsecurity_cdsa_utils
-    libsecurity_mds
-    libsecurity_cdsa_plugin
-    libsecurity_apple_csp
-    libsecurity_apple_cspdl
-    libsecurity_apple_file_dl
-    libsecurity_apple_x509_cl
-    libsecurity_apple_x509_tp
-    libsecurity_pkcs12
-    libsecurity_sd_cspdl
-    libsecurity_filedb
-    libsecurityd
-    makeWrapper
-  ];
-
-  NIX_CFLAGS_COMPILE = [
-    "-F${Security}/Library/Frameworks"
-    "-F${PCSC}/Library/Frameworks"
-    "-Wno-deprecated-declarations"
-  ];
-
-  postInstall = ''
-    wrapProgram $out/bin/security --set DYLD_INSERT_LIBRARIES /usr/lib/libsqlite3.dylib
-  '';
-
-  meta = with stdenv.lib; {
-    description = "Command line interface to macOS keychains and Security framework";
-    maintainers = with maintainers; [
-      copumpkin
-      joelteon
-    ];
-    platforms = platforms.darwin;
-    license = licenses.apsl20;
-  };
-}
diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix
index b7d8e3ba523..3c3917c827e 100644
--- a/pkgs/stdenv/darwin/default.nix
+++ b/pkgs/stdenv/darwin/default.nix
@@ -132,9 +132,6 @@ in rec {
         extraAttrs = {
           inherit platform;
           parent = last;
-
-          # This is used all over the place so I figured I'd just leave it here for now
-          secure-format-patch = ./darwin-secure-format.patch;
         };
         overrides  = self: super: (overrides self super) // { fetchurl = thisStdenv.fetchurlBoot; };
       };
@@ -158,7 +155,7 @@ in rec {
         dyld = bootstrapTools;
       };
 
-      llvmPackages_5 = {
+      llvmPackages_7 = {
         libcxx = stdenv.mkDerivation {
           name = "bootstrap-stage0-libcxx";
           phases = [ "installPhase" "fixupPhase" ];
@@ -200,7 +197,12 @@ in rec {
       python2 = self.python;
 
       ninja = super.ninja.override { buildDocs = false; };
-      darwin = super.darwin // { cctools = super.darwin.cctools.override { llvm = null; }; };
+      darwin = super.darwin // {
+        cctools = super.darwin.cctools.override {
+          llvm = null;
+          enableTapiSupport = false;
+        };
+      };
     };
   in with prevStage; stageFun 1 prevStage {
     extraPreHook = "export NIX_CFLAGS_COMPILE+=\" -F${bootstrapTools}/Library/Frameworks\"";
@@ -260,9 +262,9 @@ in rec {
       # Avoid pulling in a full python and its extra dependencies for the llvm/clang builds.
       libxml2 = super.libxml2.override { pythonSupport = false; };
 
-      llvmPackages_5 = super.llvmPackages_5 // (let
-        libraries = super.llvmPackages_5.libraries.extend (_: _: {
-          inherit (llvmPackages_5) libcxx libcxxabi;
+      llvmPackages_7 = super.llvmPackages_7 // (let
+        libraries = super.llvmPackages_7.libraries.extend (_: _: {
+          inherit (llvmPackages_7) libcxx libcxxabi;
         });
       in { inherit libraries; } // libraries);
 
@@ -278,8 +280,8 @@ in rec {
     # enables patchShebangs above. Unfortunately, patchShebangs ignores our $SHELL setting
     # and instead goes by $PATH, which happens to contain bootstrapTools. So it goes and
     # patches our shebangs back to point at bootstrapTools. This makes sure bash comes first.
-    extraNativeBuildInputs = with pkgs; [ xz pkgs.bash ];
-    extraBuildInputs = [ pkgs.darwin.CF ];
+    extraNativeBuildInputs = with pkgs; [ xz ];
+    extraBuildInputs = [ pkgs.darwin.CF pkgs.bash ];
     libcxx = pkgs.libcxx;
 
     extraPreHook = ''
@@ -314,18 +316,20 @@ in rec {
         ];
       });
 
-      llvmPackages_5 = super.llvmPackages_5 // (let
-        tools = super.llvmPackages_5.tools.extend (llvmSelf: _: {
-          inherit (llvmPackages_5) llvm clang-unwrapped;
+      llvmPackages_7 = super.llvmPackages_7 // (let
+        tools = super.llvmPackages_7.tools.extend (llvmSelf: _: {
+          clang-unwrapped = llvmPackages_7.clang-unwrapped.override { llvm = llvmSelf.llvm; };
+          llvm = llvmPackages_7.llvm.override { libxml2 = self.darwin.libxml2-nopython; };
         });
-        libraries = super.llvmPackages_5.libraries.extend (llvmSelf: _: {
-          inherit (llvmPackages_5) libcxx libcxxabi compiler-rt;
+        libraries = super.llvmPackages_7.libraries.extend (llvmSelf: _: {
+          inherit (llvmPackages_7) libcxx libcxxabi compiler-rt;
         });
       in { inherit tools libraries; } // tools // libraries);
 
       darwin = super.darwin // rec {
         inherit (darwin) dyld Libsystem libiconv locale;
 
+        cctools = super.darwin.cctools.override { enableTapiSupport = false; };
         libxml2-nopython = super.libxml2.override { pythonSupport = false; };
         CF = super.darwin.CF.override {
           libxml2 = libxml2-nopython;
@@ -335,8 +339,8 @@ in rec {
     };
   in with prevStage; stageFun 4 prevStage {
     shell = "${pkgs.bash}/bin/bash";
-    extraNativeBuildInputs = with pkgs; [ xz pkgs.bash ];
-    extraBuildInputs = [ pkgs.darwin.CF ];
+    extraNativeBuildInputs = with pkgs; [ xz ];
+    extraBuildInputs = [ pkgs.darwin.CF pkgs.bash ];
     libcxx = pkgs.libcxx;
 
     extraPreHook = ''
@@ -353,12 +357,12 @@ in rec {
         ncurses libffi zlib llvm gmp pcre gnugrep
         coreutils findutils diffutils patchutils;
 
-      llvmPackages_5 = super.llvmPackages_5 // (let
-        tools = super.llvmPackages_5.tools.extend (_: super: {
-          inherit (llvmPackages_5) llvm clang-unwrapped;
+      llvmPackages_7 = super.llvmPackages_7 // (let
+        tools = super.llvmPackages_7.tools.extend (_: super: {
+          inherit (llvmPackages_7) llvm clang-unwrapped;
         });
-        libraries = super.llvmPackages_5.libraries.extend (_: _: {
-          inherit (llvmPackages_5) compiler-rt libcxx libcxxabi;
+        libraries = super.llvmPackages_7.libraries.extend (_: _: {
+          inherit (llvmPackages_7) compiler-rt libcxx libcxxabi;
         });
       in { inherit tools libraries; } // tools // libraries);
 
@@ -414,9 +418,6 @@ in rec {
       inherit platform bootstrapTools;
       libc         = pkgs.darwin.Libsystem;
       shellPackage = pkgs.bash;
-
-      # This is used all over the place so I figured I'd just leave it here for now
-      secure-format-patch = ./darwin-secure-format.patch;
     };
 
     allowedRequisites = (with pkgs; [
diff --git a/pkgs/stdenv/darwin/make-bootstrap-tools.nix b/pkgs/stdenv/darwin/make-bootstrap-tools.nix
index 670215a735d..cfa8aac0578 100644
--- a/pkgs/stdenv/darwin/make-bootstrap-tools.nix
+++ b/pkgs/stdenv/darwin/make-bootstrap-tools.nix
@@ -3,7 +3,7 @@
 with import pkgspath { inherit system; };
 
 let
-  llvmPackages = llvmPackages_5;
+  llvmPackages = llvmPackages_7;
 in rec {
   coreutils_ = coreutils.override (args: {
     # We want coreutils without ACL support.
@@ -80,14 +80,14 @@ in rec {
       cp -d ${libxml2.out}/lib/libxml2*.dylib $out/lib
 
       # Copy what we need of clang
-      cp -d ${llvmPackages.clang-unwrapped}/bin/clang $out/bin
-      cp -d ${llvmPackages.clang-unwrapped}/bin/clang++ $out/bin
-      cp -d ${llvmPackages.clang-unwrapped}/bin/clang-[0-9].[0-9] $out/bin
+      cp -d ${llvmPackages.clang-unwrapped}/bin/clang* $out/bin
 
       cp -rL ${llvmPackages.clang-unwrapped}/lib/clang $out/lib
 
       cp -d ${llvmPackages.libcxx}/lib/libc++*.dylib $out/lib
       cp -d ${llvmPackages.libcxxabi}/lib/libc++abi*.dylib $out/lib
+      cp -d ${llvmPackages.llvm.lib}/lib/libLLVM.dylib $out/lib
+      cp -d ${libffi}/lib/libffi*.dylib $out/lib
 
       mkdir $out/include
       cp -rd ${llvmPackages.libcxx}/include/c++     $out/include
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh
index 8dff3557807..6f1a654a38a 100644
--- a/pkgs/stdenv/generic/setup.sh
+++ b/pkgs/stdenv/generic/setup.sh
@@ -182,10 +182,8 @@ addToSearchPathWithCustomDelimiter() {
     fi
 }
 
-PATH_DELIMITER=':'
-
 addToSearchPath() {
-    addToSearchPathWithCustomDelimiter "${PATH_DELIMITER}" "$@"
+    addToSearchPathWithCustomDelimiter ":" "$@"
 }
 
 # Add $1/lib* into rpaths.
@@ -508,7 +506,7 @@ activatePackage() {
     fi
 
     if [[ "$hostOffset" -eq 0 && -d "$pkg/bin" ]]; then
-        addToSearchPath HOST_PATH "$pkg/bin"
+        addToSearchPath _HOST_PATH "$pkg/bin"
     fi
 
     if [[ -f "$pkg/nix-support/setup-hook" ]]; then
@@ -617,10 +615,15 @@ fi
 
 
 PATH="${_PATH-}${_PATH:+${PATH:+:}}$PATH"
+HOST_PATH="${_HOST_PATH-}${_HOST_PATH:+${HOST_PATH:+:}}$HOST_PATH"
 if (( "${NIX_DEBUG:-0}" >= 1 )); then
     echo "final path: $PATH"
+    echo "final host path: $HOST_PATH"
 fi
 
+unset _PATH
+unset _HOST_PATH
+
 
 # Make GNU Make produce nested output.
 export NIX_INDENT_MAKE=1
diff --git a/pkgs/tools/archivers/gnutar/default.nix b/pkgs/tools/archivers/gnutar/default.nix
index b64696a3420..c2e7f75fc7f 100644
--- a/pkgs/tools/archivers/gnutar/default.nix
+++ b/pkgs/tools/archivers/gnutar/default.nix
@@ -13,6 +13,7 @@ stdenv.mkDerivation rec {
   configureFlags = stdenv.lib.optionals stdenv.isDarwin [
     "gt_cv_func_CFPreferencesCopyAppValue=no"
     "gt_cv_func_CFLocaleCopyCurrent=no"
+    "gt_cv_func_CFLocaleCopyPreferredLanguages=no"
   ];
 
   # gnutar tries to call into gettext between `fork` and `exec`,
diff --git a/pkgs/tools/archivers/p7zip/default.nix b/pkgs/tools/archivers/p7zip/default.nix
index 5430c2cb73e..3dac4245de4 100644
--- a/pkgs/tools/archivers/p7zip/default.nix
+++ b/pkgs/tools/archivers/p7zip/default.nix
@@ -37,6 +37,8 @@ stdenv.mkDerivation rec {
 
   setupHook = ./setup-hook.sh;
 
+  NIX_CFLAGS_COMPILE = "-Wno-error=c++11-narrowing";
+
   meta = {
     homepage = http://p7zip.sourceforge.net/;
     description = "A port of the 7-zip archiver";
diff --git a/pkgs/tools/compression/pbzip2/default.nix b/pkgs/tools/compression/pbzip2/default.nix
index fb3da5e48d6..c7c1b7efc94 100644
--- a/pkgs/tools/compression/pbzip2/default.nix
+++ b/pkgs/tools/compression/pbzip2/default.nix
@@ -17,6 +17,8 @@ stdenv.mkDerivation rec {
 
   installFlags = "PREFIX=$(out)";
 
+  NIX_CFLAGS_COMPILE = "-Wno-error=reserved-user-defined-literal";
+
   meta = with stdenv.lib; {
     homepage = http://compression.ca/pbzip2/;
     description = "A parallel implementation of bzip2 for multi-core machines";
diff --git a/pkgs/tools/filesystems/e2fsprogs/default.nix b/pkgs/tools/filesystems/e2fsprogs/default.nix
index e601a12e6e6..11f107e994f 100644
--- a/pkgs/tools/filesystems/e2fsprogs/default.nix
+++ b/pkgs/tools/filesystems/e2fsprogs/default.nix
@@ -39,7 +39,9 @@ stdenv.mkDerivation rec {
 
   postInstall = ''
     # avoid cycle between outputs
-    mv $out/lib/${pname}/e2scrub_all_cron $bin/bin/
+    if [ -f $out/lib/${pname}/e2scrub_all_cron ]; then
+      mv $out/lib/${pname}/e2scrub_all_cron $bin/bin/
+    fi
   '';
 
   enableParallelBuilding = true;
diff --git a/pkgs/tools/filesystems/file-rename/default.nix b/pkgs/tools/filesystems/file-rename/default.nix
index e799bc5a4da..8dc4ec534a2 100644
--- a/pkgs/tools/filesystems/file-rename/default.nix
+++ b/pkgs/tools/filesystems/file-rename/default.nix
@@ -15,6 +15,8 @@ perlPackages.buildPerlPackage rec {
       --prefix PERL5LIB : $out/${perlPackages.perl.libPrefix}
   '';
 
+  doCheck = !stdenv.isDarwin;
+
   meta = with stdenv.lib; {
     description = "Perl extension for renaming multiple files";
     license = licenses.artistic1;
diff --git a/pkgs/tools/misc/toybox/default.nix b/pkgs/tools/misc/toybox/default.nix
index 98fa06bccfd..1b518be63a5 100644
--- a/pkgs/tools/misc/toybox/default.nix
+++ b/pkgs/tools/misc/toybox/default.nix
@@ -54,6 +54,8 @@ stdenv.mkDerivation rec {
   checkInputs = [ which ]; # used for tests with checkFlags = [ "DEBUG=true" ];
   checkTarget = "tests";
 
+  NIX_CFLAGS_COMPILE = "-Wno-error";
+
   meta = with stdenv.lib; {
     description = "Lightweight implementation of some Unix command line utilities";
     homepage = https://landley.net/toybox/;
diff --git a/pkgs/tools/networking/ntopng/default.nix b/pkgs/tools/networking/ntopng/default.nix
index b307a8f6f13..b1e1bfcdd65 100644
--- a/pkgs/tools/networking/ntopng/default.nix
+++ b/pkgs/tools/networking/ntopng/default.nix
@@ -53,7 +53,7 @@ stdenv.mkDerivation rec {
     sed 's|LIBS += -lstdc++.6||' -i Makefile
   '';
 
-  NIX_CFLAGS_COMPILE = [ "-fpermissive" ];
+  NIX_CFLAGS_COMPILE = [ "-fpermissive" "-Wno-error=reserved-user-defined-literal" ];
 
   meta = with stdenv.lib; {
     description = "High-speed web-based traffic analysis and flow collection tool";
diff --git a/pkgs/tools/package-management/nix/default.nix b/pkgs/tools/package-management/nix/default.nix
index 7590a37a8e3..ca1a38c4ab4 100644
--- a/pkgs/tools/package-management/nix/default.nix
+++ b/pkgs/tools/package-management/nix/default.nix
@@ -3,6 +3,7 @@
 , stateDir ? "/nix/var"
 , confDir ? "/etc"
 , boehmgc
+, llvmPackages_6
 }:
 
 let
@@ -174,6 +175,8 @@ in rec {
     };
 
     inherit storeDir stateDir confDir boehmgc;
+
+    stdenv = llvmPackages_6.stdenv;
   };
 
   nixUnstable = lib.lowPrio (callPackage common rec {
@@ -188,6 +191,8 @@ in rec {
     fromGit = true;
 
     inherit storeDir stateDir confDir boehmgc;
+
+    stdenv = llvmPackages_6.stdenv;
   });
 
 }
diff --git a/pkgs/tools/security/opensc/default.nix b/pkgs/tools/security/opensc/default.nix
index 7d709712fc8..3144665e4ec 100644
--- a/pkgs/tools/security/opensc/default.nix
+++ b/pkgs/tools/security/opensc/default.nix
@@ -21,6 +21,8 @@ stdenv.mkDerivation rec {
     libXt libxslt libiconv docbook_xml_dtd_412
   ] ++ stdenv.lib.optional stdenv.isDarwin Carbon;
 
+  NIX_CFLAGS_COMPILE = "-Wno-error";
+
   configureFlags = [
     "--enable-zlib"
     "--enable-readline"
diff --git a/pkgs/tools/security/tcpcrypt/default.nix b/pkgs/tools/security/tcpcrypt/default.nix
index 7ffec8c4c88..3641472f276 100644
--- a/pkgs/tools/security/tcpcrypt/default.nix
+++ b/pkgs/tools/security/tcpcrypt/default.nix
@@ -1,5 +1,5 @@
 { stdenv, fetchFromGitHub, autoreconfHook
-, openssl
+, openssl, lib
 , libcap, libpcap, libnfnetlink, libnetfilter_conntrack, libnetfilter_queue
 }:
 
@@ -20,8 +20,8 @@ stdenv.mkDerivation rec {
 
   outputs = [ "bin" "dev" "out" ];
   nativeBuildInputs = [ autoreconfHook ];
-  buildInputs = [ openssl ]
-    ++ optionals stdenv.isLinux [ libcap libpcap libnfnetlink libnetfilter_conntrack libnetfilter_queue ];
+  buildInputs = [ openssl libpcap ]
+    ++ optionals stdenv.isLinux [ libcap libnfnetlink libnetfilter_conntrack libnetfilter_queue ];
 
   enableParallelBuilding = true;
 
diff --git a/pkgs/tools/text/platinum-searcher/default.nix b/pkgs/tools/text/platinum-searcher/default.nix
index 829d734a8f7..4b30387f7ac 100644
--- a/pkgs/tools/text/platinum-searcher/default.nix
+++ b/pkgs/tools/text/platinum-searcher/default.nix
@@ -16,11 +16,6 @@ buildGoPackage rec {
 
   goDeps = ./deps.nix;
 
-  preFixup = stdenv.lib.optionalString stdenv.isDarwin ''
-    # fixes cycle between $out and $bin
-    install_name_tool -delete_rpath $out/lib $bin/bin/pt
-  '';
-
   meta = with stdenv.lib; {
     homepage = https://github.com/monochromegane/the_platinum_searcher;
     description = "A code search tool similar to ack and the_silver_searcher(ag).";
diff --git a/pkgs/tools/text/sgml/opensp/default.nix b/pkgs/tools/text/sgml/opensp/default.nix
index 27fa7bb91a8..8d659713d95 100644
--- a/pkgs/tools/text/sgml/opensp/default.nix
+++ b/pkgs/tools/text/sgml/opensp/default.nix
@@ -1,4 +1,5 @@
-{ lib, stdenv, fetchurl, xmlto, docbook_xml_dtd_412, libxslt, docbook_xsl, autoconf, automake, gettext, libiconv, libtool}:
+{ lib, stdenv, fetchurl, fetchpatch, xmlto, docbook_xml_dtd_412
+, libxslt, docbook_xsl, autoconf, automake, gettext, libiconv, libtool}:
 
 stdenv.mkDerivation {
   name = "opensp-1.5.2";
@@ -8,16 +9,18 @@ stdenv.mkDerivation {
     sha256 = "1khpasr6l0a8nfz6kcf3s81vgdab8fm2dj291n5r2s53k228kx2p";
   };
 
-  patchPhase = ''
+  postPatch = ''
     sed -i s,/usr/share/sgml/docbook/xml-dtd-4.1.2/,${docbook_xml_dtd_412}/xml/dtd/docbook/, \
       docsrc/*.xml
   '';
 
-  configureFlags = lib.optional stdenv.isDarwin [
-    "--with-libintl-prefix=/usr"
-    "--with-libiconv-prefix=/usr"
+  patches = [
+    (fetchpatch {
+      url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/app-text/opensp/files/opensp-1.5.2-c11-using.patch?id=688d9675782dfc162d4e6cff04c668f7516118d0";
+      sha256 = "04q14s8qsad0bkjmj067dn831i0r6v7742rafdlnbfm5y249m2q6";
+    })
   ];
-
+  
   setupHook = ./setup-hook.sh;
 
   postFixup = ''
@@ -29,8 +32,9 @@ stdenv.mkDerivation {
   preConfigure = if stdenv.isCygwin then "autoreconf -fi" else null;
 
   # need autoconf, automake, gettext, and libtool for reconfigure
-  buildInputs = stdenv.lib.optionals stdenv.isCygwin [ autoconf automake gettext libiconv libtool ]
-    ++ [ xmlto docbook_xml_dtd_412 libxslt docbook_xsl ];
+  nativeBuildInputs = stdenv.lib.optionals stdenv.isCygwin [ autoconf automake libtool ];
+
+  buildInputs = [ xmlto docbook_xml_dtd_412 libxslt docbook_xsl gettext libiconv ];
 
   doCheck = false; # fails
 
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index cdc3510965f..81e1e6f63ae 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -1291,6 +1291,7 @@ in
   contacts = callPackage ../tools/misc/contacts {
     inherit (darwin) cf-private;
     inherit (darwin.apple_sdk.frameworks) Foundation AddressBook;
+    xcbuildHook = xcbuild6Hook;
   };
 
   compsize = callPackage ../os-specific/linux/compsize { };
@@ -3388,7 +3389,9 @@ in
     hdf4 = null;
   };
 
-  haproxy = callPackage ../tools/networking/haproxy { };
+  haproxy = callPackage ../tools/networking/haproxy {
+    stdenv = if stdenv.cc.isClang then llvmPackages_6.stdenv else stdenv;
+  };
 
   haveged = callPackage ../tools/security/haveged { };
 
@@ -4479,7 +4482,9 @@ in
     docbook-xsl = docbook_xsl;
   };
 
-  mosh = callPackage ../tools/networking/mosh { };
+  mosh = callPackage ../tools/networking/mosh {
+    stdenv = if stdenv.cc.isClang then llvmPackages_6.stdenv else stdenv;
+  };
 
   motuclient = callPackage ../applications/science/misc/motu-client { };
 
@@ -5088,6 +5093,7 @@ in
   pinentry_mac = callPackage ../tools/security/pinentry/mac.nix {
     inherit (darwin) cf-private;
     inherit (darwin.apple_sdk.frameworks) Cocoa;
+    xcbuildHook = xcbuild6Hook;
   };
 
   pingtcp = callPackage ../tools/networking/pingtcp { };
@@ -5261,7 +5267,9 @@ in
 
   remarshal = callPackage ../development/tools/remarshal { };
 
-  rig = callPackage ../tools/misc/rig { };
+  rig = callPackage ../tools/misc/rig {
+    stdenv = gccStdenv;
+  };
 
   rocket = libsForQt5.callPackage ../tools/graphics/rocket { };
 
@@ -5773,7 +5781,7 @@ in
 
   fusesmb = callPackage ../tools/filesystems/fusesmb { samba = samba3; };
 
-  sl = callPackage ../tools/misc/sl { };
+  sl = callPackage ../tools/misc/sl { stdenv = gccStdenv; };
 
   socat = callPackage ../tools/networking/socat { };
 
@@ -6898,7 +6906,9 @@ in
     inherit (buildPackages.darwin) bootstrap_cmds;
   };
 
-  cdb = callPackage ../development/tools/database/cdb { };
+  cdb = callPackage ../development/tools/database/cdb {
+    stdenv = gccStdenv;
+  };
 
   chez = callPackage ../development/compilers/chez {
     inherit (darwin) cctools;
@@ -6911,11 +6921,6 @@ in
     name = "clang-wrapper-with-reexport-hack";
     bintools = darwin.binutils.override {
       useMacosReexportHack = true;
-      bintools = darwin.binutils.bintools.override {
-        cctools = darwin.cctools.override {
-          enableDumpNormalizedLibArgs = true;
-        };
-      };
     };
   };
   llvm-polly = llvmPackages_latest.llvm-polly;
@@ -6961,7 +6966,10 @@ in
 
   cryptol = haskell.lib.justStaticExecutables haskellPackages.cryptol;
 
-  inherit (callPackages ../development/compilers/crystal {})
+  inherit (callPackages ../development/compilers/crystal {
+    stdenv = if stdenv.cc.isClang then llvmPackages_6.stdenv else stdenv;
+    inherit (llvmPackages_6) clang llvm;
+  })
     crystal_0_25
     crystal_0_26
     crystal;
@@ -7575,7 +7583,7 @@ in
   llvm_37 = llvmPackages_37.llvm;
   llvm_35 = llvmPackages_35.llvm;
 
-  llvmPackages = recurseIntoAttrs llvmPackages_5;
+  llvmPackages = recurseIntoAttrs llvmPackages_7;
 
   llvmPackages_35 = callPackage ../development/compilers/llvm/3.5 ({
     isl = isl_0_14;
@@ -7888,7 +7896,9 @@ in
 
   tinycc = callPackage ../development/compilers/tinycc { };
 
-  tinyscheme = callPackage ../development/interpreters/tinyscheme { };
+  tinyscheme = callPackage ../development/interpreters/tinyscheme {
+    stdenv = gccStdenv;
+  };
 
   inherit (ocaml-ng.ocamlPackages_4_02) trv;
 
@@ -8138,7 +8148,9 @@ in
 
   lush2 = callPackage ../development/interpreters/lush {};
 
-  maude = callPackage ../development/interpreters/maude { };
+  maude = callPackage ../development/interpreters/maude {
+    stdenv = if stdenv.cc.isClang then llvmPackages_5.stdenv else stdenv;
+  };
 
   me_cleaner = pythonPackages.callPackage ../tools/misc/me_cleaner { };
 
@@ -8217,11 +8229,13 @@ in
     php = php72-unit;
   });
 
-   php73Packages-unit = recurseIntoAttrs (callPackage ./php-packages.nix {
+  php73Packages-unit = recurseIntoAttrs (callPackage ./php-packages.nix {
     php = php73-unit;
   });
 
-  inherit (callPackages ../development/interpreters/php { })
+  inherit (callPackages ../development/interpreters/php {
+    stdenv = if stdenv.cc.isClang then llvmPackages_6.stdenv else stdenv;
+  })
     php71
     php72
     php73;
@@ -8796,9 +8810,7 @@ in
 
   cmake_2_8 = callPackage ../development/tools/build-managers/cmake/2.8.nix { };
 
-  cmake = libsForQt5.callPackage ../development/tools/build-managers/cmake {
-    inherit (darwin) cf-private;
-  };
+  cmake = libsForQt5.callPackage ../development/tools/build-managers/cmake { };
 
   cmakeCurses = cmake.override { useNcurses = true; };
 
@@ -8827,9 +8839,11 @@ in
   cpplint = callPackage ../development/tools/analysis/cpplint { };
 
   cquery = callPackage ../development/tools/misc/cquery {
-    llvmPackages = llvmPackages_latest;
+    # 7 is the default, but only on Linux, so keep this for now
+    llvmPackages = llvmPackages_7;
   };
 
+
   ccls = callPackage ../development/tools/misc/ccls {
     llvmPackages = llvmPackages_7;
     stdenv = llvmPackages_7.stdenv;
@@ -9566,11 +9580,17 @@ in
   xcodebuild = callPackage ../development/tools/xcbuild/wrapper.nix {
     inherit (darwin.apple_sdk.frameworks) CoreServices CoreGraphics ImageIO;
   };
+  xcodebuild6 = xcodebuild.override { stdenv = llvmPackages_6.stdenv; };
   xcbuild = xcodebuild;
   xcbuildHook = makeSetupHook {
     deps = [ xcbuild ];
   } ../development/tools/xcbuild/setup-hook.sh  ;
 
+  # xcbuild with llvm 6
+  xcbuild6Hook = makeSetupHook {
+    deps = [ xcodebuild6 ];
+  } ../development/tools/xcbuild/setup-hook.sh  ;
+
   xcpretty = callPackage ../development/tools/xcpretty { };
 
   xmlindent = callPackage ../development/web/xmlindent {};
@@ -9844,9 +9864,13 @@ in
 
   cln = callPackage ../development/libraries/cln { };
 
-  clucene_core_2 = callPackage ../development/libraries/clucene-core/2.x.nix { };
+  clucene_core_2 = callPackage ../development/libraries/clucene-core/2.x.nix {
+    stdenv = if stdenv.cc.isClang then llvmPackages_6.stdenv else stdenv;
+  };
 
-  clucene_core_1 = callPackage ../development/libraries/clucene-core { };
+  clucene_core_1 = callPackage ../development/libraries/clucene-core {
+    stdenv = if stdenv.cc.isClang then llvmPackages_6.stdenv else stdenv;
+  };
 
   clucene_core = clucene_core_1;
 
@@ -10896,7 +10920,7 @@ in
 
   libao = callPackage ../development/libraries/libao {
     usePulseAudio = config.pulseaudio or stdenv.isLinux;
-    inherit (darwin.apple_sdk.frameworks) CoreAudio CoreServices AudioUnit;
+    inherit (darwin.apple_sdk.frameworks) CoreAudio CoreServices AudioUnit AudioToolbox;
   };
 
   libaosd = callPackage ../development/libraries/libaosd { };
@@ -10972,7 +10996,7 @@ in
     inherit (darwin.apple_sdk.frameworks) CoreServices;
   };
   libcanberra-gtk3 = pkgs.libcanberra.override {
-    gtk = gtk3;
+    gtk = gtk3.override { x11Support = true; };
   };
   libcanberra-gtk2 = pkgs.libcanberra-gtk3.override {
     gtk = gtk2.override { gdktarget = "x11"; };
@@ -12002,6 +12026,7 @@ in
   libGLSupported = lib.elem stdenv.hostPlatform.system lib.platforms.mesaPlatforms;
 
   mesa_noglu = callPackage ../development/libraries/mesa {
+    # 7 is the default, but only on Linux, so keep this for now
     llvmPackages = llvmPackages_7;
     inherit (darwin.apple_sdk.frameworks) OpenGL;
     inherit (darwin.apple_sdk.libs) Xplugin;
@@ -12525,6 +12550,7 @@ in
       inherit gtk3;
       inherit (gnome3) dconf;
       inherit (gst_all_1) gstreamer gst-plugins-base;
+      inherit llvmPackages_5;
     });
 
   libsForQt511 = recurseIntoAttrs (lib.makeScope qt511.newScope mkLibsForQt5);
@@ -12542,6 +12568,7 @@ in
       inherit gtk3;
       inherit (gnome3) dconf;
       inherit (gst_all_1) gstreamer gst-plugins-base;
+      inherit llvmPackages_5;
     });
 
   libsForQt512 = recurseIntoAttrs (lib.makeScope qt512.newScope mkLibsForQt5);
@@ -19115,7 +19142,9 @@ in
 
   openbox = callPackage ../applications/window-managers/openbox { };
 
-  openbox-menu = callPackage ../applications/misc/openbox-menu { };
+  openbox-menu = callPackage ../applications/misc/openbox-menu {
+    stdenv = gccStdenv;
+  };
 
   openbrf = libsForQt5.callPackage ../applications/misc/openbrf { };
 
@@ -21721,7 +21750,9 @@ in
 
   xtris = callPackage ../games/xtris { };
 
-  inherit (callPackage ../games/quake2/yquake2 { })
+  inherit (callPackage ../games/quake2/yquake2 {
+    inherit (darwin.apple_sdk.frameworks) Cocoa OpenAL;
+  })
     yquake2
     yquake2-ctf
     yquake2-ground-zero
@@ -22628,11 +22659,13 @@ in
   root = callPackage ../applications/science/misc/root {
     inherit (darwin) cf-private;
     inherit (darwin.apple_sdk.frameworks) Cocoa OpenGL;
+    stdenv = if stdenv.cc.isClang then llvmPackages_5.stdenv else stdenv;
   };
 
   root5 = lowPrio (callPackage ../applications/science/misc/root/5.nix {
     inherit (darwin) cf-private;
     inherit (darwin.apple_sdk.frameworks) Cocoa OpenGL;
+    stdenv = if stdenv.cc.isClang then llvmPackages_5.stdenv else stdenv;
   });
 
   rink = callPackage ../applications/science/misc/rink { };
@@ -23278,7 +23311,9 @@ in
 
   fsuae = callPackage ../misc/emulators/fs-uae { };
 
-  putty = callPackage ../applications/networking/remote/putty { };
+  putty = callPackage ../applications/networking/remote/putty {
+    gtk2 = gtk2-x11;
+  };
 
   qMasterPassword = libsForQt5.callPackage ../applications/misc/qMasterPassword { };
 
diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix
index 1fc36139ac0..1753ac9dc7a 100644
--- a/pkgs/top-level/darwin-packages.nix
+++ b/pkgs/top-level/darwin-packages.nix
@@ -15,7 +15,7 @@ in
   binutils-unwrapped = callPackage ../os-specific/darwin/binutils {
     inherit (darwin) cctools;
     inherit (pkgs) binutils-unwrapped;
-    inherit (pkgs.llvmPackages_5) llvm;
+    inherit (pkgs.llvmPackages_7) llvm;
   };
 
   binutils = pkgs.wrapBintoolsWith {
@@ -27,13 +27,13 @@ in
   };
 
   cctools = callPackage ../os-specific/darwin/cctools/port.nix {
-    inherit (darwin) libobjc maloader;
+    inherit (darwin) libobjc maloader libtapi;
     stdenv = if stdenv.isDarwin then stdenv else pkgs.libcxxStdenv;
     libcxxabi = pkgs.libcxxabi;
   };
 
   cf-private = callPackage ../os-specific/darwin/cf-private {
-    inherit (darwin) CF apple_sdk osx_private_sdk;
+    inherit (darwin) CF apple_sdk;
   };
 
   DarwinTools = callPackage ../os-specific/darwin/DarwinTools { };
@@ -59,12 +59,6 @@ in
 
   opencflite = callPackage ../os-specific/darwin/opencflite { };
 
-  osx_private_sdk = callPackage ../os-specific/darwin/osx-private-sdk { };
-
-  security_tool = darwin.callPackage ../os-specific/darwin/security-tool {
-    Security-framework = darwin.apple_sdk.frameworks.Security;
-  };
-
   stubs = callPackages ../os-specific/darwin/stubs { };
 
   trash = darwin.callPackage ../os-specific/darwin/trash { };
@@ -83,4 +77,6 @@ in
 
   darling = callPackage ../os-specific/darwin/darling/default.nix { };
 
+  libtapi = callPackage ../os-specific/darwin/libtapi {};
+
 })
diff --git a/pkgs/top-level/perl-packages.nix b/pkgs/top-level/perl-packages.nix
index 0d39a52b813..c875ee5d5ed 100644
--- a/pkgs/top-level/perl-packages.nix
+++ b/pkgs/top-level/perl-packages.nix
@@ -6688,6 +6688,7 @@ let
       sha256 = "1044rj3wbfmgaif2jb0k28m2aczli6ai2n5yvn6pr7zjyw16kvd2";
     };
     buildInputs = [ pkgs.gtk2 Cairo ExtUtilsDepends ExtUtilsPkgConfig Glib Pango ];
+    doCheck = !stdenv.isDarwin;
     meta = {
       homepage = http://gtk2-perl.sourceforge.net/;
       description = "Perl interface to the 2.x series of the Gimp Toolkit library";
@@ -14499,6 +14500,7 @@ let
       url = "mirror://cpan/authors/id/D/DW/DWHEELER/${name}.tar.gz";
       sha256 = "1655337l1cyd7q62007wrk87q2gbbwfq9xjy1wgx3hyflxpkkvl4";
     };
+    doCheck = !stdenv.isDarwin;
     meta = {
       description = "Stream TAP from pgTAP test scripts";
       license = with stdenv.lib.licenses; [ artistic1 gpl1Plus ];
@@ -14656,6 +14658,7 @@ let
       sha256 = "1msxg3j1hx5wsc7vr81x5gs9gdbn4y0x6cvyj3pq4dgi1603dbvi";
     };
     propagatedBuildInputs = [ AppConfig ];
+    doCheck = !stdenv.isDarwin;
     meta = {
       description = "Comprehensive template processing system";
       license = with stdenv.lib.licenses; [ artistic1 gpl1Plus ];
diff --git a/pkgs/top-level/release.nix b/pkgs/top-level/release.nix
index 6c2159f9bef..d18c1dbd2e7 100644
--- a/pkgs/top-level/release.nix
+++ b/pkgs/top-level/release.nix
@@ -193,7 +193,6 @@ let
 
       darwin = packagePlatforms pkgs.darwin // {
         cf-private = {};
-        osx_private_sdk = {};
         xcode = {};
       };
     } ));