Yes, and it does have flaws like any other software, but as far as viruses go, it's practically imune as the whole User Interface and System works sandboxed inside Unix.
The thing is, there's this Unix system running underneath, which is basically the kernel and some extensions to it, maybe also drivers, don't know that for sure. And on top of that there's like another system who only has reading access to the system files and can in no way be modified otherwise.
Of coure you could ******* up the system by going in the console(terminal), logging in as the root user and start messing stuff up but you would have to self interract with the system. For a program or a virus to do this it would have to create an automated task in automator which is also impossible.
I'm quite aware of OSX's UNIX based history, and something as simple as a faulty kext (kernel extension) could do quite a bit of damage. Other sandboxes do provide quite a bit of security, but perfectly immune is not something I would say with confidence.
The upside is that previous security flaws have been patched up fairly quickly and usually before anyone comes up with any meaningful exploits.