From 55d881eea334049dbb6ac10623bb895363857fca Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 9 Aug 2016 14:11:29 +0200 Subject: [PATCH 1/2] Revert adding .git-revision unconditionally This reverts commit 1e534e234b0a92bf06361fa41b7ac8691fdbc769. We already should have a .git directory if it is managed via Git, otherwise there is no way to get the Git revision if neither .git-revision or .git is present. But having .git-revision _and_ .git present seems very much redundant to me. Signed-off-by: aszlig Cc: @bennofs, @Profpatsch Issue: #17218 --- .../tools/{get-git-revision => get-version-suffix} | 2 +- nixos/modules/installer/tools/nixos-rebuild.sh | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) rename nixos/modules/installer/tools/{get-git-revision => get-version-suffix} (95%) diff --git a/nixos/modules/installer/tools/get-git-revision b/nixos/modules/installer/tools/get-version-suffix similarity index 95% rename from nixos/modules/installer/tools/get-git-revision rename to nixos/modules/installer/tools/get-version-suffix index b57d9cf9fa0..b8972cd57d2 100644 --- a/nixos/modules/installer/tools/get-git-revision +++ b/nixos/modules/installer/tools/get-version-suffix @@ -17,6 +17,6 @@ getVersion() { if nixpkgs=$(nix-instantiate --find-file nixpkgs "$@"); then getVersion $nixpkgs if [ -n "$rev" ]; then - echo "$rev" + echo ".git.$rev" fi fi diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index 80a4537375c..5ecdcdb3cdb 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -311,10 +311,9 @@ fi # nixos-version shows something useful). if [ -n "$canRun" ]; then if nixpkgs=$(nix-instantiate --find-file nixpkgs "${extraBuildFlags[@]}"); then - revision=$($SHELL $nixpkgs/nixos/modules/installer/tools/get-git-revision "${extraBuildFlags[@]}" || true) - if [ -n "$revision" ]; then - echo -n ".git.$revision" > "$nixpkgs/.version-suffix" || true - echo -n "$revision" > "$nixpkgs/.git-revision" || true + suffix=$($SHELL $nixpkgs/nixos/modules/installer/tools/get-version-suffix "${extraBuildFlags[@]}" || true) + if [ -n "$suffix" ]; then + echo -n "$suffix" > "$nixpkgs/.version-suffix" || true fi fi fi From 0b9d9eded15e13079b1f0fef059ecb25bfb308c4 Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 9 Aug 2016 14:15:53 +0200 Subject: [PATCH 2/2] nixos/version: Try to get Git revison from .git Let's first try if we can determine the Git revision from the .git directory and if that fails, fall back to get the info from the ".git-revision" file... and after that use something generic like "master". This should address #17218 in better way, because we don't need to create another redundant file in the source checkout of nixpkgs. I'm not going to route of falling back to using .git, because after 55d881e, we already have ".git-revision" files in people's Git repositories, which in turn means that nixos-version will report that old file every time even if the working tree has updated. Signed-off-by: aszlig Cc: @bennofs, Profpatsch Reported-by: @devhell Fixes: #17218 --- nixos/modules/misc/version.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix index 6af310a9d87..2ecdbdbf392 100644 --- a/nixos/modules/misc/version.nix +++ b/nixos/modules/misc/version.nix @@ -63,7 +63,9 @@ in nixosRevision = mkOption { internal = true; type = types.str; - default = if pathExists revisionFile then fileContents revisionFile else "master"; + default = if pathIsDirectory gitRepo then commitIdFromGitRepo gitRepo + else if pathExists revisionFile then fileContents revisionFile + else "master"; description = "The Git revision from which this NixOS configuration was built."; };