I think you might be surprised to learn how much of this came from open source code:
> xnulinux builds XNU, the open-source kernel of macOS, from Apple's published sources
EDIT: XNU sources, for those who are unaware that the XNU kernel is open source: https://github.com/apple-oss-distributions/xnu