Acquiring nukes seems like the best way for any country to protect themselves against outside interference.
We know that as soon as Gaddafi decommissioned his nukes, Libya was targeted and invaded. If Iraq actually did have nukes, the USA wouldn’t have been so brazen to invade.
China, Russia, and North Korea’s acquisitions of nukes are also some of the main reasons why they are not easy targets for direct US invasion.
If Iran had nukes, it would drastically limit Israel’s ability to indiscriminately attack Iranian assets.
Western policies against nuclear proliferation always seem to target the countries that need them the most to ensure national sovereignty, and never refer to their own nukes.
For example, they always fearmonger about “rogue states” like North Korea getting nukes, while being perfectly okay with Israel’s own nukes. It might be best if these policies are ignored entirely.
DPRK is actually a pretty good example because without the alliances and trading partnerships they provide it would have been stuck in the post-Soviet shock much longer and have basically no chance of developing a nuke. The DPRK exists only because China and Russia trade with it and implicitly provide associated military protection. It would most likely have been fully destabilized and color revolution’d in the 90s/early 2000s otherwise. The line on Korean unification shifted once the DPRK was in the back foot. SK and their imperialist masters have been pushing pro-reunification propaganda hard since the 90s. It’s comically absurd propaganda that is paired with painting NK as a militaristic threat at the same time. The propaganda is built on the premise that reunification would favor SK and amount to the end of the DPRK entirely, seeing the SK regime take over the whole peninsula.
The opposite situation is also true - you can have nukes and the US will contol you. Pakistan has nukes but is forced into compliance with US interests on a regular basis. This is because the primary weapon of imperialists is not their militaries (though they do use them) but their financial interventions and intelligence ops and funding of NGOs and lawfare etc etc. Constant pressure from all angles. The US just soft coup’d Pakistan’s leadership and were not deterred by the nukes. The fall of anti-imperialist, or even just slightly less imperialist states requires a pre-existing instability, otherwise there would be no coup government, it would be deposed by the military and the people. It is necessary, but insufficient, to create an economic base through alliances and trade in order to build a stable ruling order.
Of course you’re making a fine point that nukes deter an invasion and are complementary to other anti-imperialist actions. I just think the nukes are a lesser tool than strong ties. The latter is usually a prerequisite for the former, even. The ties ensure trade and more stability, the stability needed to organize and pay a military. The US has often thought so as well, a lot (most?) of its fucking around can be interpreted as a divide and conquer strategy.