summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/pg/pghero/update.nix
blob: 4b85dd8f76a3202afe4ad25b3f2d7f4ea2f6e8f3 (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
51
52
53
54
55
56
57
58
59
60
61
62
{
  lib,
  writeShellScript,
  git,
  nix,
  bundler,
  bundix,
  coreutils,
  common-updater-scripts,
}:
writeShellScript "update-script" ''
  set -eu
  PATH=${
    lib.makeBinPath [
      git
      nix
      bundler
      bundix
      coreutils
      common-updater-scripts
    ]
  }
  nix() {
    command nix --extra-experimental-features nix-command "$@"
  }
  bundle() {
    BUNDLE_FORCE_RUBY_PLATFORM=1 command bundle "$@"
  }

  attrPath=''${UPDATE_NIX_ATTR_PATH:-pghero}

  toplevel=$(git rev-parse --show-toplevel)
  position=$(nix eval --file "$toplevel" --raw "$attrPath.meta.position")
  gemdir=$(dirname "$position")

  cd "$gemdir"

  tempdir=$(mktemp -d)
  cleanup() {
    rc=$?
    rm -r -- "$tempdir" || true
    exit $rc
  }
  trap cleanup EXIT

  cp gemset.nix "$tempdir"

  bundle lock --update --lockfile="$tempdir"/Gemfile.lock
  bundix --lockfile="$tempdir"/Gemfile.lock --gemset="$tempdir"/gemset.nix

  oldVersion=''${UPDATE_NIX_OLD_VERSION-}
  newVersion=$(nix eval --file "$tempdir"/gemset.nix --raw pghero.version)

  if [ "$oldVersion" = "$newVersion" ]; then
    exit
  fi

  cp "$tempdir"/{Gemfile.lock,gemset.nix} .

  cd "$toplevel"
  update-source-version "$attrPath" "$newVersion" --file="$gemdir"/package.nix --ignore-same-hash
''