terraform-nixos icon indicating copy to clipboard operation
terraform-nixos copied to clipboard

NixOS upgrades may break due to lack of stateVersion

Open roberth opened this issue 5 years ago • 5 comments

Describe the bug

Installations of NixOS should set the stateVersion option, such that NixOS can take legacy filesystem state locations and such into account.

To Reproduce

(hypothetical but bound to happen)

  1. Deploy NixOS, say 19.09. This creates a system state compatible with 19.09.
  2. Deploy NixOS, say 20.03. This now expects a system state that is like a fresh 20.03 install. It does not apply its compatibility measures, because it doesn't know that the system is still in a 19.09-like state.
  3. A database is down because the files are in the 19.09 location rather than the fresh 20.03 location and another service is misconfigured because the default values for its options have changed

Expected behavior terraform-nixos saves the stateVersion on first deployment and sets it until the machine is destroyed.

Environment

  • OS name + version: n/a
  • Version of the code: master as of reporting

Additional context

From the docs

Every once in a while, a new NixOS release may change configuration defaults in a way incompatible with stateful data. For instance, if the default version of PostgreSQL changes, the new version will probably be unable to read your existing databases. To prevent such breakage, you should set the value of this option to the NixOS release with which you want to be compatible. The effect is that NixOS will use defaults corresponding to the specified release (such as using an older version of PostgreSQL). It‘s perfectly fine and recommended to leave this value at the release version of the first install of this system. Changing this option will not upgrade your system. In fact it is meant to stay constant exactly when you upgrade your system. You should only bump this option, if you are sure that you can or have migrated all state on your system which is affected by this option.

roberth avatar Jul 18 '20 09:07 roberth

Why isn't it the configuration.nix author's job to set stateVersion in their configuration to prevent this?

exarkun avatar Dec 09 '21 15:12 exarkun

Agreed. The terraform-nixos project should probably mention that responsibility though.

zimbatm avatar Dec 09 '21 16:12 zimbatm

Actually, NixOS should probably also fail to evaluate without the stateVersion.

zimbatm avatar Dec 09 '21 16:12 zimbatm

Actually, NixOS should probably also fail to evaluate without the stateVersion.

Sounds good to me (maybe only if it tries to use it). Certainly also not terraform-nixos's responsibility.

exarkun avatar Dec 09 '21 16:12 exarkun

I started here: https://github.com/NixOS/nixpkgs/pull/149877

zimbatm avatar Dec 11 '21 22:12 zimbatm