about summary refs log tree commit diff
path: root/pkgs/servers/mastodon
diff options
context:
space:
mode:
authorSandro Jäckel <sandro.jaeckel@gmail.com>2023-07-06 16:01:34 +0200
committerSandro Jäckel <sandro.jaeckel@gmail.com>2023-07-06 16:18:11 +0200
commit71a96bd985dcaa116a0c59f5f19f811b44461849 (patch)
tree61accc7f87bfd92f14ef0f4112a6f7ff7a1c574d /pkgs/servers/mastodon
parent73636cc3019b54b4aff77957efd651d3507118b5 (diff)
mastodon: simplify update script
Diffstat (limited to 'pkgs/servers/mastodon')
-rw-r--r--pkgs/servers/mastodon/default.nix3
-rw-r--r--pkgs/servers/mastodon/update.nix29
-rwxr-xr-xpkgs/servers/mastodon/update.sh23
3 files changed, 14 insertions, 41 deletions
diff --git a/pkgs/servers/mastodon/default.nix b/pkgs/servers/mastodon/default.nix
index 422b3e2be5c5b..1547485a03782 100644
--- a/pkgs/servers/mastodon/default.nix
+++ b/pkgs/servers/mastodon/default.nix
@@ -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; {
diff --git a/pkgs/servers/mastodon/update.nix b/pkgs/servers/mastodon/update.nix
deleted file mode 100644
index f9dc8db3980a1..0000000000000
--- a/pkgs/servers/mastodon/update.nix
+++ /dev/null
@@ -1,29 +0,0 @@
-{ 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}
-''
diff --git a/pkgs/servers/mastodon/update.sh b/pkgs/servers/mastodon/update.sh
index 7b4d97fd13972..e36072160dfe3 100755
--- a/pkgs/servers/mastodon/update.sh
+++ b/pkgs/servers/mastodon/update.sh
@@ -1,4 +1,5 @@
-#!/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