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.
Strategic alliances are much more important. When the imperialists come and prod, who will have your back?
If your strategic alliances are good you will acquire nukes as needed and weather imperialist sanctions.
Any historical examples of this actually working? Especially since the break-up of the USSR? China's strategy directly precludes them ever coming to save your ass against the US for example. That strategy could change but I don't see that happening before the 2030s at the earliest.
It takes more than just being on the same side to launch into a direct war with the US over some friendship. The USSR never did it, they at most offered support, weapons, some pilots and aircraft and turned things into wars where the US directly fought their proxies but they avoided direct conflict with the US because of the risk of escalation to immediate nuclear war. In the case of Korea with China's help they eked out a stalemate and denied them a victory. In the case of Vietnam they won, but at a terrible cost, the US invaded and did atrocities and butchered and dumped toxic forever chemicals all over their country in addition to traditional munitions and mines which kill people to this day.
Nukes aren't about just winning, you can win without nukes, they're about dissuading the invaders from coming and butchering your people in the first place, from subjecting your people to years, decades of hardship, to destroying your means of production and plunging your people into misery, disease, starvation, poverty, etc.
It's all well and good to have friends who will give you some weapons and maybe lend you some pilots, doesn't save your people from starving when the Americans take out your crop production. Doesn't save them from misery and poverty and deprivation during the war and for years after because they've destroyed all your industry and infrastructure and killed and maimed so many young people.
Also nukes are not an "acquire as needed" thing as very few countries have done so successfully. It's not like China just handed the DPRK some nuclear weapons or the complete schematics, they had to build them themselves and it took many years. If the day comes when you need nukes fast because the US is saber-rattling and talking of an invasion, you won't have the time to get them. You'll either already have them and they'll do no more than rattle the saber or you won't have them and they'll bomb the shit out of you and take away your ability to get them. Once the US eye of Sauron is on your country, if you try to get nukes and they notice (they will), they have a strong incentive to bomb the shit out of you to prevent it and punish you as an example to others.
Sanctions are a separate topic in defense. Yes you need alliances to weather them, no such alliances had no real possibility of existing before the present escalation against Russia and before that increasing escalation against China with sanctions. And such alliances again do not protect against direct intervention if the US wishes to go there. Increasingly they may find themselves unable to do that with any luck but in the past it was not the case and there is no guarantee they won't be able to again in future. Nukes and alliances are shields against two separate things IMO. Both have a role to play if you want to guarantee the US can't attack you successfully.
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.