mastodon: use fetchFromGitHub, fix shellcheck hints

This commit is contained in:
Sandro Jäckel 2023-06-20 23:36:06 +02:00
parent e9e3f2e736
commit 0000005ec6
No known key found for this signature in database
GPG Key ID: 3AF5A43A3EECC2E5
3 changed files with 32 additions and 28 deletions

View File

@ -1,9 +1,10 @@
# This file was generated by pkgs.mastodon.updateScript.
{ fetchgit, applyPatches }: let
src = fetchgit {
url = "https://github.com/mastodon/mastodon.git";
{ fetchFromGitHub, applyPatches }: let
src = fetchFromGitHub {
owner = "mastodon";
repo = "mastodon";
rev = "v4.1.2";
sha256 = "18yzpc2rz9sa04y2sdxzsfkndbqqsfqvji47imwc3yj40l8hciws";
sha256 = "mkcGEQVE+sF4jYdEubHTGK9mp9O/Ny08AUqnnwW736M=";
};
in applyPatches {
inherit src;

View File

@ -1,17 +1,16 @@
{ pkgs
, runCommand
{ runCommand
, lib
, makeWrapper
, yarn2nix
, bundix
, coreutils
, diffutils
, nix-prefetch-git
, nix-prefetch-github
, gnused
, jq
}:
let
binPath = lib.makeBinPath [ yarn2nix bundix coreutils diffutils nix-prefetch-git gnused jq ];
binPath = lib.makeBinPath [ yarn2nix bundix coreutils diffutils nix-prefetch-github gnused jq ];
in
runCommand "mastodon-update-script"
{

View File

@ -1,15 +1,21 @@
#!/usr/bin/env bash
set -e
URL=https://github.com/mastodon/mastodon.git
OWNER=mastodon
REPO=mastodon
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--url)
URL="$2"
--owner)
OWNER="$2"
shift # past argument
shift # past value
;;
--repo)
REPO="$2"
shift # past argument
shift # past value
;;
@ -36,13 +42,11 @@ while [[ $# -gt 0 ]]; do
done
if [[ -z "$VERSION" || -n "$POSITIONAL" ]]; then
echo "Usage: update.sh [--url URL] --ver VERSION [--rev REVISION] [--patches PATCHES]"
echo "URL may be any path acceptable to 'git clone' and VERSION the"
echo "semantic version number. If VERSION is not a revision acceptable to"
echo "'git checkout', you must provide one in REVISION. If URL is not"
echo "provided, it defaults to https://github.com/mastodon/mastodon.git."
echo "PATCHES, if provided, should be one or more Nix expressions"
echo "separated by spaces."
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 VERSION is not a revision acceptable to 'git checkout', you must provide one in REVISION."
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
@ -57,7 +61,7 @@ TARGET_DIR="$PWD"
WORK_DIR=$(mktemp -d)
# Check that working directory was created.
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
if [[ -z "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
echo "Could not create temporary directory"
exit 1
fi
@ -70,19 +74,19 @@ function cleanup {
}
trap cleanup EXIT
echo "Fetching source code $REVISION from $URL"
JSON=$(nix-prefetch-git --url "$URL" --rev "$REVISION" 2> $WORK_DIR/nix-prefetch-git.out)
SHA=$(echo $JSON | jq -r .sha256)
FETCHED_SOURCE_DIR=$(grep '^path is' $WORK_DIR/nix-prefetch-git.out | sed 's/^path is //')
echo "Fetching source code $REVISION"
JSON=$(nix-prefetch-github "$OWNER" "$REPO" --rev "$REVISION" 2> $WORK_DIR/nix-prefetch-git.out)
SHA=$(echo "$JSON" | jq -r .sha256)
echo "Creating version.nix"
echo \"$VERSION\" | sed 's/^"v/"/' > version.nix
echo "\"$VERSION\"" | sed 's/^"v/"/' > version.nix
cat > source.nix << EOF
# This file was generated by pkgs.mastodon.updateScript.
{ fetchgit, applyPatches }: let
src = fetchgit {
url = "$URL";
{ fetchFromGitHub, applyPatches }: let
src = fetchFromGitHub {
owner = "mastodon";
repo = "mastodon";
rev = "$REVISION";
sha256 = "$SHA";
};
@ -95,4 +99,4 @@ SOURCE_DIR="$(nix-build --no-out-link -E '(import <nixpkgs> {}).callPackage ./so
echo "Creating gemset.nix"
bundix --lockfile="$SOURCE_DIR/Gemfile.lock" --gemfile="$SOURCE_DIR/Gemfile"
echo "" >> $TARGET_DIR/gemset.nix # Create trailing newline to please EditorConfig checks
echo "" >> "$TARGET_DIR/gemset.nix" # Create trailing newline to please EditorConfig checks