From c61de2d2621914e29eae86140dc0ca70b1af0959 Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Sat, 14 Dec 2024 23:38:14 +0800 Subject: [PATCH] system/state-version: init --- nixos/modules/system/state-version.nix | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 nixos/modules/system/state-version.nix diff --git a/nixos/modules/system/state-version.nix b/nixos/modules/system/state-version.nix new file mode 100644 index 0000000..b3510d2 --- /dev/null +++ b/nixos/modules/system/state-version.nix @@ -0,0 +1,48 @@ +# Portions of this file are sourced from +# https://github.com/linyinfeng/dotfiles/blob/b618b0fd16fb9c79ab7199ed51c4c0f98a392cea/nixos/modules/system/state-version.nix +{ + config, + options, + lib, + ... +}: +with lib; +let + cfg = config.system; +in +{ + options = { + system.targetStateVersion = mkOption { + inherit (options.system.stateVersion) type; + default = config.system.stateVersion; + description = '' + System is going to be upgraded to the targetStateVersion. + ''; + }; + system.pendingStateVersionUpgrade = mkOption { + type = types.bool; + default = cfg.stateVersion != cfg.targetStateVersion; + readOnly = true; + }; + }; + + config = { + specialisation = mkIf cfg.pendingStateVersionUpgrade { + target-state-version = { + configuration = { + system.stateVersion = mkForce targetStateVersion; + }; + }; + }; + + warnings = mkIf cfg.pendingStateVersionUpgrade [ + '' + + host: ${config.networking.hostName} + pending stateVersion upgrade from ${cfg.stateVersion} to ${cfg.targetStateVersion} + release notes: https://nixos.org/manual/nixos/stable/release-notes.html#sec-release-${cfg.targetStateVersion} + + '' + ]; + }; +}