summaryrefslogtreecommitdiff
path: root/pkgs/nix-tools/darwin-version.sh
blob: e19443a433a1513be1d1ad019eaa5f63c3b2b8f1 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#! @shell@
set -e
set -o pipefail
export PATH=@path@:$PATH

showSyntax() {
  echo "darwin-version [--help|--darwin-revision|--nixpkgs-revision|--configuration-revision|--json]" >&2
}

case "$1" in
  --help)
    showSyntax
    ;;
  --darwin-revision)
    revision="$(jq --raw-output '.darwinRevision // "null"' < /run/current-system/darwin-version.json)"
    if [[ "$revision" == "null" ]]; then
      echo "$0: nix-darwin commit hash is unknown" >&2
      exit 1
    fi
    echo "$revision"
    ;;
  --nixpkgs-revision)
    revision="$(jq --raw-output '.nixpkgsRevision // "null"' < /run/current-system/darwin-version.json)"
    if [[ "$revision" == "null" ]]; then
      echo "$0: Nixpkgs commit hash is unknown" >&2
      exit 1
    fi
    echo "$revision"
    ;;
  --configuration-revision)
    revision="$(jq --raw-output '.configurationRevision // "null"' < /run/current-system/darwin-version.json)"
    if [[ "$revision" == "null" ]]; then
      echo "$0: configuration commit hash is unknown" >&2
      exit 1
    fi
    echo "$revision"
    ;;
  --json)
    cat /run/current-system/darwin-version.json
    ;;
  *)
    label="$(jq --raw-output '.darwinLabel // "null"' < /run/current-system/darwin-version.json)"
    if [[ "$label" == "null" ]]; then
      showSyntax
      exit 1
    fi
    echo "$label"
    ;;
esac