When should I change system.stateVersion?

When i omit, I get:

evaluation warning: system.stateVersion is not set, defaulting to 24.11.

@boxofrox is right, the warnings do not make sense when i read this discussion.

It’s something you shouldn’t need to touch, then it should not give a warning when omitting the value, because then i rather want NixOS to deal with this state version stuff.

But NixOS doesn’t deal with it. It needs to know what version the stateful files on your system is so it can make the right build-time decisions. It doesn’t have a way to know the answer of that unless you specifically tell it.

Then the version should be defined somewhere on the stateful files itself, how can you call the files stateful when it relies on user input via stateVersion, the system doesn’t know which version was used to produce the state? That’s stateless.

That’s the point, right? One of the tenets of nix is that you should be able to put your config in a repo and build the system’s toplevel derivation on any other machine. For that code to account for system state’s expected format / contents, it has to be recorded in the code. That’s exactly what stateVersion is.

No, the files do not rely on stateVersion. The file were produced by whatever apps you ran. stateVersion’s job is to tell the system what versions of the corresponding tooling can work with that state without either breaking the state completely or failing to operate.

There are better ways of doing this, this is just the current way that is used in NixOS.

2026 I’m updating this again and I’m “fine” with that, it’s obviously bad but I’m fine with that…

What I find not so fine is the “just search through the massive changelog with a bunch of other irrelevant info in it”. Where you can’t easily start where you are and just go over what matters one by one…
If you have a design like this the absolute minimum that should be done is have a dedicated page for it with these changes listed, preferably with examples/hints for how to migrate, but that’s a luxury I can live without.

Just an auto-generated page-set dedicated to it, with each version on a separate page so people can open the relevant tabs, go through them one by one, closing the tab when it’s done (that way it’s harder to get lost, especially if anything requires a reboot in between) would be enough…

You don’t need to upgrade the stateVersion. If you still want to find out what the changelogs have to say about stateVersion you can find that out very easily with ctrl+f “stateVersion”.

This time I didn’t strictly need to, just decided to do it to avoid having 15 warning messages on rebuild or a config option that sets the default value, to keep things minimal.
But a couple years ago on some server I did have to, don’t remember exactly why (iirc doing something with containers required newer stateVersion, but postgres got moved in the meantime).

Either way, doing “ctrl+f” on a massive page where you can’t tell where you are and can’t easily start where you need to is equivalent to saying “go blah yourself”…

I’m not asking for anything more than another page (or better a page-set) that basically just filters out any entries that don’t contain stateVersion… it’s literally just a copy&paste of whatever generates the changelog page and filtering out entries that don’t have it… unless the page is made by hand?

The changelogs are handwritten by the nixpkgs contributors. nixpkgs/nixos/doc/manual/release-notes at master · NixOS/nixpkgs · GitHub

Also, stateVersion is not intended to be changed, as the big fat warning in your generated configuration.nix says. Why would the release notes be optimized for something you’re not supposed to do in the first place?

It seems like there will be module-specific stateVersions going forward, so you would probably know what the scope is more easily.

The configuration and state directories used by nixos-containers have been moved from /etc/containers and /var/lib/containers to /etc/nixos-containers and /var/lib/nixos-containers.

If you are changing system.stateVersion to "22.05" manually on an existing system you are responsible for migrating these directories yourself.

This is to improve compatibility with libcontainer based software such as Podman and Skopeo which assumes they have ownership over /etc/containers

This is the original reason why I did it back then. I don’t fully grasp what that “compatibility” entailed but at the time I deemed it wiser to update stateVersion, and it was fine, except for the hassle of having to dig through the changelog.

In general assumptions and mistakes are the main reason to keep things up to date, it’s not necessarily easy to keep track of circumstantial differences from 10 years ago and if someone makes a stateVersion related mistake I find it likely end-users like me would be the ones to “catch it”, unless the automated testing checks if things actually function for every possible stateVersion?

Either way I don’t want to drag this out, just needed to point out that this is basically a hack around having actual state versioning on the system and a method of properly migrating/updating it.
With the major con being that it requires long-term maintenance in the nix code without providing a good method of deprecation and cleanup.

And I must again stress that “it’s fine”, nothing is perfect, but closing your eyes and pretending “it’s not really there don’t touch it” isn’t a wise answer.
I’d be much more fine with an answer like “yeah we know, but no one has the time to do anything about it”.

I don’t believe there is a general way to do this.

Imagine that stateVersion gates a new database schema where the difference is whether a new piece of metadata is included as a column in a database.

On rollbacks which cross system.stateVersion, can the software under the old stateVersion gracefully ignore the new metadata? If not, should you drop this new metadata? Does it need to be backed up somewhere? On roll-forward, do you try to restore that column? What if additional state was generated under the older stateVersion?

Changing system.stateVersion is dangerous because state is hard to manage, and expecting state to be easily migrated without loss of data or integrity is just not realistic in many scenarios. If you change stateVersion, you are effectively committing to either not rolling back to previous configurations, or only launching those old configurations on a new VM/server/computer to generate fresh state.

If you don’t install anything that actually refers to stateVersion, then I suppose you could update stateVersion so that you get the latest state type if/when you actually do install something that uses it; after which you should probably never touch it again until you are truly ready to never rollback.

Yeah you’re right, to do it properly you’d need both stateVersion on the system and in the config. On the system it defines what the state of the system is, and in the config it defines with what assumptions the config is written.

Then you could block booting incompatible cases, and maybe even automatically handle some differences.

E.g. as far as I can see, most of the cases are just trivial default changes, e.g. nextcloud versions.
These are arguably only really relevant for the “config assumptions” case, and completely irrelevant for the actual system state.

Alternatively separate such versioning, because it’s fundamentally different concerns.
Which as waffle8946 mentioned is likely to be the future.
I’m fine with that future, but “again” I think it really needs to be documented such that it’s easy to verify and address if ever needed, instead of being mixed in between a lot of other information.

It of course would be best if no one ever needed to update it, and so far (~8 years) I felt inclined enough to suffer through it only about 3 times.
But I doubt anyone can guarantee there won’t ever be a need to do it, so I’d generally prefer to stay ahead in small steps than to suddenly rush 10 version bumps all at once because of some refactor/change I need.

I share this opinion. Hell, lots of uses of stateVersion are arguably incorrect. Testing is very rare, only one test currently does anything with it and I’m like 90% sure that’s a mistake. stateVersion as designed sucks.

Sadly, that does not change the design. By changing it, you’re exposing yourself to the very complexity it tries to hide, which is fine, that’s your choice.

But then you throw your hands up and say you don’t want to deal with the complexity after all? You can’t both expect the distro to deal with the complexity for you and also circumvent it to deal with it yourself.

Even more so because you seem to refuse to read the release notes, which tell you how to deal with changes that are not hidden behind stateVersion. You have to give people a chance to help you if you want help!


Anyway, I guess ultimately your opinion just boils down to the fact that stateVersion is generally a poor way to deal with managing state, and that you would like to see this changed. That’s fair enough. You have many allies, hopefully we can come up with a better solution.

This recent thread talks about it, and an interim solution (that @waffle8946 mentions) that will in fact make dealing with it yourself more achievable was proposed and seems likely to be merged. Probably in use by 27.05 or so, given release timelines.

Various people over two threads have also already come up with many scenarios and edge cases for full deprecation. The final solution will probably have multiple different replacements for different types of state, likely encoded in policy rather than nix code.

You really misunderstood, my main “ask” (as stated in my first post) is to have a separate page (or better pages per version) with only change-log entries relevant to stateVersion, that is all.

As it is documented currently it’s very inconvenient to gather what the relevant changes are and how to address them.

Every other point is either a response, or a digression on my part (for which I’m sorry).