anchor.diff:    '';
     unpatchScripts = dest: ''
       for script in ${scripts}; do
  -      cp $script.orig ${dest}/$script
  +      test ! -e $script.orig || cp $script.orig ${dest}/$script
       done
     '';
  -  make = ''
  -    make -j $NIX_BUILD_CORES -l $NIX_BUILD_CORES
  -  '';
  +  make = "make -j $NIX_BUILD_CORES -l $NIX_BUILD_CORES";
   
     skip_tests = [
       # known failures (TODO: fix upstream)
  
positive.code:     "unit.RDBBtree"
      # Slow tests
      "unit.DiskBackedQueue"
    '';
    skip_tests_filter =
        builtins.concatStringSep " " (map (t: "'!" + t + "'") skip_tests);
  
  in rec {
    versionFile = pkgs.stdenv.mkDerivation {
      name = "rethinkdb-version";
      src = <rethinkdb>;
      buildInputs = [ pkgs.git ];
      builder = builtins.toFile "builder.sh" ''
        source $stdenv/setup
        cd $src
        echo -n $(bash scripts/gen-version.sh) > $out
      '';
    };
  
    sourceTarball = pkgs.stdenv.mkDerivation rec {
      name = "rethinkdb-${version}.tgz";
      version = builtins.unsafeDiscardStringContext (builtins.readFile versionFile);
      builder = builtins.toFile "builder.sh" ''
        source $stdenv/setup
        # TODO: https://github.com/NixOS/nixpkgs/issues/13744
        export SSL_CERT_FILE=$cacert/etc/ssl/certs/ca-bundle.crt
        cp -r $src rethinkdb
        chmod -R u+w rethinkdb
        cd rethinkdb
        ${patchScripts}
        ./configure --fetch jemalloc
        ${make} dist-dir
        ${unpatchScripts "build/packages/rethinkdb-${version}"}
        cd build/packages
        tar zcf $out rethinkdb-${version}
      '';
      __noChroot = true;
      src = <rethinkdb>;
      buildInputs = with pkgs; [
        protobuf
        python
  
negative.code:     ];
    };
  
    fastTests = pkgs.stdenv.mkDerivation rec {
      name = "rethinkdb-fast-tests-results-${src.version}";
      src = sourcePrep;
      buildInputs = with pkgs; [
        protobuf
        python27Full
  