summary refs log tree commit diff
path: root/nixos/modules/misc/version.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-27 19:46:36 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-27 20:30:09 +0200
commitd166c854b6ecfd9ada520439b06f7eb9e3e4be7c (patch)
tree2f94ab69034b71c912ef5d477ecd141979089a2f /nixos/modules/misc/version.nix
parente3a5bca4ae3737dbe0ff2675d1fd77fdf72db609 (diff)
downloadnixpkgs-d166c854b6ecfd9ada520439b06f7eb9e3e4be7c.tar
nixpkgs-d166c854b6ecfd9ada520439b06f7eb9e3e4be7c.tar.gz
nixpkgs-d166c854b6ecfd9ada520439b06f7eb9e3e4be7c.tar.bz2
nixpkgs-d166c854b6ecfd9ada520439b06f7eb9e3e4be7c.tar.lz
nixpkgs-d166c854b6ecfd9ada520439b06f7eb9e3e4be7c.tar.xz
nixpkgs-d166c854b6ecfd9ada520439b06f7eb9e3e4be7c.tar.zst
nixpkgs-d166c854b6ecfd9ada520439b06f7eb9e3e4be7c.zip
Add option system.stateVersion
This option requests compatibility with older NixOS releases with
respect to stateful data, in cases where new releases have defaults
that might be incompatible with system state of existing NixOS
deployments. For instance, if we change the default version of
PostgreSQL, existing deployments will break if the new version can't
read databases created by the old version.

So for example, setting

  system.stateVersion = "15.07";

requests that options like services.postgresql.package use defaults
corresponding to the 15.07 release branch. Note that
nixos-generate-config emits this option. (In the future, NixOps may
set system.stateVersion to the NixOS release in use when the machine
was created.)

See also #7939 for another motivating example.
Diffstat (limited to 'nixos/modules/misc/version.nix')
-rw-r--r--nixos/modules/misc/version.nix26
1 files changed, 24 insertions, 2 deletions
diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix
index 5afdcf214f2..8a52df42dd8 100644
--- a/nixos/modules/misc/version.nix
+++ b/nixos/modules/misc/version.nix
@@ -6,12 +6,35 @@ with lib;
 
   options = {
 
+    system.stateVersion = mkOption {
+      type = types.str;
+      default = config.system.nixosRelease;
+      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
+        changes, the new version will probably be unable to read your
+        existing databases. To prevent such breakage, you can set the
+        value of this option to the NixOS release with which you want
+        to be compatible. The effect is that NixOS will option
+        defaults corresponding to the specified release (such as using
+        an older version of PostgreSQL).
+      '';
+    };
+
     system.nixosVersion = mkOption {
       internal = true;
       type = types.str;
       description = "NixOS version.";
     };
 
+    system.nixosRelease = mkOption {
+      internal = true;
+      type = types.str;
+      default = readFile "${toString pkgs.path}/.version";
+      description = "NixOS release.";
+    };
+
     system.nixosVersionSuffix = mkOption {
       internal = true;
       type = types.str;
@@ -41,8 +64,7 @@ with lib;
 
   config = {
 
-    system.nixosVersion =
-      mkDefault (readFile "${toString pkgs.path}/.version" + config.system.nixosVersionSuffix);
+    system.nixosVersion = mkDefault (config.system.nixosRelease + config.system.nixosVersionSuffix);
 
     system.nixosVersionSuffix =
       let suffixFile = "${toString pkgs.path}/.version-suffix"; in