Unverified Commit 71a96bd9 authored by Sandro Jäckel's avatar Sandro Jäckel
Browse files

mastodon: simplify update script

parent 73636cc3
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -156,7 +156,8 @@ stdenv.mkDerivation rec {

  passthru = {
    tests.mastodon = nixosTests.mastodon;
    updateScript = callPackage ./update.nix {};
    # run with: nix-shell ./maintainers/scripts/update.nix --argstr package mastodon
    updateScript = ./update.sh;
  };

  meta = with lib; {

pkgs/servers/mastodon/update.nix

deleted100644 → 0
+0 −29
Original line number Diff line number Diff line
{ runCommand
, lib
, makeWrapper
, yarn2nix
, bundix
, coreutils
, diffutils
, nix-prefetch-github
, gnused
, jq
}:
let
  binPath = lib.makeBinPath [ yarn2nix bundix coreutils diffutils nix-prefetch-github gnused jq ];
in
runCommand "mastodon-update-script"
{
  nativeBuildInputs = [ makeWrapper ];

  meta = {
    maintainers = with lib.maintainers; [ happy-river ];
    description = "Utility to generate Nix expressions for Mastodon's dependencies";
    platforms = lib.platforms.unix;
  };
} ''
  mkdir -p $out/bin
  cp ${./update.sh} $out/bin/update.sh
  patchShebangs $out/bin/update.sh
  wrapProgram $out/bin/update.sh --prefix PATH : ${binPath}
''
+12 −11
Original line number Diff line number Diff line
#!/usr/bin/env bash
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p yarn2nix bundix coreutils diffutils nix-prefetch-github gnused jq
set -e

OWNER=mastodon
@@ -41,22 +42,22 @@ while [[ $# -gt 0 ]]; do
    esac
done

if [[ -z "$VERSION" || -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 VERSION is not a revision acceptable to 'git checkout', you must provide one in REVISION."
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

if [[ -z "$REVISION" ]]; then
    REVISION="$VERSION"
    REVISION="$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} -s "https://api.github.com/repos/$OWNER/$REPO/releases" | jq -r  'map(select(.prerelease == false)) | .[0].tag_name')"
    VERSION="$(echo "$REVISION" | cut -c2-)"
fi

rm -f gemset.nix version.nix source.nix
TARGET_DIR="$PWD"

cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1

WORK_DIR=$(mktemp -d)

@@ -85,8 +86,8 @@ cat > source.nix << EOF
# This file was generated by pkgs.mastodon.updateScript.
{ fetchFromGitHub, applyPatches }: let
  src = fetchFromGitHub {
    owner = "mastodon";
    repo = "mastodon";
    owner = "$OWNER";
    repo = "$REPO";
    rev = "$REVISION";
    sha256 = "$SHA";
  };
@@ -99,4 +100,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 "" >> gemset.nix  # Create trailing newline to please EditorConfig checks