summary refs log tree commit diff
path: root/pkgs/os-specific/darwin
diff options
context:
space:
mode:
authorSteven Pease <peasteven@gmail.com>2021-01-19 20:42:30 -0800
committerSteven Pease <peasteven@gmail.com>2021-01-19 20:42:30 -0800
commit0fdab8d560461b8666d54342dac06718b9d1ecdd (patch)
treeff9a026a5d7c3fa9e3bef49bc238b172a8133bd2 /pkgs/os-specific/darwin
parentd8c1c0dc501855658ef3f4bf6a896c82730fe806 (diff)
parent83fd591dec09681e74fff454292883eb99e0a765 (diff)
downloadnixpkgs-0fdab8d560461b8666d54342dac06718b9d1ecdd.tar
nixpkgs-0fdab8d560461b8666d54342dac06718b9d1ecdd.tar.gz
nixpkgs-0fdab8d560461b8666d54342dac06718b9d1ecdd.tar.bz2
nixpkgs-0fdab8d560461b8666d54342dac06718b9d1ecdd.tar.lz
nixpkgs-0fdab8d560461b8666d54342dac06718b9d1ecdd.tar.xz
nixpkgs-0fdab8d560461b8666d54342dac06718b9d1ecdd.tar.zst
nixpkgs-0fdab8d560461b8666d54342dac06718b9d1ecdd.zip
Merge branch 'master' into add-newer-xcode-hashes
Diffstat (limited to 'pkgs/os-specific/darwin')
-rw-r--r--pkgs/os-specific/darwin/DarwinTools/default.nix6
-rw-r--r--pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh2
-rw-r--r--pkgs/os-specific/darwin/apple-sdk/default.nix131
-rw-r--r--pkgs/os-specific/darwin/apple-sdk/frameworks.nix228
-rw-r--r--pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix17
-rw-r--r--pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c148
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/CarbonHeaders/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/CommonCrypto/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/Csu/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/IOKit/default.nix19
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/Librpcsvc/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix60
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/Libsystem/reexported_libraries41
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/Security/boot.nix17
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/adv_cmds/boot.nix6
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/adv_cmds/default.nix25
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/architecture/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/basic_cmds/default.nix6
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/bootstrap_cmds/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/bsdmake/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/default.nix8
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/developer_cmds/default.nix6
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/diskdev_cmds/default.nix6
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/dyld/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/file_cmds/default.nix6
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/hfs/default.nix6
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libauto/default.nix8
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libpthread/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libunwind/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/network_cmds/default.nix6
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/objc4/default.nix5
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/shell_cmds/default.nix6
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/system_cmds/default.nix4
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/text_cmds/default.nix6
-rw-r--r--pkgs/os-specific/darwin/binutils/default.nix6
-rw-r--r--pkgs/os-specific/darwin/cctools/port.nix18
-rw-r--r--pkgs/os-specific/darwin/chunkwm/default.nix4
-rw-r--r--pkgs/os-specific/darwin/darling/default.nix2
-rw-r--r--pkgs/os-specific/darwin/darwin-stubs/default.nix18
-rw-r--r--pkgs/os-specific/darwin/discrete-scroll/default.nix1
-rw-r--r--pkgs/os-specific/darwin/goku/default.nix4
-rw-r--r--pkgs/os-specific/darwin/insert_dylib/default.nix4
-rw-r--r--pkgs/os-specific/darwin/iproute2mac/default.nix4
-rw-r--r--pkgs/os-specific/darwin/khd/default.nix4
-rw-r--r--pkgs/os-specific/darwin/kwm/default.nix4
-rw-r--r--pkgs/os-specific/darwin/libtapi/default.nix18
-rw-r--r--pkgs/os-specific/darwin/lsusb/default.nix8
-rw-r--r--pkgs/os-specific/darwin/m-cli/default.nix4
-rw-r--r--pkgs/os-specific/darwin/maloader/default.nix6
-rw-r--r--pkgs/os-specific/darwin/noah/default.nix4
-rw-r--r--pkgs/os-specific/darwin/opencflite/default.nix4
-rw-r--r--pkgs/os-specific/darwin/osx-cpu-temp/default.nix31
-rw-r--r--pkgs/os-specific/darwin/osxfuse/default.nix4
-rw-r--r--pkgs/os-specific/darwin/osxsnarf/default.nix2
-rw-r--r--pkgs/os-specific/darwin/qes/default.nix4
-rw-r--r--pkgs/os-specific/darwin/reattach-to-user-namespace/default.nix14
-rw-r--r--pkgs/os-specific/darwin/skhd/default.nix4
-rw-r--r--pkgs/os-specific/darwin/spacebar/default.nix8
-rw-r--r--pkgs/os-specific/darwin/stubs/default.nix4
-rw-r--r--pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix4
-rw-r--r--pkgs/os-specific/darwin/swift-corelibs/libdispatch.nix3
-rw-r--r--pkgs/os-specific/darwin/trash/default.nix6
-rw-r--r--pkgs/os-specific/darwin/usr-include/default.nix4
-rw-r--r--pkgs/os-specific/darwin/wifi-password/default.nix8
-rw-r--r--pkgs/os-specific/darwin/xcode/sdk-pkgs.nix8
-rw-r--r--pkgs/os-specific/darwin/yabai/default.nix8
67 files changed, 637 insertions, 405 deletions
diff --git a/pkgs/os-specific/darwin/DarwinTools/default.nix b/pkgs/os-specific/darwin/DarwinTools/default.nix
index 174f9478633..5badf2434d6 100644
--- a/pkgs/os-specific/darwin/DarwinTools/default.nix
+++ b/pkgs/os-specific/darwin/DarwinTools/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl }:
+{ lib, stdenv, fetchurl }:
 
 stdenv.mkDerivation rec {
   name = "DarwinTools-1";
@@ -25,7 +25,7 @@ stdenv.mkDerivation rec {
   '';
 
   meta = {
-    maintainers = [ stdenv.lib.maintainers.matthewbauer ];
-    platforms = stdenv.lib.platforms.darwin;
+    maintainers = [ lib.maintainers.matthewbauer ];
+    platforms = lib.platforms.darwin;
   };
 }
diff --git a/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh b/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh
index 86c241cd0f5..bbf9625e655 100644
--- a/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh
+++ b/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh
@@ -3,7 +3,7 @@ linkSystemCoreFoundationFramework() {
   # gross! many symbols (such as _OBJC_CLASS_$_NSArray) are defined in system CF, but not
   # in the opensource release
   # if the package needs private headers, we assume they also want to link with system CF
-  NIX_LDFLAGS+=" /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation"
+  NIX_LDFLAGS+=" @out@/Library/Frameworks/CoreFoundation.framework/CoreFoundation"
 }
 
 preConfigureHooks+=(linkSystemCoreFoundationFramework)
diff --git a/pkgs/os-specific/darwin/apple-sdk/default.nix b/pkgs/os-specific/darwin/apple-sdk/default.nix
index 89c13d0b92d..0ba7a1d209e 100644
--- a/pkgs/os-specific/darwin/apple-sdk/default.nix
+++ b/pkgs/os-specific/darwin/apple-sdk/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, xar, cpio, pkgs, python3, pbzx, lib }:
+{ stdenv, fetchurl, xar, cpio, pkgs, python3, pbzx, lib, darwin-stubs, print-reexports }:
 
 let version = "10.12"; in
 
@@ -42,17 +42,28 @@ let
       rmdir System
 
       pushd lib
-      ln -s -L /usr/lib/libcups*.dylib .
+      cp ${darwin-stubs}/usr/lib/libcups*.tbd .
+      ln -s libcups.2.tbd      libcups.tbd
+      ln -s libcupscgi.1.tbd   libcupscgi.tbd
+      ln -s libcupsimage.2.tbd libcupsimage.tbd
+      ln -s libcupsmime.1.tbd  libcupsmime.tbd
+      ln -s libcupsppdc.1.tbd  libcupsppdc.tbd
       popd
     '';
 
-    meta = with stdenv.lib; {
+    meta = with lib; {
       description = "Apple SDK ${version}";
       maintainers = with maintainers; [ copumpkin ];
       platforms   = platforms.darwin;
     };
   };
 
+  mkFrameworkSubs = name: deps:
+  let
+    deps' = deps // { "${name}" = placeholder "out"; };
+    substArgs = lib.concatMap (x: [ "--subst-var-by" x deps'."${x}" ]) (lib.attrNames deps');
+  in lib.escapeShellArgs substArgs;
+
   framework = name: deps: stdenv.mkDerivation {
     name = "apple-framework-${name}";
 
@@ -63,11 +74,14 @@ let
 
     disallowedRequisites = [ sdk ];
 
+    nativeBuildInputs = [ print-reexports ];
+
+    extraTBDFiles = [];
+
     installPhase = ''
       linkFramework() {
         local path="$1"
         local nested_path="$1"
-        local dest="$out/Library/Frameworks/$path"
         if [ "$path" == "JavaNativeFoundation.framework" ]; then
           local nested_path="JavaVM.framework/Versions/A/Frameworks/JavaNativeFoundation.framework"
         fi
@@ -80,21 +94,29 @@ let
           current=A
         fi
 
-        mkdir -p "$dest"
-        pushd "$dest" >/dev/null
+        local dest="$out/Library/Frameworks/$path"
 
-        # Keep track of if this is a child or a child rescue as with
-        # ApplicationServices in the 10.9 SDK
-        local isChild=0
+        mkdir -p "$dest/Versions/$current"
+        pushd "$dest/Versions/$current" >/dev/null
 
         if [ -d "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" ]; then
-          isChild=1
           cp -R "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" .
         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
-        ln -s -L "/System/Library/Frameworks/$nested_path/Versions/$current/$name"
+
+        local tbd_source=${darwin-stubs}/System/Library/Frameworks/$nested_path/Versions/$current
+        if [ "${name}" != "Kernel" ]; then
+          # The Kernel.framework has headers but no actual library component.
+          cp -v $tbd_source/*.tbd .
+        fi
+
+        if [ -d "$tbd_source/Libraries" ]; then
+          mkdir Libraries
+          cp -v $tbd_source/Libraries/*.tbd Libraries/
+        fi
+
         ln -s -L "/System/Library/Frameworks/$nested_path/Versions/$current/Resources"
 
         if [ -f "/System/Library/Frameworks/$nested_path/module.map" ]; then
@@ -110,35 +132,74 @@ let
           linkFramework "$childpath"
         done
 
-        if [ -d "$dest/Versions/$current" ]; then
-          mv $dest/Versions/$current/* .
-        fi
+        pushd ../.. >/dev/null
+        ln -s "$current" Versions/Current
+        ln -s Versions/Current/* .
+        popd >/dev/null
 
         popd >/dev/null
       }
 
       linkFramework "${name}.framework"
+
+      # linkFramework is recursive, the rest of the processing is not.
+
+      local tbd_source=${darwin-stubs}/System/Library/Frameworks/${name}.framework
+      for tbd in $extraTBDFiles; do
+        local tbd_dest_dir=$out/Library/Frameworks/${name}.framework/$(dirname "$tbd")
+        mkdir -p "$tbd_dest_dir"
+        cp -v "$tbd_source/$tbd" "$tbd_dest_dir"
+      done
+
+      # Fix and check tbd re-export references
+      find $out -name '*.tbd' | while read tbd; do
+        echo "Fixing re-exports in $tbd"
+        substituteInPlace "$tbd" ${mkFrameworkSubs name deps}
+
+        echo "Checking re-exports in $tbd"
+        print-reexports "$tbd" | while read target; do
+          local expected="''${target%.dylib}.tbd"
+          if ! [ -e "$expected" ]; then
+            echo -e "Re-export missing:\n\t$target\n\t(expected $expected)"
+            echo -e "While processing\n\t$tbd"
+            exit 1
+          else
+            echo "Re-exported target $target ok"
+          fi
+        done
+      done
     '';
 
-    propagatedBuildInputs = deps;
+    propagatedBuildInputs = builtins.attrValues deps;
 
     # don't use pure CF for dylibs that depend on frameworks
     setupHook = ./framework-setup-hook.sh;
 
     # Not going to be more specific than this for now
-    __propagatedImpureHostDeps = stdenv.lib.optionals (name != "Kernel") [
+    __propagatedImpureHostDeps = lib.optionals (name != "Kernel") [
       # The setup-hook ensures that everyone uses the impure CoreFoundation who uses these SDK frameworks, so let's expose it
       "/System/Library/Frameworks/CoreFoundation.framework"
       "/System/Library/Frameworks/${name}.framework"
       "/System/Library/Frameworks/${name}.framework/${name}"
     ];
 
-    meta = with stdenv.lib; {
+    meta = with lib; {
       description = "Apple SDK framework ${name}";
       maintainers = with maintainers; [ copumpkin ];
       platforms   = platforms.darwin;
     };
   };
+
+  tbdOnlyFramework = name: { private ? true }: stdenv.mkDerivation {
+    name = "apple-framework-${name}";
+    dontUnpack = true;
+    installPhase = ''
+      mkdir -p $out/Library/Frameworks/
+      cp -r ${darwin-stubs}/System/Library/${lib.optionalString private "Private"}Frameworks/${name}.framework \
+        $out/Library/Frameworks
+      # NOTE there's no re-export checking here, this is probably wrong
+    '';
+  };
 in rec {
   libs = {
     xpc = stdenv.mkDerivation {
@@ -168,7 +229,8 @@ in rec {
       installPhase = ''
         mkdir -p $out/include $out/lib
         ln -s "${lib.getDev sdk}/include/Xplugin.h" $out/include/Xplugin.h
-        ln -s "/usr/lib/libXplugin.1.dylib" $out/lib/libXplugin.dylib
+        cp ${darwin-stubs}/usr/lib/libXplugin.1.tbd $out/lib
+        ln -s libXplugin.1.tbd $out/lib/libXplugin.tbd
       '';
     };
 
@@ -187,34 +249,42 @@ in rec {
   };
 
   overrides = super: {
-    AppKit = stdenv.lib.overrideDerivation super.AppKit (drv: {
+    AppKit = lib.overrideDerivation super.AppKit (drv: {
       __propagatedImpureHostDeps = drv.__propagatedImpureHostDeps ++ [
         "/System/Library/PrivateFrameworks/"
       ];
     });
 
-    CoreFoundation = stdenv.lib.overrideDerivation super.CoreFoundation (drv: {
+    Carbon = lib.overrideDerivation super.Carbon (drv: {
+      extraTBDFiles = [ "Versions/A/Frameworks/HTMLRendering.framework/Versions/A/HTMLRendering.tbd" ];
+    });
+
+    CoreFoundation = lib.overrideDerivation super.CoreFoundation (drv: {
       setupHook = ./cf-setup-hook.sh;
     });
 
-    CoreMedia = stdenv.lib.overrideDerivation super.CoreMedia (drv: {
+    CoreMedia = lib.overrideDerivation super.CoreMedia (drv: {
       __propagatedImpureHostDeps = drv.__propagatedImpureHostDeps ++ [
         "/System/Library/Frameworks/CoreImage.framework"
       ];
     });
 
-    CoreMIDI = stdenv.lib.overrideDerivation super.CoreMIDI (drv: {
+    CoreMIDI = lib.overrideDerivation super.CoreMIDI (drv: {
       __propagatedImpureHostDeps = drv.__propagatedImpureHostDeps ++ [
         "/System/Library/PrivateFrameworks/"
       ];
       setupHook = ./private-frameworks-setup-hook.sh;
     });
 
-    Security = stdenv.lib.overrideDerivation super.Security (drv: {
+    IMServicePlugIn = lib.overrideDerivation super.IMServicePlugIn (drv: {
+      extraTBDFiles = [ "Versions/A/Frameworks/IMServicePlugInSupport.framework/Versions/A/IMServicePlugInSupport.tbd" ];
+    });
+
+    Security = lib.overrideDerivation super.Security (drv: {
       setupHook = ./security-setup-hook.sh;
     });
 
-    QuartzCore = stdenv.lib.overrideDerivation super.QuartzCore (drv: {
+    QuartzCore = lib.overrideDerivation super.QuartzCore (drv: {
       installPhase = drv.installPhase + ''
         f="$out/Library/Frameworks/QuartzCore.framework/Headers/CoreImage.h"
         substituteInPlace "$f" \
@@ -222,15 +292,22 @@ in rec {
       '';
     });
 
-    MetalKit = stdenv.lib.overrideDerivation super.MetalKit (drv: {
+    MetalKit = lib.overrideDerivation super.MetalKit (drv: {
       installPhase = drv.installPhase + ''
         mkdir -p $out/include/simd
         cp ${lib.getDev sdk}/include/simd/*.h $out/include/simd/
       '';
     });
-  };
 
-  bareFrameworks = stdenv.lib.mapAttrs framework (import ./frameworks.nix {
+    WebKit = lib.overrideDerivation super.WebKit (drv: {
+      extraTBDFiles = [
+        "Versions/A/Frameworks/WebCore.framework/Versions/A/WebCore.tbd"
+        "Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy.tbd"
+      ];
+    });
+  } // lib.genAttrs [ "ContactsPersistence" "UIFoundation" "GameCenter" ] (x: tbdOnlyFramework x {});
+
+  bareFrameworks = lib.mapAttrs framework (import ./frameworks.nix {
     inherit frameworks libs;
     inherit (pkgs.darwin) libobjc;
   });
diff --git a/pkgs/os-specific/darwin/apple-sdk/frameworks.nix b/pkgs/os-specific/darwin/apple-sdk/frameworks.nix
index 02e2421f347..d3b00e6a6a6 100644
--- a/pkgs/os-specific/darwin/apple-sdk/frameworks.nix
+++ b/pkgs/os-specific/darwin/apple-sdk/frameworks.nix
@@ -5,123 +5,125 @@
 { frameworks, libs, libobjc, }:
 
 with frameworks; with libs; {
-  AGL                     = [ Carbon OpenGL ];
-  AVFoundation            = [ ApplicationServices CoreGraphics ];
-  AVKit                   = [];
-  Accounts                = [];
-  AddressBook             = [ Carbon ];
-  AppKit                  = [ AudioToolbox AudioUnit Foundation QuartzCore ];
-  AppKitScripting         = [];
-  AppleScriptKit          = [];
-  AppleScriptObjC         = [];
-  AudioToolbox            = [ CoreAudio CoreMIDI ];
-  AudioUnit               = [ AudioToolbox Carbon CoreAudio ];
-  AudioVideoBridging      = [ Foundation ];
-  Automator               = [];
-  CFNetwork               = [];
-  CalendarStore           = [];
-  Cocoa                   = [ AppKit ];
-  Collaboration           = [];
+  AGL                     = { inherit Carbon OpenGL; };
+  AVFoundation            = { inherit ApplicationServices CoreGraphics CoreMedia MediaToolbox; };
+  AVKit                   = {};
+  Accounts                = {};
+  AddressBook             = { inherit libobjc Carbon ContactsPersistence; };
+  AppKit                  = { inherit ApplicationServices AudioToolbox AudioUnit Foundation QuartzCore UIFoundation; };
+  AppKitScripting         = {};
+  AppleScriptKit          = {};
+  AppleScriptObjC         = {};
+  AudioToolbox            = { inherit CoreAudio CoreMIDI; };
+  AudioUnit               = { inherit AudioToolbox Carbon CoreAudio; };
+  AudioVideoBridging      = { inherit Foundation; };
+  Automator               = {};
+  CFNetwork               = {};
+  CalendarStore           = {};
+  Cocoa                   = { inherit AppKit CoreData; };
+  Collaboration           = {};
   # Impure version of CoreFoundation, this should not be used unless another
   # framework includes headers that are not available in the pure version.
-  CoreFoundation          = [];
-  CoreAudio               = [ IOKit ];
-  CoreAudioKit            = [ AudioUnit ];
-  CoreData                = [];
-  CoreGraphics            = [ Accelerate IOKit IOSurface SystemConfiguration ];
-  CoreImage               = [];
-  CoreLocation            = [];
-  CoreMIDI                = [];
-  CoreMIDIServer          = [];
-  CoreMedia               = [ ApplicationServices AudioToolbox AudioUnit CoreAudio CoreGraphics CoreVideo ];
-  CoreMediaIO             = [ CoreMedia ];
-  CoreText                = [ CoreGraphics ];
-  CoreVideo               = [ ApplicationServices CoreGraphics IOSurface OpenGL ];
-  CoreWLAN                = [ SecurityFoundation ];
-  DVDPlayback             = [];
-  DirectoryService        = [];
-  DiscRecording           = [ CoreServices IOKit ];
-  DiscRecordingUI         = [];
-  DiskArbitration         = [ IOKit ];
-  EventKit                = [];
-  ExceptionHandling       = [];
-  FWAUserLib              = [];
-  ForceFeedback           = [ IOKit ];
-  Foundation              = [ libobjc CoreFoundation Security ApplicationServices SystemConfiguration ];
-  GLKit                   = [];
-  GLUT                    = [ OpenGL ];
-  GSS                     = [];
-  GameController          = [];
-  GameKit                 = [ Foundation ];
-  Hypervisor              = [];
-  ICADevices              = [ Carbon IOBluetooth ];
-  IMServicePlugIn         = [];
-  IOBluetoothUI           = [ IOBluetooth ];
-  IOKit                   = [];
-  IOSurface               = [ IOKit xpc ];
-  ImageCaptureCore        = [];
-  ImageIO                 = [ CoreGraphics ];
-  InputMethodKit          = [ Carbon ];
-  InstallerPlugins        = [];
-  InstantMessage          = [];
-  JavaFrameEmbedding      = [];
-  JavaNativeFoundation    = [];
-  JavaRuntimeSupport      = [];
-  JavaScriptCore          = [];
-  Kerberos                = [];
-  Kernel                  = [ IOKit ];
-  LDAP                    = [];
-  LatentSemanticMapping   = [ Carbon ];
-  LocalAuthentication     = [];
-  MapKit                  = [];
-  MediaAccessibility      = [ CoreGraphics CoreText QuartzCore ];
-  MediaPlayer             = [];
-  MediaToolbox            = [ AudioToolbox AudioUnit CoreMedia ];
-  Metal                   = [];
-  MetalKit                = [ ModelIO Metal ];
-  ModelIO                 = [ ];
-  NetFS                   = [];
-  OSAKit                  = [ Carbon ];
-  OpenAL                  = [];
-  OpenCL                  = [ IOSurface OpenGL ];
-  OpenGL                  = [];
-  PCSC                    = [ CoreData ];
-  PreferencePanes         = [];
-  PubSub                  = [];
-  QTKit                   = [ CoreMediaIO CoreMedia MediaToolbox QuickTime VideoToolbox ];
-  QuickLook               = [ ApplicationServices ];
-  SceneKit                = [];
-  ScreenSaver             = [];
-  Scripting               = [];
-  ScriptingBridge         = [];
-  Security                = [ IOKit ];
-  SecurityFoundation      = [];
-  SecurityInterface       = [ Security ];
-  ServiceManagement       = [ Security ];
-  Social                  = [];
-  SpriteKit               = [];
-  StoreKit                = [];
-  SyncServices            = [];
-  SystemConfiguration     = [ Security ];
-  TWAIN                   = [ Carbon ];
-  Tcl                     = [];
-  VideoDecodeAcceleration = [ CoreVideo ];
-  VideoToolbox            = [ CoreMedia CoreVideo ];
-  WebKit                  = [ ApplicationServices Carbon JavaScriptCore OpenGL ];
+  CoreFoundation          = {};
+  CoreAudio               = { inherit IOKit; };
+  CoreAudioKit            = { inherit AudioUnit; };
+  CoreData                = {};
+  CoreGraphics            = { inherit Accelerate IOKit IOSurface SystemConfiguration; };
+  CoreImage               = {};
+  CoreLocation            = {};
+  CoreMIDI                = {};
+  CoreMIDIServer          = { inherit CoreMIDI; };
+  CoreMedia               = { inherit ApplicationServices AudioToolbox AudioUnit CoreAudio CoreGraphics CoreVideo; };
+  CoreMediaIO             = { inherit CoreMedia; };
+  CoreText                = { inherit CoreGraphics; };
+  CoreVideo               = { inherit ApplicationServices CoreGraphics IOSurface OpenGL; };
+  CoreWLAN                = { inherit SecurityFoundation; };
+  DVDPlayback             = {};
+  DirectoryService        = {};
+  DiscRecording           = { inherit libobjc CoreServices IOKit; };
+  DiscRecordingUI         = {};
+  DiskArbitration         = { inherit IOKit; };
+  EventKit                = {};
+  ExceptionHandling       = {};
+  FWAUserLib              = {};
+  ForceFeedback           = { inherit IOKit; };
+  Foundation              = { inherit libobjc CoreFoundation Security ApplicationServices SystemConfiguration; };
+  GLKit                   = {};
+  GLUT                    = { inherit OpenGL; };
+  GSS                     = {};
+  GameCenter              = {};
+  GameController          = {};
+  GameKit                 = { inherit Cocoa Foundation GameCenter GameController GameplayKit Metal MetalKit ModelIO SceneKit SpriteKit; };
+  GameplayKit             = {};
+  Hypervisor              = {};
+  ICADevices              = { inherit libobjc Carbon IOBluetooth; };
+  IMServicePlugIn         = {};
+  IOBluetoothUI           = { inherit IOBluetooth; };
+  IOKit                   = {};
+  IOSurface               = { inherit IOKit xpc; };
+  ImageCaptureCore        = {};
+  ImageIO                 = { inherit CoreGraphics; };
+  InputMethodKit          = { inherit Carbon; };
+  InstallerPlugins        = {};
+  InstantMessage          = {};
+  JavaFrameEmbedding      = {};
+  JavaNativeFoundation    = {};
+  JavaRuntimeSupport      = {};
+  JavaScriptCore          = { inherit libobjc; };
+  Kerberos                = {};
+  Kernel                  = { inherit IOKit; };
+  LDAP                    = {};
+  LatentSemanticMapping   = { inherit Carbon; };
+  LocalAuthentication     = {};
+  MapKit                  = {};
+  MediaAccessibility      = { inherit CoreGraphics CoreText QuartzCore; };
+  MediaPlayer             = {};
+  MediaToolbox            = { inherit AudioToolbox AudioUnit CoreMedia; };
+  Metal                   = {};
+  MetalKit                = { inherit ModelIO Metal; };
+  ModelIO                 = {};
+  NetFS                   = {};
+  OSAKit                  = { inherit Carbon; };
+  OpenAL                  = {};
+  OpenCL                  = { inherit IOSurface OpenGL; };
+  OpenGL                  = {};
+  PCSC                    = { inherit CoreData; };
+  PreferencePanes         = {};
+  PubSub                  = {};
+  QTKit                   = { inherit CoreMediaIO CoreMedia MediaToolbox QuickTime VideoToolbox; };
+  QuickLook               = { inherit ApplicationServices; };
+  SceneKit                = {};
+  ScreenSaver             = {};
+  Scripting               = {};
+  ScriptingBridge         = {};
+  Security                = { inherit IOKit; };
+  SecurityFoundation      = {};
+  SecurityInterface       = { inherit Security SecurityFoundation; };
+  ServiceManagement       = { inherit Security; };
+  Social                  = {};
+  SpriteKit               = {};
+  StoreKit                = {};
+  SyncServices            = {};
+  SystemConfiguration     = { inherit Security; };
+  TWAIN                   = { inherit Carbon; };
+  Tcl                     = {};
+  VideoDecodeAcceleration = { inherit CoreVideo; };
+  VideoToolbox            = { inherit CoreMedia CoreVideo; };
+  WebKit                  = { inherit libobjc ApplicationServices Carbon JavaScriptCore OpenGL; };
 
   # Umbrellas
-  Accelerate          = [ CoreWLAN IOBluetooth ];
-  ApplicationServices = [ CoreServices CoreText ImageIO ];
-  Carbon              = [ ApplicationServices CoreServices Foundation IOKit Security QuartzCore ];
-  CoreBluetooth       = [];
+  Accelerate          = { inherit CoreWLAN IOBluetooth; };
+  ApplicationServices = { inherit CoreGraphics CoreServices CoreText ImageIO; };
+  Carbon              = { inherit libobjc ApplicationServices CoreServices Foundation IOKit Security QuartzCore; };
+  CoreBluetooth       = {};
   # TODO: figure out which part of the umbrella depends on CoreFoundation and move it there.
-  CoreServices        = [ CFNetwork CoreFoundation CoreAudio CoreData DiskArbitration Security NetFS OpenDirectory ServiceManagement ];
-  IOBluetooth         = [ IOKit ];
-  JavaVM              = [];
-  OpenDirectory       = [];
-  Quartz              = [ QuickLook QTKit ];
-  QuartzCore          = [ ApplicationServices CoreVideo OpenCL CoreImage Metal ];
-  QuickTime           = [ ApplicationServices AudioUnit Carbon CoreAudio CoreServices OpenGL QuartzCore ];
+  CoreServices        = { inherit CFNetwork CoreFoundation CoreAudio CoreData DiskArbitration Security NetFS OpenDirectory ServiceManagement; };
+  IOBluetooth         = { inherit CoreBluetooth IOKit; };
+  JavaVM              = {};
+  OpenDirectory       = {};
+  Quartz              = { inherit QuartzCore QuickLook QTKit; };
+  QuartzCore          = { inherit libobjc ApplicationServices CoreVideo OpenCL CoreImage Metal; };
+  QuickTime           = { inherit ApplicationServices AudioUnit Carbon CoreAudio CoreServices OpenGL QuartzCore; };
 
-  vmnet = [];
+  vmnet = {};
 }
diff --git a/pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix b/pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix
new file mode 100644
index 00000000000..a548d8da753
--- /dev/null
+++ b/pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix
@@ -0,0 +1,17 @@
+{ lib, stdenv, libyaml }:
+
+stdenv.mkDerivation {
+  name = "print-reexports";
+  src = lib.sourceFilesBySuffices ./. [".c"];
+
+  buildInputs = [ libyaml ];
+
+  buildPhase = ''
+    $CC -lyaml -o $name main.c
+  '';
+
+  installPhase = ''
+    mkdir -p $out/bin
+    mv $name $out/bin
+  '';
+}
diff --git a/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c b/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c
new file mode 100644
index 00000000000..df46e3f18e8
--- /dev/null
+++ b/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c
@@ -0,0 +1,148 @@
+/**
+ * Display the list of re-exported libraries from a TAPI v2 .tbd file, one per
+ * line on stdout.
+ *
+ * TAPI files are the equivalent of library files for the purposes of linking.
+ * Like dylib files, they may re-export other libraries. In upstream usage
+ * these refer to the absolute paths of dylibs, and are resolved to .tbd files
+ * in combination with the syslibroot option. In nixpkgs, the .tbd files refer
+ * directly to other .tbd files without a syslibroot. Note that each .tbd file
+ * contains an install name, so the re-exported path does not affect the final
+ * result.
+ *
+ * In nixpkgs each framework is a distinct store path and some frameworks
+ * re-export other frameworks. The re-exported names are rewritten to refer to
+ * the store paths of dependencies via textual substitution. This utility is
+ * used to emit every file that is listed as a re-exported library, which
+ * allows the framework builder to verify their existence.
+ */
+
+#include <stdio.h>
+#include <sys/errno.h>
+#include <yaml.h>
+
+static yaml_node_t *get_mapping_entry(yaml_document_t *document, yaml_node_t *mapping, const char *name) {
+  if (!mapping) {
+    fprintf(stderr, "get_mapping_entry: mapping is null\n");
+    return NULL;
+  }
+
+  for (
+      yaml_node_pair_t *pair = mapping->data.mapping.pairs.start;
+      pair < mapping->data.mapping.pairs.top;
+      ++pair
+  ) {
+    yaml_node_t *key = yaml_document_get_node(document, pair->key);
+
+    if (!key) {
+      fprintf(stderr, "get_mapping_entry: key (%i) is null\n", pair->key);
+      return NULL;
+    }
+
+    if (key->type != YAML_SCALAR_NODE) {
+      fprintf(stderr, "get_mapping_entry: key is not a scalar\n");
+      return NULL;
+    }
+
+    if (strncmp((const char *)key->data.scalar.value, name, key->data.scalar.length) != 0) {
+      continue;
+    }
+
+    return yaml_document_get_node(document, pair->value);
+  }
+
+  return NULL;
+}
+
+static int emit_reexports(yaml_document_t *document) {
+  yaml_node_t *root = yaml_document_get_root_node(document);
+
+  yaml_node_t *exports = get_mapping_entry(document, root, "exports");
+
+  if (!exports) {
+    fprintf(stderr, "emit_reexports: no exports found\n");
+    return 0;
+  }
+
+  if (exports->type != YAML_SEQUENCE_NODE) {
+    fprintf(stderr, "emit_reexports, value is not a sequence\n");
+    return 0;
+  }
+
+  for (
+      yaml_node_item_t *export = exports->data.sequence.items.start;
+      export < exports->data.sequence.items.top;
+      ++export
+  ) {
+    yaml_node_t *export_node = yaml_document_get_node(document, *export);
+
+    yaml_node_t *reexports = get_mapping_entry(document, export_node, "re-exports");
+
+    if (!reexports) {
+      continue;
+    }
+
+    for (
+        yaml_node_item_t *reexport = reexports->data.sequence.items.start;
+        reexport < reexports->data.sequence.items.top;
+        ++reexport
+    ) {
+      yaml_node_t *val = yaml_document_get_node(document, *reexport);
+
+      if (val->type != YAML_SCALAR_NODE) {
+        fprintf(stderr, "item is not a scalar\n");
+        return 0;
+      }
+
+      fwrite(val->data.scalar.value, val->data.scalar.length, 1, stdout);
+      putchar('\n');
+    }
+  }
+
+  return 1;
+}
+
+int main(int argc, char **argv) {
+  int result = 0;
+
+  if (argc != 2) {
+    fprintf(stderr, "Invalid usage\n");
+    result = 2;
+    goto done;
+  }
+
+  FILE *f = fopen(argv[1], "r");
+  if (!f) {
+    perror("opening input file");
+    result = errno;
+    goto done;
+  }
+
+  yaml_parser_t yaml_parser;
+  if (!yaml_parser_initialize(&yaml_parser)) {
+    fprintf(stderr, "Failed to initialize yaml parser\n");
+    result = 1;
+    goto err_file;
+  }
+
+  yaml_parser_set_input_file(&yaml_parser, f);
+
+  yaml_document_t yaml_document;
+
+  if(!yaml_parser_load(&yaml_parser, &yaml_document)) {
+    fprintf(stderr, "Failed to load yaml file\n");
+    result = 1;
+    goto err_yaml;
+  }
+
+  emit_reexports(&yaml_document);
+
+err_yaml:
+  yaml_parser_delete(&yaml_parser);
+
+err_file:
+  fclose(f);
+
+done:
+  return result;
+}
diff --git a/pkgs/os-specific/darwin/apple-source-releases/CarbonHeaders/default.nix b/pkgs/os-specific/darwin/apple-source-releases/CarbonHeaders/default.nix
index 5c6d54aeb9c..9afd4b475de 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/CarbonHeaders/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/CarbonHeaders/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation }:
+{ lib, stdenv, appleDerivation }:
 
 appleDerivation {
   dontBuild = true;
@@ -12,7 +12,7 @@ appleDerivation {
       --replace "CarbonCore/" ""
   '';
 
-  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/CommonCrypto/default.nix b/pkgs/os-specific/darwin/apple-source-releases/CommonCrypto/default.nix
index ad51f1df2bc..3e5399dbb35 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/CommonCrypto/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/CommonCrypto/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation }:
+{ lib, stdenv, appleDerivation }:
 
 appleDerivation {
   installPhase = ''
@@ -6,7 +6,7 @@ appleDerivation {
     cp include/* $out/include/CommonCrypto
   '';
 
-  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/Csu/default.nix b/pkgs/os-specific/darwin/apple-source-releases/Csu/default.nix
index 7fd32a64fe5..2f6c8319b1c 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/Csu/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/Csu/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation }:
+{ lib, stdenv, appleDerivation }:
 
 appleDerivation {
   prePatch = ''
@@ -18,7 +18,7 @@ appleDerivation {
 
   installFlags = [ "DSTROOT=$(out)" ];
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "Apple's common startup stubs for darwin";
     maintainers = with maintainers; [ copumpkin ];
     platforms   = platforms.darwin;
diff --git a/pkgs/os-specific/darwin/apple-source-releases/IOKit/default.nix b/pkgs/os-specific/darwin/apple-source-releases/IOKit/default.nix
index 4b82209f176..cb54212f217 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/IOKit/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/IOKit/default.nix
@@ -1,8 +1,8 @@
-{ stdenv, appleDerivation, IOKitSrcs, xnu }:
+{ lib, stdenv, appleDerivation, IOKitSrcs, xnu, darwin-stubs }:
 
 # Someday it'll make sense to split these out into their own packages, but today is not that day.
 appleDerivation {
-  srcs = stdenv.lib.attrValues IOKitSrcs;
+  srcs = lib.attrValues IOKitSrcs;
   sourceRoot = ".";
 
   phases = [ "unpackPhase" "installPhase" ];
@@ -14,12 +14,15 @@ appleDerivation {
   ];
 
   installPhase = ''
-    ###### IMPURITIES
     mkdir -p $out/Library/Frameworks/IOKit.framework
-    pushd $out/Library/Frameworks/IOKit.framework
-    ln -s /System/Library/Frameworks/IOKit.framework/IOKit
-    ln -s /System/Library/Frameworks/IOKit.framework/Resources
-    popd
+
+    ###### IMPURITIES
+    ln -s /System/Library/Frameworks/IOKit.framework/Resources \
+      $out/Library/Frameworks/IOKit.framework
+
+    ###### STUBS
+    cp ${darwin-stubs}/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit.tbd \
+      $out/Library/Frameworks/IOKit.framework
 
     ###### HEADERS
 
@@ -179,7 +182,7 @@ appleDerivation {
     # video: missing altogether
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     maintainers = with maintainers; [ joelteon copumpkin ];
     platforms   = platforms.darwin;
     license     = licenses.apsl20;
diff --git a/pkgs/os-specific/darwin/apple-source-releases/Librpcsvc/default.nix b/pkgs/os-specific/darwin/apple-source-releases/Librpcsvc/default.nix
index a7b2bd7d981..7f93a87837a 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/Librpcsvc/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/Librpcsvc/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation, developer_cmds }:
+{ lib, stdenv, appleDerivation, developer_cmds }:
 
 appleDerivation {
   buildInputs = [ developer_cmds ];
@@ -14,7 +14,7 @@ appleDerivation {
     rmdir $out/usr/
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     maintainers = with maintainers; [ matthewbauer ];
     platforms   = platforms.darwin;
     license     = licenses.apsl20;
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 99d67002803..a5508b5ec12 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix
@@ -1,7 +1,7 @@
-{ stdenv, appleDerivation, cpio, xnu, Libc, Libm, libdispatch, cctools, Libinfo
+{ lib, 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 }:
+, mDNSResponder, launchd, libutil, hfs, darling, darwin-stubs }:
 
 appleDerivation {
   dontBuild = true;
@@ -88,52 +88,18 @@ appleDerivation {
     # The startup object files
     cp ${Csu}/lib/* $out/lib
 
-    # We can't re-exported libsystem_c and libsystem_kernel directly,
-    # so we link against the central library here.
-    mkdir -p $out/lib/system
-    ld -macosx_version_min 10.7 -arch x86_64 -dylib \
-       -o $out/lib/system/libsystem_c.dylib \
-       /usr/lib/libSystem.dylib \
-       -reexported_symbols_list ${./system_c_symbols}
-
-    ld -macosx_version_min 10.7 -arch x86_64 -dylib \
-       -o $out/lib/system/libsystem_kernel.dylib \
-       /usr/lib/libSystem.dylib \
-       -reexported_symbols_list ${./system_kernel_symbols}
-
-    # The umbrella libSystem also exports some symbols,
-    # but we don't want to pull in everything from the other libraries.
-    ld -macosx_version_min 10.7 -arch x86_64 -dylib \
-       -o $out/lib/libSystem_internal.dylib \
-       /usr/lib/libSystem.dylib \
-       -reexported_symbols_list ${./system_symbols}
-
-    # We used to determine these impurely based on the host system, but then when we got some 10.12 Hydra boxes,
-    # one of them accidentally built this derivation, referenced libsystem_symptoms.dylib, which doesn't exist on
-    # 10.11, and then broke all subsequent builds on 10.11. By picking a 10.11 compatible subset of the libraries,
-    # we avoid scary impurity issues like that.
-    libs=$(cat ${./reexported_libraries} | grep -v '^#')
-
-    for i in $libs; do
-      if [ "$i" != "/usr/lib/system/libsystem_kernel.dylib" ] && [ "$i" != "/usr/lib/system/libsystem_c.dylib" ]; then
-        args="$args -reexport_library $i"
-      fi
-    done
-
-    ld -macosx_version_min 10.7 -arch x86_64 -dylib \
-       -o $out/lib/libSystem.B.dylib \
-       -compatibility_version 1.0 \
-       -current_version 1226.10.1 \
-       -reexport_library $out/lib/system/libsystem_c.dylib \
-       -reexport_library $out/lib/system/libsystem_kernel.dylib \
-       -reexport_library $out/lib/libSystem_internal.dylib \
-       $args
+    cp -vr \
+      ${darwin-stubs}/usr/lib/libSystem.B.tbd \
+      ${darwin-stubs}/usr/lib/system \
+      $out/lib
 
-    ln -s libSystem.B.dylib $out/lib/libSystem.dylib
+    substituteInPlace $out/lib/libSystem.B.tbd \
+      --replace "/usr/lib/system/" "$out/lib/system/"
+    ln -s libSystem.B.tbd $out/lib/libSystem.tbd
 
     # Set up links to pretend we work like a conventional unix (Apple's design, not mine!)
     for name in c dbm dl info m mx poll proc pthread rpcsvc util gcc_s.10.4 gcc_s.10.5; do
-      ln -s libSystem.dylib $out/lib/lib$name.dylib
+      ln -s libSystem.tbd $out/lib/lib$name.tbd
     done
 
     # This probably doesn't belong here, but we want to stay similar to glibc, which includes resolv internally...
@@ -144,13 +110,13 @@ appleDerivation {
     chmod +w $out/lib/libresolv.9.dylib
     install_name_tool \
       -id $out/lib/libresolv.9.dylib \
-      -change "$resolv_libSystem" $out/lib/libSystem.dylib \
+      -change "$resolv_libSystem" /usr/lib/libSystem.dylib \
       $out/lib/libresolv.9.dylib
     ln -s libresolv.9.dylib $out/lib/libresolv.dylib
   '';
 
-  meta = with stdenv.lib; {
-    description = "The Mac OS libc/libSystem (impure symlinks to binaries with pure headers)";
+  meta = with lib; {
+    description = "The Mac OS libc/libSystem (tapi library with pure headers)";
     maintainers = with maintainers; [ copumpkin gridaphobe ];
     platforms   = platforms.darwin;
     license     = licenses.apsl20;
diff --git a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/reexported_libraries b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/reexported_libraries
deleted file mode 100644
index edc2e759a29..00000000000
--- a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/reexported_libraries
+++ /dev/null
@@ -1,41 +0,0 @@
-# These are generated with otool -L /usr/lib/libSystem.dylib on a 10.11 machine
-/usr/lib/system/libcache.dylib
-/usr/lib/system/libcommonCrypto.dylib
-/usr/lib/system/libcompiler_rt.dylib
-/usr/lib/system/libcopyfile.dylib
-/usr/lib/system/libcorecrypto.dylib
-/usr/lib/system/libdispatch.dylib
-/usr/lib/system/libdyld.dylib
-/usr/lib/system/libkeymgr.dylib
-/usr/lib/system/liblaunch.dylib
-/usr/lib/system/libmacho.dylib
-/usr/lib/system/libquarantine.dylib
-/usr/lib/system/libremovefile.dylib
-/usr/lib/system/libsystem_asl.dylib
-/usr/lib/system/libsystem_blocks.dylib
-
-# We handle this specially in the expression
-# /usr/lib/system/libsystem_c.dylib
-
-/usr/lib/system/libsystem_configuration.dylib
-/usr/lib/system/libsystem_coreservices.dylib
-# /usr/lib/system/libsystem_coretls.dylib  # Removed in 10.13
-/usr/lib/system/libsystem_dnssd.dylib
-/usr/lib/system/libsystem_info.dylib
-
-# We handle this specially in the expression
-# /usr/lib/system/libsystem_kernel.dylib
-
-/usr/lib/system/libsystem_m.dylib
-/usr/lib/system/libsystem_malloc.dylib
-# /usr/lib/system/libsystem_network.dylib  # Removed in 10.14
-/usr/lib/system/libsystem_networkextension.dylib
-/usr/lib/system/libsystem_notify.dylib
-/usr/lib/system/libsystem_platform.dylib
-/usr/lib/system/libsystem_pthread.dylib
-/usr/lib/system/libsystem_sandbox.dylib
-/usr/lib/system/libsystem_secinit.dylib
-/usr/lib/system/libsystem_trace.dylib
-/usr/lib/system/libunc.dylib
-/usr/lib/system/libunwind.dylib
-/usr/lib/system/libxpc.dylib
diff --git a/pkgs/os-specific/darwin/apple-source-releases/Security/boot.nix b/pkgs/os-specific/darwin/apple-source-releases/Security/boot.nix
index e04142b8b11..b819057f0c1 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/Security/boot.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/Security/boot.nix
@@ -1,4 +1,4 @@
-{ appleDerivation }:
+{ appleDerivation, darwin-stubs }:
 
 appleDerivation {
   phases = [ "unpackPhase" "installPhase" ];
@@ -12,14 +12,15 @@ appleDerivation {
   ];
 
   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
+
+    ###### IMPURITIES
+    ln -s /System/Library/Frameworks/Security.framework/{Resources,Plugins,XPCServices} \
+      $out/Library/Frameworks/Security.framework
+
+    ###### STUBS
+    cp ${darwin-stubs}/System/Library/Frameworks/Security.framework/Versions/A/Security.tbd \
+      $out/Library/Frameworks/Security.framework
 
     ###### HEADERS
 
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
index 2a2d4cbe493..4f719ef8463 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/boot.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/boot.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation, fetchzip, bsdmake, perl, flex, yacc
+{ lib, stdenv, appleDerivation, fetchzip, bsdmake, perl, flex, yacc
 }:
 
 # this derivation sucks
@@ -85,7 +85,7 @@ in appleDerivation {
   setOutputFlags = false;
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
-    maintainers = with stdenv.lib.maintainers; [ gridaphobe ];
+    platforms = lib.platforms.darwin;
+    maintainers = with 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 0cbd7d81b90..614bdf570f3 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,29 +1,24 @@
-{ stdenv, appleDerivation, xcbuild, ncurses, libutil }:
+{ lib, stdenv, appleDerivation, xcbuild, ncurses, libutil }:
 
 appleDerivation {
   # We can't just run the root build, because https://github.com/facebook/xcbuild/issues/264
 
+  patchPhase = ''
+    substituteInPlace adv_cmds.xcodeproj/project.pbxproj \
+      --replace '/usr/lib/libtermcap.dylib' 'libncurses.dylib'
+  '';
+
   # 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'
-  '';
-
   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)
+                | grep -v -e Desktop -e Embedded -e mklocale -e pkill -e pgrep -e colldef)
 
     for i in $targets; do
       xcodebuild SYMROOT=$PWD/Products OBJROOT=$PWD/Intermediates -target $i
@@ -34,7 +29,7 @@ appleDerivation {
   installPhase = ''
     for f in Products/Release/*; do
       if [ -f $f ]; then
-        install -D $file $out/bin/$(basename $f)
+        install -D $f $out/bin/$(basename $f)
       fi
     done
 
@@ -50,7 +45,7 @@ appleDerivation {
   buildInputs = [ ncurses libutil ];
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
-    maintainers = with stdenv.lib.maintainers; [ matthewbauer ];
+    platforms = lib.platforms.darwin;
+    maintainers = with lib.maintainers; [ matthewbauer ];
   };
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/architecture/default.nix b/pkgs/os-specific/darwin/apple-source-releases/architecture/default.nix
index ebeb3ef0884..f7503dbb953 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/architecture/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/architecture/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation }:
+{ lib, stdenv, appleDerivation }:
 
 appleDerivation {
   dontBuild = true;
@@ -13,7 +13,7 @@ appleDerivation {
 
   DSTROOT = "$(out)";
 
-  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/basic_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/basic_cmds/default.nix
index eadf18e028e..8cff145661f 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/basic_cmds/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/basic_cmds/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation, xcbuildHook }:
+{ lib, stdenv, appleDerivation, xcbuildHook }:
 
 appleDerivation {
   nativeBuildInputs = [ xcbuildHook ];
@@ -26,7 +26,7 @@ appleDerivation {
   '';
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
-    maintainers = with stdenv.lib.maintainers; [ matthewbauer ];
+    platforms = lib.platforms.darwin;
+    maintainers = with 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 256781f61b1..5819101e10a 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
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation, yacc, flex }:
+{ lib, stdenv, appleDerivation, yacc, flex }:
 
 appleDerivation {
   nativeBuildInputs = [ yacc flex ];
@@ -44,6 +44,6 @@ appleDerivation {
   '';
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
+    platforms = lib.platforms.darwin;
   };
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/bsdmake/default.nix b/pkgs/os-specific/darwin/apple-source-releases/bsdmake/default.nix
index 043c7b0bc70..5a5a603eae8 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/bsdmake/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/bsdmake/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation, makeWrapper }:
+{ lib, stdenv, appleDerivation, makeWrapper }:
 
 appleDerivation {
   nativeBuildInputs = [ makeWrapper ];
@@ -44,6 +44,6 @@ appleDerivation {
   '';
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
+    platforms = lib.platforms.darwin;
   };
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/default.nix b/pkgs/os-specific/darwin/apple-source-releases/default.nix
index 14c69b84eb4..12176fd526c 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, fetchzip, pkgs }:
+{ lib, stdenv, fetchurl, fetchzip, pkgs }:
 
 let
   # This attrset can in theory be computed automatically, but for that to work nicely we need
@@ -152,7 +152,7 @@ let
     name = "${name}-${version}";
     enableParallelBuilding = true;
     meta = {
-      platforms = stdenv.lib.platforms.darwin;
+      platforms = lib.platforms.darwin;
     };
   } // (if attrs ? srcs then {} else {
     src  = fetchApple version sha256 name;
@@ -160,7 +160,7 @@ let
 
   applePackage = namePath: version: sha256:
     let
-      name = builtins.elemAt (stdenv.lib.splitString "/" namePath) 0;
+      name = builtins.elemAt (lib.splitString "/" namePath) 0;
       appleDerivation = appleDerivation_ name version sha256;
       callPackage = pkgs.newScope (packages // pkgs.darwin // { inherit appleDerivation name version; });
     in callPackage (./. + "/${namePath}");
@@ -187,7 +187,7 @@ let
     # There should be an IOVideo here, but they haven't released it :(
   };
 
-  IOKitSrcs = stdenv.lib.mapAttrs (name: value: if stdenv.lib.isFunction value then value name else value) IOKitSpecs;
+  IOKitSrcs = lib.mapAttrs (name: value: if lib.isFunction value then value name else value) IOKitSpecs;
 
   # 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" {};
diff --git a/pkgs/os-specific/darwin/apple-source-releases/developer_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/developer_cmds/default.nix
index cfd13b1b049..db57537bacb 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/developer_cmds/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/developer_cmds/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation, xcbuildHook, llvmPackages }:
+{ lib, stdenv, appleDerivation, xcbuildHook, llvmPackages }:
 
 appleDerivation {
   nativeBuildInputs = [ xcbuildHook ];
@@ -30,7 +30,7 @@ appleDerivation {
   '';
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
-    maintainers = with stdenv.lib.maintainers; [ matthewbauer ];
+    platforms = lib.platforms.darwin;
+    maintainers = with lib.maintainers; [ matthewbauer ];
   };
 }
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 6d3bd103811..e46e826053f 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,4 +1,4 @@
-{ stdenv, appleDerivation, xcbuildHook
+{ lib, stdenv, appleDerivation, xcbuildHook
 , Libc, xnu, libutil }:
 
 appleDerivation {
@@ -32,7 +32,7 @@ appleDerivation {
   '';
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
-    maintainers = with stdenv.lib.maintainers; [ matthewbauer ];
+    platforms = lib.platforms.darwin;
+    maintainers = with lib.maintainers; [ matthewbauer ];
   };
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/dyld/default.nix b/pkgs/os-specific/darwin/apple-source-releases/dyld/default.nix
index ddadf1f3940..4a72ea337eb 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/dyld/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/dyld/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation }:
+{ lib, stdenv, appleDerivation }:
 
 appleDerivation {
   installPhase = ''
@@ -7,7 +7,7 @@ appleDerivation {
     cp -r include $out/
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "Impure primitive symlinks to the Mac OS native dyld, along with headers";
     maintainers = with maintainers; [ copumpkin ];
     platforms   = platforms.darwin;
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 5de84d2a6e5..407117f1dbd 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,4 +1,4 @@
-{ stdenv, appleDerivation, xcbuildHook, zlib, bzip2, lzma, ncurses, libutil }:
+{ lib, stdenv, appleDerivation, xcbuildHook, zlib, bzip2, lzma, ncurses, libutil }:
 
 appleDerivation {
   nativeBuildInputs = [ xcbuildHook ];
@@ -32,7 +32,7 @@ appleDerivation {
   '';
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
-    maintainers = with stdenv.lib.maintainers; [ matthewbauer ];
+    platforms = lib.platforms.darwin;
+    maintainers = with lib.maintainers; [ matthewbauer ];
   };
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/hfs/default.nix b/pkgs/os-specific/darwin/apple-source-releases/hfs/default.nix
index ab294b143d3..58f6fb8d7ab 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/hfs/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/hfs/default.nix
@@ -5,4 +5,10 @@ appleDerivation {
     mkdir -p $out/include/hfs
     cp core/*.h $out/include/hfs
   '';
+
+  meta = {
+    # Seems nobody wants its binary, so we didn't implement building.
+    broken = !headersOnly;
+    platforms = lib.platforms.darwin;
+  };
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libauto/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libauto/default.nix
index b2ef3374ca2..8a551dcc892 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/libauto/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/libauto/default.nix
@@ -1,8 +1,8 @@
-{ stdenv, appleDerivation, libdispatch, Libsystem }:
+{ lib, stdenv, appleDerivation, libdispatch, Libsystem }:
 
 appleDerivation {
   # these are included in the pure libc
-  buildInputs = stdenv.lib.optionals stdenv.cc.nativeLibc [ libdispatch Libsystem ];
+  buildInputs = lib.optionals stdenv.cc.nativeLibc [ libdispatch Libsystem ];
 
   buildPhase = ''
     cp ${./auto_dtrace.h} ./auto_dtrace.h
@@ -79,6 +79,8 @@ appleDerivation {
   '';
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
+    # libauto is only used by objc4/pure.nix , but objc4 is now using the impure approach, so we don't bother to fix this.
+    broken = true;
+    platforms = lib.platforms.darwin;
   };
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix
index 0532c88b66b..72ef086f599 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix
@@ -1,6 +1,6 @@
 { stdenv, appleDerivation, lib
-, enableStatic ? stdenv.targetPlatform.isiOS
-, enableShared ? !stdenv.targetPlatform.isiOS
+, enableStatic ? stdenv.hostPlatform.isStatic
+, enableShared ? !stdenv.hostPlatform.isStatic
 }:
 
 appleDerivation {
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libpthread/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libpthread/default.nix
index 650c6415def..ceb4b18df17 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/libpthread/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/libpthread/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation, libdispatch, xnu }:
+{ lib, stdenv, appleDerivation, libdispatch, xnu }:
 
 appleDerivation {
   propagatedBuildInputs = [ libdispatch xnu ];
@@ -16,6 +16,6 @@ appleDerivation {
   '';
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
+    platforms = lib.platforms.darwin;
   };
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libunwind/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libunwind/default.nix
index bd219ae434c..24986e28852 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/libunwind/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/libunwind/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation }:
+{ lib, stdenv, appleDerivation }:
 
 appleDerivation {
   buildPhase = ":";
@@ -9,7 +9,7 @@ appleDerivation {
     cp -R include $out/include
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     maintainers = with maintainers; [ copumpkin lnl7 ];
     platforms   = platforms.darwin;
     license     = licenses.apsl20;
diff --git a/pkgs/os-specific/darwin/apple-source-releases/network_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/network_cmds/default.nix
index 82be7dc860e..f216a820dd4 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/network_cmds/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/network_cmds/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation, xcbuildHook
+{ lib, stdenv, appleDerivation, xcbuildHook
 , openssl_1_0_2, Librpcsvc, xnu, libpcap, developer_cmds }:
 
 appleDerivation {
@@ -44,7 +44,7 @@ appleDerivation {
  '';
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
-    maintainers = with stdenv.lib.maintainers; [ matthewbauer ];
+    platforms = lib.platforms.darwin;
+    maintainers = with lib.maintainers; [ matthewbauer ];
   };
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/objc4/default.nix b/pkgs/os-specific/darwin/apple-source-releases/objc4/default.nix
index a7cedaaea11..2fc4afa77d9 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/objc4/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/objc4/default.nix
@@ -1,4 +1,4 @@
-{ appleDerivation }:
+{ appleDerivation, darwin-stubs }:
 
 appleDerivation {
   phases = [ "unpackPhase" "installPhase" ];
@@ -14,7 +14,8 @@ appleDerivation {
 
   installPhase = ''
     mkdir -p $out/include/objc $out/lib
-    ln -s /usr/lib/libobjc.dylib $out/lib/libobjc.dylib
+    cp ${darwin-stubs}/usr/lib/libobjc.A.tbd $out/lib/libobjc.A.tbd
+    ln -s libobjc.A.tbd $out/lib/libobjc.tbd
     cp runtime/OldClasses.subproj/List.h $out/include/objc/List.h
     cp runtime/NSObjCRuntime.h $out/include/objc/NSObjCRuntime.h
     cp runtime/NSObject.h $out/include/objc/NSObject.h
diff --git a/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/default.nix
index b87dadd391d..771dd41b575 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation, xcbuildHook }:
+{ lib, stdenv, appleDerivation, xcbuildHook }:
 
 appleDerivation {
   nativeBuildInputs = [ xcbuildHook ];
@@ -44,7 +44,7 @@ appleDerivation {
   '';
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
-    maintainers = with stdenv.lib.maintainers; [ matthewbauer ];
+    platforms = lib.platforms.darwin;
+    maintainers = with lib.maintainers; [ matthewbauer ];
   };
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/system_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/system_cmds/default.nix
index 16454cbc1a5..34d093b7cc0 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/system_cmds/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/system_cmds/default.nix
@@ -98,7 +98,7 @@ appleDerivation {
   '';
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
-    maintainers = with stdenv.lib.maintainers; [ shlevy matthewbauer ];
+    platforms = lib.platforms.darwin;
+    maintainers = with lib.maintainers; [ shlevy matthewbauer ];
   };
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/text_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/text_cmds/default.nix
index 14d7a5e3b32..d5dca4a3035 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/text_cmds/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/text_cmds/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, appleDerivation, xcbuildHook, ncurses, bzip2, zlib, lzma }:
+{ lib, stdenv, appleDerivation, xcbuildHook, ncurses, bzip2, zlib, lzma }:
 
 appleDerivation {
   nativeBuildInputs = [ xcbuildHook ];
@@ -21,7 +21,7 @@ appleDerivation {
   '';
 
   meta = {
-    platforms = stdenv.lib.platforms.darwin;
-    maintainers = with stdenv.lib.maintainers; [ matthewbauer ];
+    platforms = lib.platforms.darwin;
+    maintainers = with lib.maintainers; [ matthewbauer ];
   };
 }
diff --git a/pkgs/os-specific/darwin/binutils/default.nix b/pkgs/os-specific/darwin/binutils/default.nix
index fad33b21d04..e9aa706da2d 100644
--- a/pkgs/os-specific/darwin/binutils/default.nix
+++ b/pkgs/os-specific/darwin/binutils/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, binutils-unwrapped, cctools, llvm }:
+{ lib, stdenv, binutils-unwrapped, cctools, llvm }:
 
 # Make sure both underlying packages claim to have prepended their binaries
 # with the same targetPrefix.
@@ -32,7 +32,7 @@ stdenv.mkDerivation {
     # - strip: the binutils one seems to break mach-o files
     # - lipo: gcc build assumes it exists
     # - nm: the gnu one doesn't understand many new load commands
-    for i in ${stdenv.lib.concatStringsSep " " (builtins.map (e: targetPrefix + e) cmds)}; do
+    for i in ${lib.concatStringsSep " " (builtins.map (e: targetPrefix + e) cmds)}; do
       ln -sf "${cctools}/bin/$i" "$out/bin/$i"
     done
 
@@ -56,7 +56,7 @@ stdenv.mkDerivation {
   };
 
   meta = {
-    maintainers = with stdenv.lib.maintainers; [ matthewbauer ];
+    maintainers = with lib.maintainers; [ matthewbauer ];
     priority = 10;
   };
 }
diff --git a/pkgs/os-specific/darwin/cctools/port.nix b/pkgs/os-specific/darwin/cctools/port.nix
index 64f1490a7a7..50e0a2eb3fb 100644
--- a/pkgs/os-specific/darwin/cctools/port.nix
+++ b/pkgs/os-specific/darwin/cctools/port.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, autoconf, automake, libtool, autoreconfHook
+{ lib, stdenv, fetchFromGitHub, autoconf, automake, libtool, autoreconfHook
 , installShellFiles
 , libcxxabi, libuuid
 , libobjc ? null, maloader ? null
@@ -9,7 +9,7 @@ let
 
   # The targetPrefix prepended to binary names to allow multiple binuntils on the
   # PATH to both be usable.
-  targetPrefix = stdenv.lib.optionalString
+  targetPrefix = lib.optionalString
     (stdenv.targetPlatform != stdenv.hostPlatform)
     "${stdenv.targetPlatform.config}-";
 in
@@ -32,8 +32,8 @@ stdenv.mkDerivation {
 
   nativeBuildInputs = [ autoconf automake libtool autoreconfHook installShellFiles ];
   buildInputs = [ libuuid ]
-    ++ stdenv.lib.optionals stdenv.isDarwin [ libcxxabi libobjc ]
-    ++ stdenv.lib.optional enableTapiSupport libtapi;
+    ++ lib.optionals stdenv.isDarwin [ libcxxabi libobjc ]
+    ++ lib.optional enableTapiSupport libtapi;
 
   patches = [ ./ld-ignore-rpath-link.patch ./ld-rpath-nonfinal.patch ];
 
@@ -47,14 +47,14 @@ stdenv.mkDerivation {
 
   # TODO(@Ericson2314): Always pass "--target" and always targetPrefix.
   configurePlatforms = [ "build" "host" ]
-    ++ stdenv.lib.optional (stdenv.targetPlatform != stdenv.hostPlatform) "target";
+    ++ lib.optional (stdenv.targetPlatform != stdenv.hostPlatform) "target";
   configureFlags = [ "--disable-clang-as" ]
-    ++ stdenv.lib.optionals enableTapiSupport [
+    ++ lib.optionals enableTapiSupport [
       "--enable-tapi-support"
       "--with-libtapi=${libtapi}"
     ];
 
-  postPatch = stdenv.lib.optionalString stdenv.hostPlatform.isDarwin ''
+  postPatch = 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
@@ -100,7 +100,7 @@ stdenv.mkDerivation {
     broken = !stdenv.targetPlatform.isDarwin; # Only supports darwin targets
     homepage = "http://www.opensource.apple.com/source/cctools/";
     description = "MacOS Compiler Tools (cross-platform port)";
-    license = stdenv.lib.licenses.apsl20;
-    maintainers = with stdenv.lib.maintainers; [ matthewbauer ];
+    license = lib.licenses.apsl20;
+    maintainers = with lib.maintainers; [ matthewbauer ];
   };
 }
diff --git a/pkgs/os-specific/darwin/chunkwm/default.nix b/pkgs/os-specific/darwin/chunkwm/default.nix
index d94f66969f4..b326b98de53 100644
--- a/pkgs/os-specific/darwin/chunkwm/default.nix
+++ b/pkgs/os-specific/darwin/chunkwm/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchzip, Carbon, Cocoa, ScriptingBridge }:
+{ lib, stdenv, fetchzip, Carbon, Cocoa, ScriptingBridge }:
 
 stdenv.mkDerivation rec {
   pname = "chunkwm";
@@ -26,7 +26,7 @@ stdenv.mkDerivation rec {
     cp plugins/*.so $out/lib/chunkwm/plugins
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "Tiling window manager for macOS based on plugin architecture";
     homepage = "https://github.com/koekeishiya/chunkwm";
     platforms = platforms.darwin;
diff --git a/pkgs/os-specific/darwin/darling/default.nix b/pkgs/os-specific/darwin/darling/default.nix
index 846831d0a87..ef9afafbcd3 100644
--- a/pkgs/os-specific/darwin/darling/default.nix
+++ b/pkgs/os-specific/darwin/darling/default.nix
@@ -31,8 +31,6 @@ stdenv.mkDerivation rec {
     cp src/libaks/include/* $out/include
   '';
 
-  # buildInputs = [ cmake bison flex ];
-
   meta = with lib; {
     maintainers = with maintainers; [ matthewbauer ];
     license = licenses.gpl3;
diff --git a/pkgs/os-specific/darwin/darwin-stubs/default.nix b/pkgs/os-specific/darwin/darwin-stubs/default.nix
new file mode 100644
index 00000000000..aa946eb5bf0
--- /dev/null
+++ b/pkgs/os-specific/darwin/darwin-stubs/default.nix
@@ -0,0 +1,18 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation {
+  pname = "darwin-stubs";
+  version = "10.12";
+
+  src = fetchurl {
+    url = "https://github.com/NixOS/darwin-stubs/releases/download/v20201216/10.12.tar.gz";
+    sha256 = "1fyd3xig7brkzlzp0ql7vyfj5sp8iy56kgp548mvicqdyw92adgm";
+  };
+
+  dontBuild = true;
+
+  installPhase = ''
+    mkdir $out
+    mv * $out
+  '';
+}
diff --git a/pkgs/os-specific/darwin/discrete-scroll/default.nix b/pkgs/os-specific/darwin/discrete-scroll/default.nix
index e72402b7793..f38bf8d8132 100644
--- a/pkgs/os-specific/darwin/discrete-scroll/default.nix
+++ b/pkgs/os-specific/darwin/discrete-scroll/default.nix
@@ -31,5 +31,6 @@ stdenv.mkDerivation rec {
     homepage = "https://github.com/emreyolcu/discrete-scroll";
     platforms = platforms.darwin;
     license = licenses.mit;
+    maintainers = with lib.maintainers; [ bb2020 ];
   };
 }
diff --git a/pkgs/os-specific/darwin/goku/default.nix b/pkgs/os-specific/darwin/goku/default.nix
index f6834fca735..b65547ff32f 100644
--- a/pkgs/os-specific/darwin/goku/default.nix
+++ b/pkgs/os-specific/darwin/goku/default.nix
@@ -1,4 +1,4 @@
-{stdenv, fetchurl }:
+{lib, stdenv, fetchurl }:
 
 stdenv.mkDerivation rec {
   pname = "goku";
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
     cp gokuw $out/bin
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "Karabiner configurator";
     homepage = "https://github.com/yqrashawn/GokuRakuJoudo";
     license = licenses.gpl3;
diff --git a/pkgs/os-specific/darwin/insert_dylib/default.nix b/pkgs/os-specific/darwin/insert_dylib/default.nix
index 0ab6a415707..07e8886e3e6 100644
--- a/pkgs/os-specific/darwin/insert_dylib/default.nix
+++ b/pkgs/os-specific/darwin/insert_dylib/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, xcbuildHook }:
+{ lib, stdenv, fetchFromGitHub, xcbuildHook }:
 
 stdenv.mkDerivation
   { name = "insert_dylib-2016.08.28";
@@ -14,5 +14,5 @@ stdenv.mkDerivation
         mkdir -p $out/bin
         install -m755 Products/Release/insert_dylib $out/bin
       '';
-    meta.platforms = stdenv.lib.platforms.darwin;
+    meta.platforms = lib.platforms.darwin;
   }
diff --git a/pkgs/os-specific/darwin/iproute2mac/default.nix b/pkgs/os-specific/darwin/iproute2mac/default.nix
index edf1583de9a..915ef7c9158 100644
--- a/pkgs/os-specific/darwin/iproute2mac/default.nix
+++ b/pkgs/os-specific/darwin/iproute2mac/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, darwin, python2 }:
+{ lib, stdenv, fetchFromGitHub, darwin, python2 }:
 
 stdenv.mkDerivation rec {
   version = "1.2.1";
@@ -28,7 +28,7 @@ stdenv.mkDerivation rec {
     install -D -m 755 src/ip.py $out/bin/ip
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     homepage = "https://github.com/brona/iproute2mac";
     description = "CLI wrapper for basic network utilites on Mac OS X inspired with iproute2 on Linux systems - ip command.";
     license = licenses.mit;
diff --git a/pkgs/os-specific/darwin/khd/default.nix b/pkgs/os-specific/darwin/khd/default.nix
index b09b65f33d5..87e1a8bf6ae 100644
--- a/pkgs/os-specific/darwin/khd/default.nix
+++ b/pkgs/os-specific/darwin/khd/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, fetchpatch, Carbon, Cocoa }:
+{ lib, stdenv, fetchFromGitHub, fetchpatch, Carbon, Cocoa }:
 
 stdenv.mkDerivation rec {
   pname = "khd";
@@ -34,7 +34,7 @@ stdenv.mkDerivation rec {
     substituteInPlace $out/Library/LaunchDaemons/org.nixos.khd.plist --subst-var out
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "A simple modal hotkey daemon for OSX";
     homepage = "https://github.com/koekeishiya/khd";
     downloadPage = "https://github.com/koekeishiya/khd/releases";
diff --git a/pkgs/os-specific/darwin/kwm/default.nix b/pkgs/os-specific/darwin/kwm/default.nix
index 8c412aa68ed..273ea7345d9 100644
--- a/pkgs/os-specific/darwin/kwm/default.nix
+++ b/pkgs/os-specific/darwin/kwm/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchzip }:
+{ lib, stdenv, fetchzip }:
 
 stdenv.mkDerivation rec {
   pname = "kwm";
@@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
     substituteInPlace $out/Library/LaunchDaemons/org.nixos.kwm.plist --subst-var out
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "Tiling window manager with focus follows mouse for OSX";
     homepage = "https://github.com/koekeishiya/kwm";
     downloadPage = "https://github.com/koekeishiya/kwm/releases";
diff --git a/pkgs/os-specific/darwin/libtapi/default.nix b/pkgs/os-specific/darwin/libtapi/default.nix
index 1f1e00d13f9..8c83b4ae1e6 100644
--- a/pkgs/os-specific/darwin/libtapi/default.nix
+++ b/pkgs/os-specific/darwin/libtapi/default.nix
@@ -1,12 +1,14 @@
 { lib, stdenv, fetchFromGitHub, cmake, python3, ncurses }:
 
-stdenv.mkDerivation {
-  name = "libtapi-1000.10.8";
+stdenv.mkDerivation rec {
+  pname = "libtapi";
+  version = "1100.0.11"; # determined by looking at VERSION.txt
+
   src = fetchFromGitHub {
     owner = "tpoechtrager";
     repo = "apple-libtapi";
-    rev = "3cb307764cc5f1856c8a23bbdf3eb49dfc6bea48";
-    sha256 = "1zb10p6xkls8x7wsdwgy9c0v16z97rfkgidii9ffq5rfczgvrhjh";
+    rev = "664b8414f89612f2dfd35a9b679c345aa5389026";
+    sha256 = "1y1yl46msabfy14z0rln333a06087bk14f5h7q1cdawn8nmvbdbr";
   };
 
   sourceRoot = "source/src/llvm";
@@ -29,15 +31,17 @@ stdenv.mkDerivation {
     cmakeFlagsArray+=(-DCMAKE_CXX_FLAGS="$INCLUDE_FIX")
   '';
 
-  buildFlags = [ "clangBasic" "libtapi" ];
+  buildFlags = [ "clangBasic" "libtapi" "tapi" ];
 
-  installTargets = [ "install-libtapi" "install-tapi-headers" ];
+  installTargets = [ "install-libtapi" "install-tapi-headers" "install-tapi" ];
 
-  postInstall = ''
+  postInstall = lib.optionalString stdenv.isDarwin ''
     install_name_tool -id $out/lib/libtapi.dylib $out/lib/libtapi.dylib
   '';
 
   meta = with lib; {
+    description = "Replaces the Mach-O Dynamic Library Stub files in Apple's SDKs to reduce the size";
+    homepage = "https://github.com/tpoechtrager/apple-libtapi";
     license = licenses.apsl20;
     maintainers = with maintainers; [ matthewbauer ];
   };
diff --git a/pkgs/os-specific/darwin/lsusb/default.nix b/pkgs/os-specific/darwin/lsusb/default.nix
index 799a4761fbd..712e32f16fe 100644
--- a/pkgs/os-specific/darwin/lsusb/default.nix
+++ b/pkgs/os-specific/darwin/lsusb/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub }:
+{ lib, stdenv, fetchFromGitHub }:
 
 stdenv.mkDerivation {
   version = "1.0";
@@ -21,8 +21,8 @@ stdenv.mkDerivation {
   meta = {
     homepage = "https://github.com/jlhonora/lsusb";
     description = "lsusb command for Mac OS X";
-    platforms = stdenv.lib.platforms.darwin;
-    license = stdenv.lib.licenses.mit;
-    maintainers = [ stdenv.lib.maintainers.varunpatro ];
+    platforms = lib.platforms.darwin;
+    license = lib.licenses.mit;
+    maintainers = [ lib.maintainers.varunpatro ];
   };
 }
diff --git a/pkgs/os-specific/darwin/m-cli/default.nix b/pkgs/os-specific/darwin/m-cli/default.nix
index 2699bb8e140..b69849d8245 100644
--- a/pkgs/os-specific/darwin/m-cli/default.nix
+++ b/pkgs/os-specific/darwin/m-cli/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub }:
+{ lib, stdenv, fetchFromGitHub }:
 
 stdenv.mkDerivation rec {
   pname = "m-cli";
@@ -32,7 +32,7 @@ stdenv.mkDerivation rec {
     install -Dt "$out/share/zsh/site-functions/" -m444 completion/zsh/_m
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "Swiss Army Knife for macOS";
     inherit (src.meta) homepage;
     repositories.git = "git://github.com/rgcr/m-cli.git";
diff --git a/pkgs/os-specific/darwin/maloader/default.nix b/pkgs/os-specific/darwin/maloader/default.nix
index 0de94c92388..3943092bcf0 100644
--- a/pkgs/os-specific/darwin/maloader/default.nix
+++ b/pkgs/os-specific/darwin/maloader/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchgit, opencflite, clang, libcxx }:
+{ lib, stdenv, fetchgit, opencflite, clang, libcxx }:
 
 stdenv.mkDerivation {
   name = "maloader-0git";
@@ -31,8 +31,8 @@ stdenv.mkDerivation {
   meta = {
     description = "Mach-O loader for Linux";
     homepage = "https://github.com/shinh/maloader";
-    license = stdenv.lib.licenses.bsd2;
-    platforms = stdenv.lib.platforms.linux;
+    license = lib.licenses.bsd2;
+    platforms = lib.platforms.linux;
     broken = true; # 2018-09-08, no succesful build since 2017-08-21
   };
 }
diff --git a/pkgs/os-specific/darwin/noah/default.nix b/pkgs/os-specific/darwin/noah/default.nix
index 81f4ab2bd9e..f4d8a4b21a8 100644
--- a/pkgs/os-specific/darwin/noah/default.nix
+++ b/pkgs/os-specific/darwin/noah/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, cmake, Hypervisor }:
+{ lib, stdenv, fetchFromGitHub, cmake, Hypervisor }:
 
 stdenv.mkDerivation rec {
   pname = "noah";
@@ -14,7 +14,7 @@ stdenv.mkDerivation rec {
   nativeBuildInputs = [ cmake ];
   buildInputs = [ Hypervisor ];
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "Bash on Ubuntu on macOS";
     homepage = "https://github.com/linux-noah/noah";
     license = [ licenses.mit licenses.gpl2 ];
diff --git a/pkgs/os-specific/darwin/opencflite/default.nix b/pkgs/os-specific/darwin/opencflite/default.nix
index 26af46a171f..937d0763fef 100644
--- a/pkgs/os-specific/darwin/opencflite/default.nix
+++ b/pkgs/os-specific/darwin/opencflite/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, icu, libuuid, tzdata }:
+{ lib, stdenv, fetchurl, icu, libuuid, tzdata }:
 
 stdenv.mkDerivation rec {
   pname = "opencflite";
@@ -16,6 +16,6 @@ stdenv.mkDerivation rec {
   meta = {
     description = "Cross platform port of the macOS CoreFoundation";
     homepage = "https://sourceforge.net/projects/opencflite/";
-    license = stdenv.lib.licenses.apsl20;
+    license = lib.licenses.apsl20;
   };
 }
diff --git a/pkgs/os-specific/darwin/osx-cpu-temp/default.nix b/pkgs/os-specific/darwin/osx-cpu-temp/default.nix
new file mode 100644
index 00000000000..ea9d8399667
--- /dev/null
+++ b/pkgs/os-specific/darwin/osx-cpu-temp/default.nix
@@ -0,0 +1,31 @@
+{ lib, stdenv, fetchFromGitHub
+, IOKit
+}:
+
+stdenv.mkDerivation rec {
+  pname = "osx-cpu-temp";
+  version = "unstable-2020-12-04";
+
+  src = fetchFromGitHub rec {
+    name = "osx-cpu-temp-source";
+    owner = "lavoiesl";
+    repo = pname;
+    rev = "6ec951be449badcb7fb84676bbc2c521e600e844";
+    sha256 = "1nlibgr55bpln6jbdf8vqcp0fj9zv9343vflb7s9w0yh33fsbg9d";
+  };
+
+  buildInputs = [ IOKit ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp osx-cpu-temp $out/bin
+  '';
+
+  meta = with lib; {
+    description = "Outputs current CPU temperature for OSX.";
+    homepage = "https://github.com/lavoiesl/osx-cpu-temp";
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ virusdave ];
+    platforms = platforms.darwin;
+  };
+}
diff --git a/pkgs/os-specific/darwin/osxfuse/default.nix b/pkgs/os-specific/darwin/osxfuse/default.nix
index e13a0842012..d0f6b0f5311 100644
--- a/pkgs/os-specific/darwin/osxfuse/default.nix
+++ b/pkgs/os-specific/darwin/osxfuse/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, runCommand, fetchFromGitHub, autoreconfHook }:
+{ lib, stdenv, runCommand, fetchFromGitHub, autoreconfHook }:
 
 let
   version = "3.8.3";
@@ -39,7 +39,7 @@ stdenv.mkDerivation {
   nativeBuildInputs = [ autoreconfHook ];
   buildInputs = [ headers ];
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     homepage = "https://osxfuse.github.io";
     description = "C-based FUSE for macOS SDK";
     platforms = platforms.darwin;
diff --git a/pkgs/os-specific/darwin/osxsnarf/default.nix b/pkgs/os-specific/darwin/osxsnarf/default.nix
index d9a0de6c7f1..e31271ed2b9 100644
--- a/pkgs/os-specific/darwin/osxsnarf/default.nix
+++ b/pkgs/os-specific/darwin/osxsnarf/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
   makeFlags = [ "prefix=${placeholder "out"}" ];
 
   meta = with lib; {
-    description = "A Plan 9-inspired way to share your OS X clipboard.";
+    description = "A Plan 9-inspired way to share your OS X clipboard";
     homepage = "https://github.com/eraserhd/osxsnarf";
     license = licenses.unlicense;
     platforms = platforms.darwin;
diff --git a/pkgs/os-specific/darwin/qes/default.nix b/pkgs/os-specific/darwin/qes/default.nix
index f231ee57167..dce6e526626 100644
--- a/pkgs/os-specific/darwin/qes/default.nix
+++ b/pkgs/os-specific/darwin/qes/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, Carbon }:
+{ lib, stdenv, fetchFromGitHub, Carbon }:
 
 stdenv.mkDerivation {
   pname = "qes";
@@ -15,7 +15,7 @@ stdenv.mkDerivation {
 
   makeFlags = [ "BUILD_PATH=$(out)/bin" ];
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "Quartz Event Synthesizer";
     homepage = "https://github.com/koekeishiya/qes";
     platforms = platforms.darwin;
diff --git a/pkgs/os-specific/darwin/reattach-to-user-namespace/default.nix b/pkgs/os-specific/darwin/reattach-to-user-namespace/default.nix
index 768ca6cf9c9..dedc7578951 100644
--- a/pkgs/os-specific/darwin/reattach-to-user-namespace/default.nix
+++ b/pkgs/os-specific/darwin/reattach-to-user-namespace/default.nix
@@ -1,12 +1,14 @@
-{ stdenv, fetchurl }:
+{ lib, stdenv, fetchFromGitHub }:
 
 stdenv.mkDerivation rec {
   pname = "reattach-to-user-namespace";
-  version = "2.8";
+  version = "2.9";
 
-  src = fetchurl {
-    url = "https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard/archive/v${version}.tar.gz";
-    sha256 = "0xxxdd26rcplhpvi2vy6crxadk3d1qkq4xry10lwq6dyya2jf6wb";
+  src = fetchFromGitHub {
+    owner = "ChrisJohnsen";
+    repo = "tmux-MacOSX-pasteboard";
+    rev = "v${version}";
+    sha256 = "1qgimh58hcx5f646gj2kpd36ayvrdkw616ad8cb3lcm11kg0ag79";
   };
 
   buildFlags = [ "ARCHES=x86_64" ];
@@ -16,7 +18,7 @@ stdenv.mkDerivation rec {
     cp reattach-to-user-namespace $out/bin/
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "A wrapper that provides access to the Mac OS X pasteboard service";
     license = licenses.bsd2;
     maintainers = with maintainers; [ lnl7 ];
diff --git a/pkgs/os-specific/darwin/skhd/default.nix b/pkgs/os-specific/darwin/skhd/default.nix
index d145c0d75d0..ad33cf713d0 100644
--- a/pkgs/os-specific/darwin/skhd/default.nix
+++ b/pkgs/os-specific/darwin/skhd/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, Carbon }:
+{ lib, stdenv, fetchFromGitHub, Carbon }:
 
 stdenv.mkDerivation rec {
   pname = "skhd";
@@ -21,7 +21,7 @@ stdenv.mkDerivation rec {
     substituteInPlace $out/Library/LaunchDaemons/org.nixos.skhd.plist --subst-var out
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "Simple hotkey daemon for macOS";
     homepage = "https://github.com/koekeishiya/skhd";
     platforms = platforms.darwin;
diff --git a/pkgs/os-specific/darwin/spacebar/default.nix b/pkgs/os-specific/darwin/spacebar/default.nix
index 7af7e408223..780347c60c5 100644
--- a/pkgs/os-specific/darwin/spacebar/default.nix
+++ b/pkgs/os-specific/darwin/spacebar/default.nix
@@ -1,14 +1,14 @@
-{ stdenv, fetchFromGitHub, Carbon, Cocoa, ScriptingBridge }:
+{ lib, stdenv, fetchFromGitHub, Carbon, Cocoa, ScriptingBridge }:
 
 stdenv.mkDerivation rec {
   pname = "spacebar";
-  version = "1.1.1";
+  version = "1.2.1";
 
   src = fetchFromGitHub {
     owner = "cmacrae";
     repo = pname;
     rev = "v${version}";
-    sha256 = "1x0wzm380nv81j26jqqg4y4dwanydnpdsca41ndw6xyj9zlv73f7";
+    sha256 = "0f5ddn3sx13rwwh0nfl784160s8ml3m5593d5fz2b1996aznzrsx";
   };
 
   buildInputs = [ Carbon Cocoa ScriptingBridge ];
@@ -20,7 +20,7 @@ stdenv.mkDerivation rec {
     cp ./doc/spacebar.1 $out/share/man/man1/spacebar.1
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "A minimal status bar for macOS";
     homepage = "https://github.com/cmacrae/spacebar";
     platforms = platforms.darwin;
diff --git a/pkgs/os-specific/darwin/stubs/default.nix b/pkgs/os-specific/darwin/stubs/default.nix
index 6fedf0a451e..e21f00beb5a 100644
--- a/pkgs/os-specific/darwin/stubs/default.nix
+++ b/pkgs/os-specific/darwin/stubs/default.nix
@@ -1,6 +1,6 @@
-{ stdenv, writeScriptBin, runtimeShell }:
+{ lib, stdenv, writeScriptBin, runtimeShell }:
 
-let fake = name: stdenv.lib.overrideDerivation (writeScriptBin name ''
+let fake = name: lib.overrideDerivation (writeScriptBin name ''
   #!${runtimeShell}
   echo >&2 "Faking call to ${name} with arguments:"
   echo >&2 "$@"
diff --git a/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix b/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix
index 059cb70bfbd..9f0ee4db118 100644
--- a/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix
+++ b/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, fetchurl, ninja, python3, curl, libxml2, objc4, ICU }:
+{ lib, stdenv, fetchFromGitHub, fetchurl, ninja, python3, curl, libxml2, objc4, ICU }:
 
 let
   # 10.12 adds a new sysdir.h that our version of CF in the main derivation depends on, but
@@ -74,7 +74,7 @@ stdenv.mkDerivation {
   # Based on testing this issue seems to only occur with clang_7, so
   # please remove this when updating the default llvm versions to 8 or
   # later.
-  buildPhase = stdenv.lib.optionalString true ''
+  buildPhase = lib.optionalString true ''
     for i in {1..512}; do
         if ninja -j $NIX_BUILD_CORES; then
             break
diff --git a/pkgs/os-specific/darwin/swift-corelibs/libdispatch.nix b/pkgs/os-specific/darwin/swift-corelibs/libdispatch.nix
index bd143b6071b..a5b4b2a52df 100644
--- a/pkgs/os-specific/darwin/swift-corelibs/libdispatch.nix
+++ b/pkgs/os-specific/darwin/swift-corelibs/libdispatch.nix
@@ -8,5 +8,6 @@ stdenv.mkDerivation rec {
     rev = "f83b5a498bad8e9ff8916183cf6e8ccf677c346b";
     sha256 = "1czkyyc9llq2mnqfp19mzcfsxzas0y8zrk0gr5hg60acna6jkz2l";
   };
-  buildInputs = [ cmake apple_sdk_sierra.sdk xnu-new ];
+  nativeBuildInputs = [ cmake ];
+  buildInputs = [ apple_sdk_sierra.sdk xnu-new ];
 }
diff --git a/pkgs/os-specific/darwin/trash/default.nix b/pkgs/os-specific/darwin/trash/default.nix
index 205391a52da..ea5786f6a56 100644
--- a/pkgs/os-specific/darwin/trash/default.nix
+++ b/pkgs/os-specific/darwin/trash/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, perl, AppKit, Cocoa, ScriptingBridge }:
+{ lib, stdenv, fetchFromGitHub, perl, AppKit, Cocoa, ScriptingBridge }:
 
 stdenv.mkDerivation rec {
   version = "0.9.2";
@@ -28,7 +28,7 @@ stdenv.mkDerivation rec {
     homepage = "https://github.com/ali-rantakari/trash";
     description = "Small command-line program for OS X that moves files or
     folders to the trash.";
-    platforms = stdenv.lib.platforms.darwin;
-    license = stdenv.lib.licenses.mit;
+    platforms = lib.platforms.darwin;
+    license = lib.licenses.mit;
   };
 }
diff --git a/pkgs/os-specific/darwin/usr-include/default.nix b/pkgs/os-specific/darwin/usr-include/default.nix
index 4fef1388764..26b60ea44f5 100644
--- a/pkgs/os-specific/darwin/usr-include/default.nix
+++ b/pkgs/os-specific/darwin/usr-include/default.nix
@@ -1,4 +1,4 @@
-{stdenv, darwin}:
+{lib, stdenv, darwin}:
 
 /*
  * This is needed to build GCC on Darwin.
@@ -19,5 +19,5 @@ stdenv.mkDerivation {
     ln -sf ${darwin.CF}/Library/Frameworks/CoreFoundation.framework/Headers/* CoreFoundation
   '';
 
-  meta.platforms = stdenv.lib.platforms.darwin;
+  meta.platforms = lib.platforms.darwin;
 }
diff --git a/pkgs/os-specific/darwin/wifi-password/default.nix b/pkgs/os-specific/darwin/wifi-password/default.nix
index 2dfc97dec1b..f66af1ddfb5 100644
--- a/pkgs/os-specific/darwin/wifi-password/default.nix
+++ b/pkgs/os-specific/darwin/wifi-password/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub }:
+{ lib, stdenv, fetchFromGitHub }:
 
 stdenv.mkDerivation rec {
   version = "0.1.0";
@@ -19,8 +19,8 @@ stdenv.mkDerivation rec {
   meta = {
     homepage = "https://github.com/rauchg/wifi-password";
     description = "Get the password of the wifi you're on";
-    platforms = stdenv.lib.platforms.darwin;
-    license = stdenv.lib.licenses.mit;
-    maintainers = [ stdenv.lib.maintainers.nikitavoloboev ];
+    platforms = lib.platforms.darwin;
+    license = lib.licenses.mit;
+    maintainers = [ lib.maintainers.nikitavoloboev ];
   };
 }
diff --git a/pkgs/os-specific/darwin/xcode/sdk-pkgs.nix b/pkgs/os-specific/darwin/xcode/sdk-pkgs.nix
index 45e1f1eab4f..cc485bb62c6 100644
--- a/pkgs/os-specific/darwin/xcode/sdk-pkgs.nix
+++ b/pkgs/os-specific/darwin/xcode/sdk-pkgs.nix
@@ -37,9 +37,9 @@ rec {
     bintools = binutils-unwrapped;
     extraBuildCommands = ''
       echo "-arch ${iosPlatformArch targetPlatform}" >> $out/nix-support/libc-ldflags
-    '' + stdenv.lib.optionalString (sdk.platform == "iPhoneSimulator") ''
+    '' + lib.optionalString (sdk.platform == "iPhoneSimulator") ''
       echo "-platform_version ios-sim ${minSdkVersion} ${sdk.version}" >> $out/nix-support/libc-ldflags
-    '' + stdenv.lib.optionalString (sdk.platform == "iPhoneOS") ''
+    '' + lib.optionalString (sdk.platform == "iPhoneOS") ''
       echo "-platform_version ios ${minSdkVersion} ${sdk.version}" >> $out/nix-support/libc-ldflags
     '';
   };
@@ -54,9 +54,9 @@ rec {
       mv cc-cflags.tmp $out/nix-support/cc-cflags
       echo "-target ${targetPlatform.config} -arch ${iosPlatformArch targetPlatform}" >> $out/nix-support/cc-cflags
       echo "-isystem ${sdk}/usr/include${lib.optionalString (lib.versionAtLeast "10" sdk.version) " -isystem ${sdk}/usr/include/c++/4.2.1/ -stdlib=libstdc++"}" >> $out/nix-support/cc-cflags
-    '' + stdenv.lib.optionalString (sdk.platform == "iPhoneSimulator") ''
+    '' + lib.optionalString (sdk.platform == "iPhoneSimulator") ''
       echo "-mios-simulator-version-min=${minSdkVersion}" >> $out/nix-support/cc-cflags
-    '' + stdenv.lib.optionalString (sdk.platform == "iPhoneOS") ''
+    '' + lib.optionalString (sdk.platform == "iPhoneOS") ''
       echo "-miphoneos-version-min=${minSdkVersion}" >> $out/nix-support/cc-cflags
     '';
   }) // {
diff --git a/pkgs/os-specific/darwin/yabai/default.nix b/pkgs/os-specific/darwin/yabai/default.nix
index 742a3948707..b371e97d06f 100644
--- a/pkgs/os-specific/darwin/yabai/default.nix
+++ b/pkgs/os-specific/darwin/yabai/default.nix
@@ -1,14 +1,14 @@
-{ stdenv, fetchFromGitHub, Carbon, Cocoa, ScriptingBridge, xxd }:
+{ lib, stdenv, fetchFromGitHub, Carbon, Cocoa, ScriptingBridge, xxd }:
 
 stdenv.mkDerivation rec {
   pname = "yabai";
-  version = "3.3.0";
+  version = "3.3.4";
 
   src = fetchFromGitHub {
     owner = "koekeishiya";
     repo = pname;
     rev = "v${version}";
-    sha256 = "0y4idivqkmi3xsc8yjdzh1b15qzgyqlw7ifs26v3dc91lkjhfc4x";
+    sha256 = "1pvyjdxgy7yxxz4x87f8an0dlxvxbnmv5kya8hkzw2na453ihvab";
   };
 
   buildInputs = [ Carbon Cocoa ScriptingBridge xxd ];
@@ -20,7 +20,7 @@ stdenv.mkDerivation rec {
     cp ./doc/yabai.1 $out/share/man/man1/yabai.1
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = ''
       A tiling window manager for macOS based on binary space partitioning
     '';