Also this use would likely not be against the invading forces themselves because you'd be contaminating your own land so the use of nukes as protection against conquest requires not only the willingness to use them first but to use them on your enemy's homeland, likely military industrial targets which will also hit civilians.
That's immaterial, because your potential adversary isn't going to want to find out what your nuclear rules of engagement really are. Possessing nuclear weapons raises the threshold for putting the invasion on the table quite dramatically. And if there is a war, nuclear weapons limit its scope quite quickly.
Just think of how many Indian and Pakistani lives have been saved because the two countries stepped back when shit was about to get real. Like, three times now. All because of nukes. Unless one of them truly commits to invading and losing millions of lives, their wars are guaranteed to peter out as border skirmishes.