summary refs log tree commit diff
path: root/modules/installer/tools/get-version-suffix
blob: 76cec8d5dae32975dcc5cb673fb558dd40701952 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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 nixos=$(nix-instantiate --find-file nixos "$@"); then
    getVersion $nixos
    if [ -n "$rev" ]; then
        suffix="pre-$rev"
        if nixpkgs=$(nix-instantiate --find-file nixpkgs "$@"); then
            getVersion $nixpkgs
            if [ -n "$rev" ]; then
                suffix+="-$rev"
            fi
        fi
        echo $suffix
    fi
fi