As Dieter Fleck identifies in his book41. It can be legally acceptable to use nuclear weapon in an attack. But some requirements must be fulfilled like manageable damage to civilian objects, it must also be of course only military targets with proportion. It is of great importance that the attacker use distinction and also use proportionality for this to even happen. so it will be very hard to use this kind of attack and the attacker must be absolute sure that they can manage this kind of attack. to clarify things, this attack is in the term of self-defence purposes.
NPT do not prohibit some states to own nuclear weapons but advocates the use of nuclear technology. This makes many different laws regarding transfer inside