summary refs log tree commit diff
path: root/nixos/modules/installer/tools/get-version-suffix
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2016-08-09 14:11:29 +0200
committeraszlig <aszlig@redmoonstudios.org>2016-08-09 14:15:06 +0200
commit55d881eea334049dbb6ac10623bb895363857fca (patch)
tree451fe519a10072585adb88c2d1086489a4f39d13 /nixos/modules/installer/tools/get-version-suffix
parent199f5a2844cb31be96872599d8db7105b572f116 (diff)
downloadnixpkgs-55d881eea334049dbb6ac10623bb895363857fca.tar
nixpkgs-55d881eea334049dbb6ac10623bb895363857fca.tar.gz
nixpkgs-55d881eea334049dbb6ac10623bb895363857fca.tar.bz2
nixpkgs-55d881eea334049dbb6ac10623bb895363857fca.tar.lz
nixpkgs-55d881eea334049dbb6ac10623bb895363857fca.tar.xz
nixpkgs-55d881eea334049dbb6ac10623bb895363857fca.tar.zst
nixpkgs-55d881eea334049dbb6ac10623bb895363857fca.zip
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 <aszlig@redmoonstudios.org>
Cc: @bennofs, @Profpatsch
Issue: #17218
Diffstat (limited to 'nixos/modules/installer/tools/get-version-suffix')
-rw-r--r--nixos/modules/installer/tools/get-version-suffix22
1 files changed, 22 insertions, 0 deletions
diff --git a/nixos/modules/installer/tools/get-version-suffix b/nixos/modules/installer/tools/get-version-suffix
new file mode 100644
index 00000000000..b8972cd57d2
--- /dev/null
+++ b/nixos/modules/installer/tools/get-version-suffix
@@ -0,0 +1,22 @@
+getVersion() {
+    local dir="$1"
+    rev=
+    if [ -e "$dir/.git" ]; then
+        if [ -z "$(type -P git)" ]; then
+            echo "warning: Git not found; cannot figure out revision of $dir" >&2
+            return
+        fi
+        cd "$dir"
+        rev=$(git rev-parse --short HEAD)
+        if git describe --always --dirty | grep -q dirty; then
+            rev+=M
+        fi
+    fi
+}
+
+if nixpkgs=$(nix-instantiate --find-file nixpkgs "$@"); then
+    getVersion $nixpkgs
+    if [ -n "$rev" ]; then
+        echo ".git.$rev"
+    fi
+fi