The drones and missiles helped them to not lose the war, but they were significantly damaged by the initial strikes. A nuclear capability might have been sufficient deterrent to prevent those.
It also might not. Nuclear powers have lost a lot of "smaller wars" since 1945. Given that most wars are of the smaller variety, and that the threshold of nuke use is very high, it makes sense to think of the economy of the entire arsenal. Especially if your national economy is on the weaker side.
Too many people looked at Gaddafi's fall and Kim's endurance and made a short generalization "it pays to have nukes". But there is nuance in that contrast - if Libya was a friend of China and directly bordered it, no one would dare attack it the way it was attacked, nukes or not.
Iran's largest leverage is in controlling Hormuz and threatening Dubai, Qatar etc. with destruction of their oil and water infrastructure. All of this can be done cheaply with conventional weapons. If they ever use nukes, though, they can expect to be nuked in response.
There is no amount of nuclear capability that can stop a party you are major threat to from attacking you. See Hamas attacking Israel. Of course Iran will still enrich uranium because they are an excellent negotition leverage.