2021-05-21 21:15:23 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
2021-05-29 15:33:16 +00:00
|
|
|
#!nix-shell -i bash -p jq nix-prefetch-github yarn yarn2nix-moretea.yarn2nix moreutils
|
2021-05-21 21:15:23 +00:00
|
|
|
|
|
|
|
# NOTE: please check on new releases which steps aren't necessary anymore!
|
|
|
|
# Currently the following things are done:
|
|
|
|
#
|
|
|
|
# * Add correct `name`/`version` field to `package.json`, otherwise `yarn2nix` fails to
|
|
|
|
# find required dependencies.
|
|
|
|
# * Adjust `file:`-dependencies a bit for the structure inside a Nix build.
|
|
|
|
# * Update hashes for the tarball & the fixed-output drv with all `mix`-dependencies.
|
|
|
|
# * Generate `yarn.lock` & `yarn.nix` in a temporary directory.
|
|
|
|
|
2021-05-29 15:33:16 +00:00
|
|
|
set -euxo pipefail
|
2021-05-21 21:15:23 +00:00
|
|
|
|
|
|
|
dir="$(realpath $(dirname "$0"))"
|
2021-05-29 15:33:16 +00:00
|
|
|
export latest="$(curl -q https://api.github.com/repos/plausible/analytics/releases/latest \
|
2021-05-21 21:15:23 +00:00
|
|
|
| jq -r '.tag_name')"
|
|
|
|
nix_version="$(cut -c2- <<< "$latest")"
|
|
|
|
|
2021-05-29 15:33:16 +00:00
|
|
|
if [[ "$(nix-instantiate -A plausible.version --eval --json | jq -r)" = "$nix_version" ]];
|
2021-05-21 21:15:23 +00:00
|
|
|
then
|
|
|
|
echo "Already using version $latest, skipping"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
SRC="https://raw.githubusercontent.com/plausible/analytics/${latest}"
|
|
|
|
|
|
|
|
package_json="$(curl -qf "$SRC/assets/package.json")"
|
|
|
|
|
|
|
|
echo "$package_json" \
|
2021-11-06 13:10:16 +00:00
|
|
|
| jq '. + {"name":"plausible","version": $ENV.latest}' \
|
2021-05-21 21:15:23 +00:00
|
|
|
| sed -e 's,../deps/,../../tmp/deps/,g' \
|
|
|
|
> $dir/package.json
|
|
|
|
|
2021-05-29 15:33:16 +00:00
|
|
|
tarball_meta="$(nix-prefetch-github plausible analytics --rev "$latest")"
|
|
|
|
tarball_hash="$(nix to-base32 sha256-$(jq -r '.sha256' <<< "$tarball_meta"))"
|
|
|
|
tarball_path="$(nix-build -E 'with import ./. {}; { p }: fetchFromGitHub (builtins.fromJSON p)' --argstr p "$tarball_meta")"
|
2021-05-21 21:15:23 +00:00
|
|
|
fake_hash="$(nix-instantiate --eval -A lib.fakeSha256 | xargs echo)"
|
|
|
|
|
|
|
|
sed -i "$dir/default.nix" \
|
|
|
|
-e 's,version = ".*",version = "'"$nix_version"'",' \
|
|
|
|
-e '/^ src = fetchFromGitHub/,+4{;s/sha256 = "\(.*\)"/sha256 = "'"$tarball_hash"'"/}' \
|
2021-05-29 14:13:20 +00:00
|
|
|
-e '/^ mixFodDeps =/,+3{;s/sha256 = "\(.*\)"/sha256 = "'"$fake_hash"'"/}'
|
2021-05-21 21:15:23 +00:00
|
|
|
|
2021-05-29 15:33:16 +00:00
|
|
|
mix_hash="$(nix to-base32 $(nix-build -A plausible.mixFodDeps 2>&1 | tail -n3 | grep 'got:' | cut -d: -f2- | xargs echo || true))"
|
2021-05-21 21:15:23 +00:00
|
|
|
|
2021-05-29 14:13:20 +00:00
|
|
|
sed -i "$dir/default.nix" -e '/^ mixFodDeps =/,+3{;s/sha256 = "\(.*\)"/sha256 = "'"$mix_hash"'"/}'
|
2021-05-21 21:15:23 +00:00
|
|
|
|
|
|
|
tmp_setup_dir="$(mktemp -d)"
|
|
|
|
trap "rm -rf $tmp_setup_dir" EXIT
|
|
|
|
|
|
|
|
cp -r $tarball_path/* $tmp_setup_dir/
|
2021-05-29 14:13:20 +00:00
|
|
|
cp -r "$(nix-build -A plausible.mixFodDeps)" "$tmp_setup_dir/deps"
|
2021-05-29 15:33:16 +00:00
|
|
|
chmod -R u+rwx "$tmp_setup_dir"
|
2021-05-21 21:15:23 +00:00
|
|
|
|
|
|
|
pushd $tmp_setup_dir/assets
|
|
|
|
yarn
|
|
|
|
yarn2nix > "$dir/yarn.nix"
|
|
|
|
cp yarn.lock "$dir/yarn.lock"
|
|
|
|
popd
|
|
|
|
|
|
|
|
nix-build -A plausible
|