FAQ/When do I update stateVersion
system.stateVersion should never be updatedWhy am I told not to update[1] system.stateVersion?
Since it is not clearly codified what system.stateVersion should be used for, and it is used for a great many different things in practice[2], there is no practical way to ensure that changing it is ever safe.
The consequences of changing its value range from none at all, to complete destruction of data written by specific software.
How do I update NixOS, if changing system.stateVersion does not do that?
See Updating nixos.
Why does system.stateVersion look like a NixOS version?
This is because it notes down the version of NixOS you first installed with a given configuration. It does not mean that you should update it.
When can I update system.stateVersion safely?
Currently, you cannot update it safely without a complete understanding of all NixOS modules you are using, directly or indirectly.
Only when the NixOS release notes say that it can be changed, should it be changed.
Is it ok to leave system.stateVersion at a very old version?
The NixOS module authors are aware of their use of the setting, and must ensure that old versions continue to work. Whether and how this is sustainable is an upstream issue; Users should not update the setting unless instructed otherwise.
What even is system.stateVersion for, if it is just an unchanging string?
Currently, this is undefined[2].
As a result, modules can effectively use it for anything, which makes the effects of changing it unpredictable.
Since it is sometimes used to protect data integrity upon package updates, changing the number can lead to irreversible data loss.