Sanctions, preemptive strike from nuclear states, etc. Yes, cost outweigh the benefits but depends on geopolitics.
China supported and transfer nuclear technology to Pakistan and North Korea. Also secretly trying to build nuke programs for Iran, Syria, Egypt, Libya, and Yemen as well. US was fully aware of it but turn a blind eye.
France, Britian and US supported Israel nuke program because they hate terrorist Islamic radicals. However US & NATO allies was against Iran of acquiring nukes and sanction the country. Israel even tried to transfer nuclear weapons to South Africa.
Nuclear Non-Proliferation Treaty is outdated, more countries are going to uses civilian nuclear energy as a stepping stone to nuclear proferliation.
It's false pretense to say nuclear weapons are for peaceful reason or national security because its going to be used in war and it will kill innocent people. I"m not trying to advocate using nuclear weapons in war. I'm a firm believer of using nukes as a last option.