Libya got destroyed by American forces because it did not have any real deterrent to invasion and Assad literally allowed NATO in to show he had no weapons of mass destruction only to then be toppled anyway.
Seems that playing ball with the Americans does not work as Iran has learned the hard way with Trump breaking their nuclear treaty. It's because America - just like China and other super powers - do not believe that international law applies to them. Might makes right in their eyes, regardless of the pompous self aggrandising crap about freedom and democracy.
India had nukes before Pakistan, and built them because of China, not Pakistan. The order of development was:
US built them because of WW II, to beat Germany to them, and aid the War effort.
USSR, because US had them.
China, because USSR.
India, because China.
Pakistan, because India.