terraform-nixos
terraform-nixos copied to clipboard
NixOS upgrades may break due to lack of stateVersion
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)
- Deploy NixOS, say 19.09. This creates a system state compatible with 19.09.
- 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.
- 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.
Why isn't it the configuration.nix author's job to set stateVersion in their configuration to prevent this?
Agreed. The terraform-nixos project should probably mention that responsibility though.
Actually, NixOS should probably also fail to evaluate without the stateVersion.
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.
I started here: https://github.com/NixOS/nixpkgs/pull/149877