Joel addressed the build vs. buy argument here (20 years ago).
If it’s a core business function — do it yourself, no matter what.
https://www.joelonsoftware.com/2001/10/14/in-defense-of-not-...
I guess what's not obvious to many people is that maintaining and optimizing the kernel and JVM is a core business function for Twitter (but probably not writing a kernel!). Likewise CPU design is now a core business function for Apple. Anything "down" your dependency stack can be.
On the other hand, software for employees to file expense reports likely isn't, etc.