nixos-rebuild: inline get-version-suffix script

It has no other consumers anyway. Also saves some work.
This commit is contained in:
K900 2024-09-19 20:05:58 +03:00
parent 7df54fcf63
commit 1bf0ffb22e
2 changed files with 21 additions and 24 deletions

View File

@ -1,23 +0,0 @@
getVersion() {
local dir="$1"
rev=
gitDir="$dir/.git"
if [ -e "$gitDir" ]; 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 --git-dir="$gitDir" rev-parse --short HEAD)
if git --git-dir="$gitDir" 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

View File

@ -548,6 +548,26 @@ getNixDrv() {
fi
}
getVersion() {
local dir="$1"
local rev=
local gitDir="$dir/.git"
if [ -e "$gitDir" ]; 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 --git-dir="$gitDir" rev-parse --short HEAD)
if git --git-dir="$gitDir" describe --always --dirty | grep -q dirty; then
rev+=M
fi
fi
echo ".git.$rev"
}
if [[ -n $buildNix && -z $flake ]]; then
log "building Nix..."
getNixDrv
@ -569,7 +589,7 @@ fi
# nixos-version shows something useful).
if [[ -n $canRun && -z $flake ]]; then
if nixpkgs=$(runCmd nix-instantiate --find-file nixpkgs "${extraBuildFlags[@]}"); then
suffix=$(runCmd $SHELL "$nixpkgs/nixos/modules/installer/tools/get-version-suffix" "${extraBuildFlags[@]}" || true)
suffix=$(getVersion "$nixpkgs" || true)
if [ -n "$suffix" ]; then
echo -n "$suffix" > "$nixpkgs/.version-suffix" || true
fi