summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorJan Malakhovski <oxij@oxij.org>2015-09-18 13:46:47 +0000
committerJan Malakhovski <oxij@oxij.org>2015-11-12 21:14:49 +0000
commit732eb3c4ccaac3312fe9334b5d77b3b88140c971 (patch)
treef7ed819441b6078341e4d7e00e33a273442fedbe /nixos
parenta99a634acf674730975f0d29ce31d2c71226821b (diff)
downloadnixlib-732eb3c4ccaac3312fe9334b5d77b3b88140c971.tar
nixlib-732eb3c4ccaac3312fe9334b5d77b3b88140c971.tar.gz
nixlib-732eb3c4ccaac3312fe9334b5d77b3b88140c971.tar.bz2
nixlib-732eb3c4ccaac3312fe9334b5d77b3b88140c971.tar.lz
nixlib-732eb3c4ccaac3312fe9334b5d77b3b88140c971.tar.xz
nixlib-732eb3c4ccaac3312fe9334b5d77b3b88140c971.tar.zst
nixlib-732eb3c4ccaac3312fe9334b5d77b3b88140c971.zip
nixos: cleanup version module, allow setting nixosVersion with env variable
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/misc/version.nix48
1 files changed, 27 insertions, 21 deletions
diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix
index b4b0281fe587..ee6948db3d3a 100644
--- a/nixos/modules/misc/version.nix
+++ b/nixos/modules/misc/version.nix
@@ -2,13 +2,21 @@
 
 with lib;
 
+let
+  cfg = config.system;
+
+  releaseFile = "${toString pkgs.path}/.version";
+  suffixFile = "${toString pkgs.path}/.version-suffix";
+  revisionFile = "${toString pkgs.path}/.git-revision";
+in
+
 {
 
-  options = {
+  options.system = {
 
-    system.stateVersion = mkOption {
+    stateVersion = mkOption {
       type = types.str;
-      default = config.system.nixosRelease;
+      default = cfg.nixosRelease;
       description = ''
         Every once in a while, a new NixOS release may change
         configuration defaults in a way incompatible with stateful
@@ -22,38 +30,40 @@ with lib;
       '';
     };
 
-    system.nixosVersion = mkOption {
+    nixosVersion = mkOption {
       internal = true;
       type = types.str;
       description = "NixOS version.";
     };
 
-    system.nixosRelease = mkOption {
+    nixosRelease = mkOption {
       readOnly = true;
       type = types.str;
-      default = readFile "${toString pkgs.path}/.version";
+      default = readFile releaseFile;
       description = "NixOS release.";
     };
 
-    system.nixosVersionSuffix = mkOption {
+    nixosVersionSuffix = mkOption {
       internal = true;
       type = types.str;
+      default = if pathExists suffixFile then readFile suffixFile else "pre-git";
       description = "NixOS version suffix.";
     };
 
-    system.nixosRevision = mkOption {
+    nixosRevision = mkOption {
       internal = true;
       type = types.str;
+      default = if pathExists revisionFile then readFile revisionFile else "master";
       description = "NixOS Git revision hash.";
     };
 
-    system.nixosCodeName = mkOption {
+    nixosCodeName = mkOption {
       readOnly = true;
       type = types.str;
       description = "NixOS release code name.";
     };
 
-    system.defaultChannel = mkOption {
+    defaultChannel = mkOption {
       internal = true;
       type = types.str;
       default = https://nixos.org/channels/nixos-unstable;
@@ -64,18 +74,14 @@ with lib;
 
   config = {
 
-    system.nixosVersion = mkDefault (config.system.nixosRelease + config.system.nixosVersionSuffix);
-
-    system.nixosVersionSuffix =
-      let suffixFile = "${toString pkgs.path}/.version-suffix"; in
-      mkDefault (if pathExists suffixFile then readFile suffixFile else "pre-git");
+    system = {
+      # This is set here rather than up there so that changing this
+      # env variable will not rebuild the manual
+      nixosVersion = mkDefault (maybeEnv "NIXOS_VERSION" (cfg.nixosRelease + cfg.nixosVersionSuffix));
 
-    system.nixosRevision =
-      let fn = "${toString pkgs.path}/.git-revision"; in
-      mkDefault (if pathExists fn then readFile fn else "master");
-
-    # Note: code names must only increase in alphabetical order.
-    system.nixosCodeName = "Emu";
+      # Note: code names must only increase in alphabetical order.
+      nixosCodeName = "Emu";
+    };
 
     # Generate /etc/os-release.  See
     # http://0pointer.de/public/systemd-man/os-release.html for the