aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/modules/installer/tools/get-version-suffix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/nixos/modules/installer/tools/get-version-suffix')
-rw-r--r--nixpkgs/nixos/modules/installer/tools/get-version-suffix22
1 files changed, 22 insertions, 0 deletions
diff --git a/nixpkgs/nixos/modules/installer/tools/get-version-suffix b/nixpkgs/nixos/modules/installer/tools/get-version-suffix
new file mode 100644
index 00000000000..b8972cd57d2
--- /dev/null
+++ b/nixpkgs/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