Skip to content

Commit

Permalink
version: make system.stateVersion mandatory
Browse files Browse the repository at this point in the history
When testing the Sequoia UID change, I discovered that @mjm
didn’t have `system.stateVersion` set; I suspect this is not too
uncommon. Let’s make it required now, like NixOS is trying to,
to improve our backwards‐compatibility story in anticipation of
starting to cut release branches.
  • Loading branch information
emilazy committed Sep 12, 2024
1 parent f4f18f3 commit 8ca178a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
34 changes: 26 additions & 8 deletions modules/system/version.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ with lib;
let
cfg = config.system;

defaultStateVersion = options.system.stateVersion.default;

# Based on `lib.trivial.revisionWithDefault` from nixpkgs.
gitRevision = path:
if pathIsGitRepo "${path}/.git"
Expand Down Expand Up @@ -34,8 +32,9 @@ in
{
options = {
system.stateVersion = mkOption {
type = types.int;
default = 5;
type = types.ints.between 1 config.system.maxStateVersion;
# TODO: Remove this default and the assertion below.
default = config.system.maxStateVersion;
description = ''
Every once in a while, a new NixOS release may change
configuration defaults in a way incompatible with stateful
Expand All @@ -49,6 +48,12 @@ in
'';
};

system.maxStateVersion = mkOption {
internal = true;
type = types.int;
default = 5;
};

system.darwinLabel = mkOption {
type = types.str;
description = "Label to be used in the names of generated outputs.";
Expand Down Expand Up @@ -121,9 +126,22 @@ in
# documentation is not reprocessed on every commit
system.darwinLabel = mkDefault "${cfg.nixpkgsVersion}+${cfg.darwinVersion}";

assertions = [ {
assertion = cfg.stateVersion <= defaultStateVersion;
message = "system.stateVersion = ${toString cfg.stateVersion}; is not a valid value";
} ];
assertions = [
{
assertion = options.system.stateVersion.highestPrio != (lib.mkOptionDefault { }).priority;
message = ''
The `system.stateVersion` option is not defined in your
nix-darwin configuration. The value is used to conditionalize
backwards‐incompatible changes in default settings. You should
usually set this once when installing nix-darwin on a new system
and then never change it (at least without reading all the relevant
entries in the changelog using `darwin-rebuild changelog`).
You can use the current value for new installations as follows:
system.stateVersion = ${toString config.system.maxStateVersion};
'';
}
];
};
}
2 changes: 2 additions & 0 deletions release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ let
};

config = {
system.stateVersion = lib.mkDefault config.system.maxStateVersion;

system.build.run-test = pkgs.runCommand "darwin-test-${testName}"
{ allowSubstitutes = false; preferLocalBuild = true; }
''
Expand Down

0 comments on commit 8ca178a

Please sign in to comment.