When Apple purchased the company [NeXT](https://en.wikipedia.org/wiki/NeXT) in 1997, they got not only CEO Steve Jobs from the deal, but also the smaller company's technologies.  This included [NeXTSTEP](https://en.wikipedia.org/wiki/NeXTSTEP), the Unix-based operating system for NeXT machines.

Under Jobs' leadership, Apple then modified NeXTSTEP to work on Macintosh hardware.  The result was MacOS X.  Some Apple technologies were retained (e.g. QuickTime), whereas many others (many of which were seldom used anyway) were discarded.  In addition, Apple tried to keep backwards compatibility with the Classic run-time environment and the Carbon source-code API.

Darwin is the kernel and low-level layers of MacOS X.  It is open source, but the rest of MacOS X is not.