summaryrefslogtreecommitdiff
path: root/modules/system/version.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/system/version.nix')
-rw-r--r--modules/system/version.nix68
1 files changed, 47 insertions, 21 deletions
diff --git a/modules/system/version.nix b/modules/system/version.nix
index 3effb50..54829d1 100644
--- a/modules/system/version.nix
+++ b/modules/system/version.nix
@@ -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"
@@ -34,9 +32,10 @@ in
{
options = {
system.stateVersion = mkOption {
- type = types.int;
- default = 4;
- description = lib.mdDoc ''
+ 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
data. For instance, if the default version of PostgreSQL
@@ -49,16 +48,29 @@ in
'';
};
+ system.maxStateVersion = mkOption {
+ internal = true;
+ type = types.int;
+ default = 5;
+ };
+
system.darwinLabel = mkOption {
type = types.str;
- description = lib.mdDoc "Label to be used in the names of generated outputs.";
+ description = "Label to be used in the names of generated outputs.";
+ };
+
+ system.darwinRelease = mkOption {
+ readOnly = true;
+ type = types.str;
+ default = (lib.importJSON ../../version.json).release;
+ description = "The nix-darwin release (e.g. `24.11`).";
};
system.darwinVersion = mkOption {
internal = true;
type = types.str;
- default = "darwin${toString cfg.stateVersion}${cfg.darwinVersionSuffix}";
- description = lib.mdDoc "The full darwin version (e.g. `darwin4.2abdb5a`).";
+ default = cfg.darwinRelease + cfg.darwinVersionSuffix;
+ description = "The full nix-darwin version (e.g. `24.11.2abdb5a`).";
};
system.darwinVersionSuffix = mkOption {
@@ -67,28 +79,29 @@ in
default = if cfg.darwinRevision != null
then ".${substring 0 7 cfg.darwinRevision}"
else "";
- description = lib.mdDoc "The short darwin version suffix (e.g. `.2abdb5a`).";
+ description = "The short nix-darwin version suffix (e.g. `.2abdb5a`).";
};
system.darwinRevision = mkOption {
internal = true;
type = types.nullOr types.str;
default = gitRevision (toString ../..);
- description = lib.mdDoc "The darwin git revision from which this configuration was built.";
+ description = "The darwin git revision from which this configuration was built.";
};
system.nixpkgsRelease = mkOption {
readOnly = true;
type = types.str;
default = lib.trivial.release;
- description = lib.mdDoc "The nixpkgs release (e.g. `16.03`).";
+ description = "The nixpkgs release (e.g. `24.11`).";
};
+ # TODO: Shouldn’t mismatch the Darwin release, rethink all this…
system.nixpkgsVersion = mkOption {
internal = true;
type = types.str;
default = cfg.nixpkgsRelease + cfg.nixpkgsVersionSuffix;
- description = lib.mdDoc "The full nixpkgs version (e.g. `16.03.1160.f2d4ee1`).";
+ description = "The full nixpkgs version (e.g. `24.11.1160.f2d4ee1`).";
};
system.nixpkgsVersionSuffix = mkOption {
@@ -97,7 +110,7 @@ in
default = if useSourceRevision
then ".${lib.substring 0 8 (nixpkgsSrc.lastModifiedDate or nixpkgsSrc.lastModified or "19700101")}.${nixpkgsSrc.shortRev or "dirty"}"
else lib.trivial.versionSuffix;
- description = lib.mdDoc "The short nixpkgs version suffix (e.g. `.1160.f2d4ee1`).";
+ description = "The short nixpkgs version suffix (e.g. `.1160.f2d4ee1`).";
};
system.nixpkgsRevision = mkOption {
@@ -106,24 +119,37 @@ in
default = if useSourceRevision && nixpkgsSrc ? rev
then nixpkgsSrc.rev
else lib.trivial.revisionWithDefault null;
- description = lib.mdDoc "The nixpkgs git revision from which this configuration was built.";
+ description = "The nixpkgs git revision from which this configuration was built.";
};
system.configurationRevision = mkOption {
type = types.nullOr types.str;
default = null;
- description = lib.mdDoc "The Git revision of the top-level flake from which this configuration was built.";
+ description = "The Git revision of the top-level flake from which this configuration was built.";
};
};
config = {
# This default is set here rather than up there so that the options
# 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";
- } ];
+ system.darwinLabel = mkDefault cfg.darwinVersion;
+
+ 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};
+ '';
+ }
+ ];
};
}