For a "real" port, check the Git logs to see what was done for another platform, for example the nintendo switch and learn from that.
For a bit more lightweight port you might be able to compile with --os:any and -d:useMalloc; in this case Nim will have very few dependencies on your operating system, apart from some basic ANSI C functions like malloc/free/fopen/fwrite.
is everything just selected in the sources file with "when thisOS" etc.
Yep, it's done like that. A "generic interface" wouldn't help, the interface would have to be enormous and spread out over multiple files and directories just like today's code.