system/state-version: init

This commit is contained in:
Lu Wang 2024-12-14 23:38:14 +08:00
parent 44cf0004f4
commit c61de2d262
Signed by: rebmit
SSH key fingerprint: SHA256:3px8QV1zEerIrEWHaqtH5rR9kjetyRST5EipOPrd+bU

View file

@ -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}
''
];
};
}