Treaties aren't set in stone, and novel ones can be invented. If I had to crystal-ball predict what a plausible Ukrainian victory looks like here—that is, the best likely outcome I think they might achieve on a relatively short timetable—it's a negotiated peace that gives some territorial concessions
and, for face-saving for Putin/Russia, rejects Ukrainian NATO ambitions... but puts them in a quick-n-dirty EU status that grants them a security agreement of some kind, as they progress on the slower track to full EU membership.
I think if Russia backs them into fully rejecting all security agreements with the West as part of a settlement, they're just in for a takeover by other means, once Russia has its near-term concerns addressed by the peace settlement and can afford to sit back and wait. I think the most likely way out of that (assuming Ukraine achieves one) is a novel arrangement of some kind, more likely with with the EU than NATO, or (waaaay less likely) a new bloc & mutual defense agreement with Sweden and Finland.