Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make nixos.stateVersion mandatory #65314

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

aristidb
Copy link
Contributor

Motivation for this change

In #61321 a necessary migration was only run if the stateVersion is older than 19.09. The default value of cfg.release (= 19.09) prevented it from being run on systems without explicit stateVersion.

In this particular case, maybe using stateVersion could have been avoided, but in general, it is not safe to have a system without explicitly set stateVersion.

All systems installed in the last few years should have it set automatically, but there are surely still a lot of configs out there with it not set.

(While stateVersion as it is currently designed has other problems, like mentioned in #50112, the goal here is to just do the minimal change to get systems safe.)

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • [N/A] macOS
    • [N/A] other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding an assertion like this to provide a much better error message than the generic "Option is used but not defined"

{
  assertions = [
    {
      assertion = options.system.stateVersion.isDefined;
      message = "`system.stateVersion', which protects against future state migrations, "
        + "is not defined. Set it to its previous default value of \"${cfg.release}\".";
    }
  ];
}

@infinisil
Copy link
Member

Copy link
Member

@Ekleog Ekleog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having already seen people getting badly bitten by this, I'm all 👍 for this change!

@@ -188,6 +188,7 @@ in rec {
networking.hostName = "client";
nix.readOnlyStore = false;
virtualisation.writableStore = false;
system.stateVersion = "19.09"; # TODO: determine automatically
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this TODO ought to be resolved before merging this, as otherwise we'll forget it after 19.09 branch-off, and we'll start testing outdated versions of postgresql on the next postgresql bump (or similar thing that would involve bumping stateVersion)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Giving it a bit more thought: either that or just add bumping this to the release process checklist, maybe -- definitely need to record the existence of this TODO somewhere at least, though.

@srhb
Copy link
Contributor

srhb commented Aug 1, 2019

@infinisil Regarding the assertion: Maybe replace the last paragraph. We want to avoid a situation where a user accidentally deletes the setting, gets that assertion message, then puts it back with a release possibly several versions ahead of their system's compatibility at the suggestion of the text.

@infinisil
Copy link
Member

infinisil commented Aug 1, 2019

@srhb Yeah, but I'm not sure what would be a good replacement for it. Ideally I'd like to say

Set it to the NixOS version you initially installed, but only if you recently updated and notice problems. If you're sure that you don't need an older stateVersion by checking all things you would have to manually upgrade, you can set it to 19.09

Not sure how this can be phrased better..

@srhb
Copy link
Contributor

srhb commented Aug 1, 2019

@infinisil Punting a bit, but how about referring to the option documentation and we can try to improve on that? Better than having to cook up a great explanation in multiple places. :)

@infinisil
Copy link
Member

I took the liberty to push a better stateVersion description to this PR in 548d427, how does it sound?

@oxij
Copy link
Member

oxij commented Aug 2, 2019 via email

@infinisil
Copy link
Member

infinisil commented Aug 2, 2019

Actually, it's kind of bad UX if we now make stateVersion mandatory, but at some later point deprecate that option in favor of per-module stateVersion's as described in #50112 (comment) (but with stateVersion's declared in configuration.nix, not in /var/lib/nixos)

So it's arguably better if we first figure out the per-module stateVersion, and only after that make it mandatory. This also means a lot of users won't ever see a warning for it being unset, because they're not using any modules that need it.

But then again, figuring out per-module stateVersion will take some time, likely with an RFC, and until that point users who don't have the global stateVersion set are at risk of breakage

@oxij
Copy link
Member

oxij commented Aug 5, 2019 via email

@infinisil
Copy link
Member

That sure would be the least-invasive solution for now, but copy-pasting it around doesn't sound very nice. Maybe an internal option system.warnStateVersionUnset which modules like postgres can set to true would be better. I like this as a temporary solution

@samueldr
Copy link
Member

samueldr commented Aug 5, 2019

To be more end-user friendly, the internal setting could be a list, system.modulesRequiringState, and modules requiring state append to it. This would allow printing "The modules xxx, yyy and zzz require stateVersion to be set`. An empty list would mean nothing requires a stateful version to be set...


Though, this is all well, but with this coming update, most, if not all, systems will require stateVersion to be set because of how it ends up being used for systemd-timesyncd. (#64922) So, in a way, it's now de facto required. Unless a solution is figured out before the 19.09 fork/release, to handle the issue in another way.

@infinisil
Copy link
Member

I see. So it might be best to just go ahead with the original idea of this PR and make stateVersion mandatory. With a good assertion error this shouldn't be a big problem.

@oxij
Copy link
Member

oxij commented Aug 5, 2019 via email

@danbst
Copy link
Contributor

danbst commented Aug 7, 2019

I'm contra to adding mandatory options. I'm also against of having asserts about filesystems."/" and boot.loader. We should remove those out for

$ nix build -f ./nixos system --arg configuration '{ services.postgresql.enable = true; }' 

to just build.

It should be nixos-install or nixos-rebuild who should check whether stateVersion is configured correctly.

@infinisil
Copy link
Member

@oxij Always requiring stateVersion has the benefit that a module that initially didn't need it and was enabled by the user will continue evaluating successfully even if it eventually does need it. If this was done with the module list thing, people could suddenly have to set stateVersion when they update their NixOS.

I feel like this is a band-aid like situation, we should just rip it off in one swoop by making stateVersion mandatory, which it should've been from the beginning. Once everybody has it set, we won't have to worry it again, no maintenance cost either.

@danbst That would be neat yeah, but I think that's something for the future. For most users whether the stateVersion check is done in the module or in nixos-rebuild doesn't make a difference, so there's no big cost to going with the former for now.

@oxij
Copy link
Member

oxij commented Aug 10, 2019 via email

@infinisil
Copy link
Member

On second thought, yeah actually that doesn't sound half bad @oxij, having a warning copy-pasted to every module that uses stateVersion until the per-module version is implemented. It's the only solution that doesn't need new infrastructure (which would eventually have to be removed again).

@dasJ
Copy link
Member

dasJ commented Sep 1, 2019

To make the switch less painful, I think we should handle this like a deprecation (basically deprecating omittance of stateVersion).
So IMO, another PR (for 19.09) which emits a warning would be more appropriate. This PR could go into 20.03, then.

@stale
Copy link

stale bot commented Jun 1, 2020

Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the
    related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on
    irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 1, 2020
@dasJ
Copy link
Member

dasJ commented Jun 1, 2020

still important to me

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 1, 2020
@stale
Copy link

stale bot commented Jun 5, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 5, 2021
@infinisil infinisil added the significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc. label Apr 19, 2023
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 19, 2023
@lucasew
Copy link
Contributor

lucasew commented Aug 7, 2023

Is this still relevant?

@oxij
Copy link
Member

oxij commented Aug 9, 2023

Yes, as an issue, it is still relevant.

@Enzime
Copy link
Member

Enzime commented Oct 22, 2023

Duplicate of #149877

@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 19, 2024
@wegank wegank marked this pull request as draft March 20, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: nixos 8.has: module (update) significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet