Skip to content

Commit 37d0868

Browse files
committed
nixos/version: validate system.stateVersion
1 parent 16c2255 commit 37d0868

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

nixos/doc/manual/release-notes/rl-2505.section.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@
437437
- Overriding Wayland compositor is possible using `enableWaylandSession` option, but you might need to take care [`xfce4-session`](https://gitlab.xfce.org/xfce/xfce4-session/-/merge_requests/49), [`dbus-update-activation-environment`](https://github.com/labwc/labwc/blob/eaf11face68ee1f1bcc7ce1498304ca8c108c8ba/src/config/session.c#L234) and [`systemctl --user import-environment`](https://github.com/labwc/labwc/blob/eaf11face68ee1f1bcc7ce1498304ca8c108c8ba/src/config/session.c#L239) on startup.
438438
- For new Xfce installations, default panel layout has [changed](https://gitlab.xfce.org/xfce/xfce4-panel/-/merge_requests/158/diffs) to not include external panel plugins by default. You can still add them yourself using the "Panel Preferences" dialog.
439439

440+
- [`system.stateVersion`](#opt-system.stateVersion) is now validated and must be in the `"YY.MM"` format, ideally corresponding to a prior NixOS release.
441+
440442
- GOverlay has been updated to 1.2, please check the [upstream changelog](https://github.com/benjamimgois/goverlay/releases) for more details.
441443

442444
- [`services.mongodb`](#opt-services.mongodb.enable) is now compatible with the `mongodb-ce` binary package. To make use of it, set [`services.mongodb.package`](#opt-services.mongodb.package) to `pkgs.mongodb-ce`.

nixos/modules/misc/version.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ let
1616
toLower
1717
optionalString
1818
literalExpression
19+
match
1920
mkRenamedOptionModule
2021
mkDefault
2122
mkOption
@@ -263,6 +264,27 @@ in
263264

264265
config = {
265266

267+
assertions = [
268+
{
269+
assertion = match "[0-9]{2}\\.[0-9]{2}" config.system.stateVersion != null;
270+
message = ''
271+
${config.system.stateVersion} is an invalid value for 'system.stateVersion'; it must be in the format "YY.MM",
272+
which corresponds to a prior release of NixOS.
273+
274+
If you want to switch releases or switch to unstable, you should change your channel and/or flake input URLs only.
275+
*DO NOT* touch the 'system.stateVersion' option, as it will not help you upgrade.
276+
Leave it exactly on the previous value, which is likely the value you had for it when you installed your system.
277+
278+
If you're unsure which value to set it to, use "${
279+
if match "[0-9]{2}\\.[0-9]{2}" options.system.stateVersion.default != null then
280+
options.system.stateVersion.default
281+
else
282+
options.system.nixos.release.default
283+
}" as a default.
284+
'';
285+
}
286+
];
287+
266288
system.nixos = {
267289
# These defaults are set here rather than up there so that
268290
# changing them would not rebuild the manual

0 commit comments

Comments
 (0)