update glitch
This commit is contained in:
parent
87ffa71fe4
commit
045c0ed739
8 changed files with 704 additions and 540 deletions
|
@ -1,108 +1,42 @@
|
|||
#!/usr/bin/env -S nix shell nixpkgs#bundix nixpkgs#coreutils nixpkgs#diffutils nixpkgs#nix-prefetch-git nixpkgs#nix-prefetch-github nixpkgs#gnused nixpkgs#jq nixpkgs#prefetch-yarn-deps -c bash
|
||||
#!/usr/bin/env -S nix shell nixpkgs#coreutils nixpkgs#bundix nixpkgs#nix-prefetch-github nixpkgs#jq -c bash
|
||||
|
||||
set -e
|
||||
|
||||
OWNER=mastodon
|
||||
REPO=mastodon
|
||||
cd "$(dirname "$0")" # cd to the script's directory
|
||||
|
||||
POSITIONAL=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
echo "Retrieving latest glitch-soc commit..."
|
||||
commit="$(curl -SsL 'https://api.github.com/repos/glitch-soc/mastodon/branches/main')"
|
||||
rev="$(jq -r '.commit.sha' <<<"$commit")"
|
||||
echo "Latest commit is $rev."
|
||||
|
||||
case $key in
|
||||
--owner)
|
||||
OWNER="$2"
|
||||
shift # past argument
|
||||
shift # past value
|
||||
;;
|
||||
--repo)
|
||||
REPO="$2"
|
||||
shift # past argument
|
||||
shift # past value
|
||||
;;
|
||||
--ver)
|
||||
VERSION="$2"
|
||||
shift # past argument
|
||||
shift # past value
|
||||
;;
|
||||
--rev)
|
||||
REVISION="$2"
|
||||
shift # past argument
|
||||
shift # past value
|
||||
;;
|
||||
--patches)
|
||||
PATCHES="$2"
|
||||
shift # past argument
|
||||
shift # past value
|
||||
;;
|
||||
*) # unknown option
|
||||
POSITIONAL+=("$1")
|
||||
shift # past argument
|
||||
;;
|
||||
esac
|
||||
done
|
||||
echo
|
||||
echo "Prefetching source..."
|
||||
hash="$(nix-prefetch-github glitch-soc mastodon --rev "$rev" | jq -r '.hash')"
|
||||
|
||||
if [[ -n "$POSITIONAL" ]]; then
|
||||
echo "Usage: update.sh [--owner OWNER] [--repo REPO] [--ver VERSION] [--rev REVISION] [--patches PATCHES]"
|
||||
echo "OWNER and REPO must be paths on github."
|
||||
echo "If REVISION is not provided, the latest tag from github.com/mastodon/mastodon is fetched and VERSION is calculated from it."
|
||||
echo "If OWNER and REPO are not provided, it defaults they default to mastodon and mastodon."
|
||||
echo "PATCHES, if provided, should be one or more Nix expressions separated by spaces."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VERSION="${REVISION:0:7}"
|
||||
|
||||
rm -f gemset.nix source.nix
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
|
||||
|
||||
WORK_DIR=$(mktemp -d)
|
||||
|
||||
# Check that working directory was created.
|
||||
if [[ -z "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
|
||||
echo "Could not create temporary directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Delete the working directory on exit.
|
||||
function cleanup {
|
||||
# Report errors, if any, from nix-prefetch-git
|
||||
grep "fatal" $WORK_DIR/nix-prefetch-git.out >/dev/stderr || true
|
||||
rm -rf "$WORK_DIR"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
echo "Fetching source code $REVISION"
|
||||
JSON=$(nix-prefetch-github "$OWNER" "$REPO" --rev "$REVISION" 2> $WORK_DIR/nix-prefetch-git.out)
|
||||
HASH=$(echo "$JSON" | jq -r .hash)
|
||||
|
||||
cat > source.nix << EOF
|
||||
# This file was generated by pkgs.mastodon.updateScript.
|
||||
{ fetchFromGitHub, applyPatches, patches ? [] }:
|
||||
let
|
||||
version = "$VERSION";
|
||||
revision = "$REVISION";
|
||||
in
|
||||
(
|
||||
applyPatches {
|
||||
src = fetchFromGitHub {
|
||||
owner = "$OWNER";
|
||||
repo = "$REPO";
|
||||
rev = "\${revision}";
|
||||
hash = "$HASH";
|
||||
};
|
||||
patches = patches ++ [$PATCHES];
|
||||
}) // {
|
||||
inherit version;
|
||||
yarnHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
|
||||
echo
|
||||
echo "Generating version_data.nix..."
|
||||
cat > version_data.nix << EOF
|
||||
# This file was generated with update.sh.
|
||||
{
|
||||
rev = "$rev";
|
||||
hash = "$hash";
|
||||
yarnHash = "";
|
||||
}
|
||||
EOF
|
||||
SOURCE_DIR="$(nix-build --no-out-link -E '(import <nixpkgs> {}).callPackage ./source.nix {}')"
|
||||
|
||||
echo "Creating gemset.nix"
|
||||
bundix --lockfile="$SOURCE_DIR/Gemfile.lock" --gemfile="$SOURCE_DIR/Gemfile"
|
||||
echo "" >> gemset.nix # Create trailing newline to please EditorConfig checks
|
||||
echo
|
||||
echo "Building source derivation..."
|
||||
srcdir="$(nix build --no-link --print-out-paths --no-warn-dirty ../..#glitch-soc-source)"
|
||||
echo "Source derivation is $srcdir."
|
||||
|
||||
# echo "Creating yarn-hash.nix"
|
||||
# YARN_HASH="$(prefetch-yarn-deps "$SOURCE_DIR/yarn.lock")"
|
||||
# YARN_HASH="$(nix hash to-sri --type sha256 "$YARN_HASH")"
|
||||
# sed -i "s/sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=/$YARN_HASH/g" source.nix
|
||||
echo
|
||||
echo "Generating gemset.nix using built source derivation..."
|
||||
rm -f gemset.nix
|
||||
bundix --quiet --lockfile $srcdir/Gemfile.lock --gemfile $srcdir/Gemfile
|
||||
echo "" >> gemset.nix
|
||||
|
||||
echo
|
||||
echo "Done."
|
||||
|
||||
echo
|
||||
echo "You'll have to manually enter the commit hash for the yarn deps from the error message when first trying to build the package."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue