anchor.diff:        substituteInPlace crypto/async/arch/async_posix.h \
           --replace '!defined(__ANDROID__) && !defined(__OpenBSD__)' \
                     '!defined(__ANDROID__) && !defined(__OpenBSD__) && 0'
  +    ''
  +    # Move ENGINESDIR into OPENSSLDIR for static builds, in order to move
  +    # it to the separate etc output.
  +    + lib.optionalString static ''
  +      substituteInPlace Configurations/unix-Makefile.tmpl \
  +        --replace 'ENGINESDIR=$(libdir)/engines-{- $sover_dirname -}' \
  +                  'ENGINESDIR=$(OPENSSLDIR)/engines-{- $sover_dirname -}'
       '';
   
  -    outputs = [ "bin" "dev" "out" "man" ] ++ lib.optional withDocs "doc";
  +    outputs = [ "bin" "dev" "out" "man" ]
  +      ++ lib.optional withDocs "doc"
  +      # Separate output for the runtime dependencies of the static build.
  +      # Specifically, move OPENSSLDIR into this output, as its path will be
  +      # compiled into 'libcrypto.a'. This makes it a runtime dependency of
  +      # any package that statically links openssl, so we want to keep that
  +      # output minimal.
  +      ++ lib.optional static "etc";
       setOutputFlags = false;
       separateDebugInfo =
         !stdenv.hostPlatform.isDarwin &&
  
positive.code:       mv $out/include $dev/
  
        # remove dependency on Perl at runtime
        rm -r $out/etc/ssl/misc
  
        rmdir $out/etc/ssl/{certs,private}
      '';
  
      postFixup = lib.optionalString (!stdenv.hostPlatform.isWindows) ''
        # Check to make sure the main output doesn't depend on perl
        if grep -r '${buildPackages.perl}' $out; then
          echo "Found an erroneous dependency on perl ^^^" >&2
          exit 1
        fi
  
negative.code:     configureFlags = [
        "shared" # "shared" builds both shared and static libraries
        "--libdir=lib"
        (if !static then
           "--openssldir=etc/ssl"
         else
           # Move OPENSSLDIR to the 'etc' output for static builds. Prepend '/.'
           # to the path to make it appear absolute before variable expansion,
           # else the 'prefix' would be prepended to it.
           "--openssldir=/.$(etc)/etc/ssl"
        )
      ] ++ lib.optionals withCryptodev [
        "-DHAVE_CRYPTODEV"
        "-DUSE_CRYPTODEV_DIGESTS"
  