From b35fe01f025fdbc0c0ca9352583b685ead6e3b10 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 16 Jan 2013 14:40:41 +0100 Subject: [PATCH] Set the NixOS version to something useful when building from Git --- modules/installer/tools/nixos-rebuild.sh | 10 ++++++++++ modules/misc/version.nix | 17 ++++++++++++----- release.nix | 4 ++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/modules/installer/tools/nixos-rebuild.sh b/modules/installer/tools/nixos-rebuild.sh index 0b149610e324..28a1d2282939 100644 --- a/modules/installer/tools/nixos-rebuild.sh +++ b/modules/installer/tools/nixos-rebuild.sh @@ -140,6 +140,16 @@ if [ -n "$buildNix" ]; then fi +# Update the version suffix if we're building from Git (so that +# nixos-version shows something useful). +if nixos=$(nix-instantiate --find-file nixos "${extraBuildFlags[@]}"); then + suffix=$($SHELL $nixos/modules/installer/tools/get-version-suffix "${extraBuildFlags[@]}") + if [ -n "$suffix" ]; then + echo -n "$suffix" > "$nixos/.version-suffix" + fi +fi + + # Either upgrade the configuration in the system profile (for "switch" # or "boot"), or just build it and create a symlink "result" in the # current directory (for "build" and "test"). diff --git a/modules/misc/version.nix b/modules/misc/version.nix index 319cdcb5f98f..23e96171d1fe 100644 --- a/modules/misc/version.nix +++ b/modules/misc/version.nix @@ -5,18 +5,25 @@ with pkgs.lib; { options = { - + system.nixosVersion = mkOption { - default = - builtins.readFile ../../.version - + (if builtins.pathExists ../../.version-suffix then builtins.readFile ../../.version-suffix else "pre-git"); description = "NixOS version."; }; + system.nixosVersionSuffix = mkOption { + description = "NixOS version suffix."; + }; + }; config = { + system.nixosVersion = + builtins.readFile ../../.version + config.system.nixosVersionSuffix; + + system.nixosVersionSuffix = + if builtins.pathExists ../../.version-suffix then builtins.readFile ../../.version-suffix else "pre-git"; + # Generate /etc/os-release. See # http://0pointer.de/public/systemd-man/os-release.html for the # format. @@ -32,7 +39,7 @@ with pkgs.lib; ''; target = "os-release"; }; - + }; } diff --git a/release.nix b/release.nix index 4c29fce29f29..6caf3b385b16 100644 --- a/release.nix +++ b/release.nix @@ -20,7 +20,7 @@ let let versionModule = - { system.nixosVersion = version + (lib.optionalString (!officialRelease) versionSuffix); + { system.nixosVersionSuffix = lib.optionalString (!officialRelease) versionSuffix; isoImage.isoBaseName = "nixos-${type}"; }; @@ -55,7 +55,7 @@ let with import {inherit system;}; let - versionModule = { system.nixosVersion = version + (lib.optionalString (!officialRelease) versionSuffix); }; + versionModule = { system.nixosVersionSuffix = lib.optionalString (!officialRelease) versionSuffix; }; config = (import lib/eval-config.nix { inherit system;