anchor.diff:        (with pkgs; [ xz.bin xz.out libcxx libcxxabi ]) ++
         (with pkgs.darwin; [ dyld Libsystem CF ICU locale ]);
   
  -    overrides = persistent1 prevStage;
  -  };
  -
  -  persistent2 = prevStage: self: super: with prevStage; {
  -    inherit
  -      patchutils m4 scons flex perl bison unifdef unzip openssl python
  -      gettext sharutils libarchive pkg-config groff bash subversion
  -      openssh sqlite sed serf openldap db cyrus-sasl expat apr-util
  -      findfreetype libssh curl cmake autoconf automake libtool cpio
  -      libcxx libcxxabi;
  -
  -    darwin = super.darwin // {
  -      inherit (darwin)
  -        dyld Libsystem xnu configd libdispatch libclosure launchd libiconv locale;
  -    };
  -  };
  -
  -  stage3 = prevStage: with prevStage; stageFun 3 prevStage {
  +    overrides = persistent;
  +  };
  +
  +  stage3 = prevStage: let
  +    persistent = self: super: with prevStage; {
  +      inherit
  +        patchutils m4 scons flex perl bison unifdef unzip openssl python
  +        gettext sharutils libarchive pkg-config groff bash subversion
  +        openssh sqlite sed serf openldap db cyrus-sasl expat apr-util
  +        findfreetype libssh curl cmake autoconf automake libtool cpio
  +        libcxx libcxxabi;
  +
  +      darwin = super.darwin // {
  +        inherit (darwin)
  +          dyld Libsystem xnu configd libdispatch libclosure launchd libiconv locale;
  +      };
  +    };
  +  in with prevStage; stageFun 3 prevStage {
       shell = "${pkgs.bash}/bin/bash";
   
       # We have a valid shell here (this one has no bootstrap-tools runtime deps) so stageFun
  
positive.code:     extraBuildInputs = [];
    };
  
    persistent0 = _: _: _: {};
  
    stage1 = prevStage: with prevStage; stageFun 1 prevStage {
      extraPreHook = "export NIX_CFLAGS_COMPILE+=\" -F${bootstrapTools}/Library/Frameworks\"";
      extraBuildInputs = [ pkgs.libcxx ];
  
      allowedRequisites =
        [ bootstrapTools ] ++ (with pkgs; [ libcxx libcxxabi ]) ++ [ pkgs.darwin.Libsystem ];
  
      overrides = persistent0 prevStage;
    };
  
    persistent1 = prevStage: self: super: with prevStage; {
      inherit
        zlib patchutils m4 scons flex perl bison unifdef unzip openssl python
        libxml2 gettext sharutils gmp libarchive ncurses pkg-config libedit groff
        openssh sqlite sed serf openldap db cyrus-sasl expat apr-util subversion xz
        findfreetype libssh curl cmake autoconf automake libtool ed cpio coreutils;
  
      darwin = super.darwin // {
        inherit (darwin)
          dyld Libsystem xnu configd ICU libdispatch libclosure launchd;
      };
    };
  
    stage2 = prevStage: with prevStage; stageFun 2 prevStage {
      extraPreHook = ''
        export PATH_LOCALE=${pkgs.darwin.locale}/share/locale
      '';
  
negative.code:       (with pkgs; [ xz.bin xz.out bash libcxx libcxxabi ]) ++
        (with pkgs.darwin; [ dyld ICU Libsystem locale ]);
  
      overrides = persistent;
    };
  
    stage4 = prevStage: let
      persistent = self: super: with prevStage; {
        inherit
          gnumake gzip gnused bzip2 gawk ed xz patch bash
          libcxxabi libcxx ncurses libffi zlib gmp pcre gnugrep
          coreutils findutils diffutils patchutils;
  
         llvmPackages = let llvmOverride = llvmPackages.llvm.override { inherit libcxxabi; };
         in super.llvmPackages // {
           llvm = llvmOverride;
           clang-unwrapped = llvmPackages.clang-unwrapped.override { llvm = llvmOverride; };
         };
  
        darwin = super.darwin // {
          inherit (darwin) dyld Libsystem libiconv locale;
        };
      };
    in with prevStage; stageFun 4 prevStage {
      shell = "${pkgs.bash}/bin/bash";
      extraBuildInputs = with pkgs; [ xz darwin.CF libcxx pkgs.bash ];
      extraPreHook = ''
        export PATH_LOCALE=${pkgs.darwin.locale}/share/locale
      '';
      overrides = persistent;
    };
  
    stdenvDarwin = prevStage: let
      pkgs = prevStage;
      persistent = self: super: with prevStage; {
        inherit
          gnumake gzip gnused bzip2 gawk ed xz patch bash
          libcxxabi libcxx ncurses libffi zlib llvm gmp pcre gnugrep
          coreutils findutils diffutils patchutils;
  
        llvmPackages = super.llvmPackages // {
          inherit (llvmPackages) llvm clang-unwrapped;
        };
  
        darwin = super.darwin // {
          inherit (darwin) dyld ICU Libsystem cctools libiconv;
        };
      } // lib.optionalAttrs (super.targetPlatform == localSystem) {
        # Need to get rid of these when cross-compiling.
        inherit binutils binutils-raw;
      };
    in import ../generic rec {
      inherit config;
      inherit (pkgs.stdenv) fetchurlBoot;
  
  