depot/pkgs/by-name/pg/pghero/update.nix
Luke Granger-Brown 57725ef3ec Squashed 'third_party/nixpkgs/' content from commit 76612b17c0ce
git-subtree-dir: third_party/nixpkgs
git-subtree-split: 76612b17c0ce71689921ca12d9ffdc9c23ce40b2
2024-11-10 23:59:47 +00:00

59 lines
1.2 KiB
Nix

{ 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
''