“An operating system is a collection of things that don’t fit inside a programming language; there shouldn’t be one” - Dan Ingalls 1981
That's a really terrible definition that dates from before multitasking, GUIs, and window systems and desktops.
Smalltalk and its current incarnation Squeak and SqueakNOS (for Squeak No Operating System) is a virtual machine written in a high level programming language that contains everything that we now call an operating system including its device drivers. It runs on bare metal hardware.
Alan Kay his research group [2] attempted to make an entire personal computer operating system in just 10.000 lines of high level programming language and demonstrated that it is possible to do [3].
[3] answers the question "How would you build an operating system?" from OP.
[1] https://archive.org/details/byte-magazine-1981-08
[2] https://tinlizzie.org/IA/index.php/Papers_from_Viewpoints_Re...