about summary refs log tree commit diff
path: root/pkgs/servers/mastodon
diff options
context:
space:
mode:
authorSandro <sandro.jaeckel@gmail.com>2023-07-22 01:14:07 +0200
committerGitHub <noreply@github.com>2023-07-22 01:14:07 +0200
commitc6d9dfa60bd7010401c3249354039bbf8b06019f (patch)
tree63b305556e4c4029ac05a2860120695a13ad8496 /pkgs/servers/mastodon
parentf8ad4849c3f80c0b4189c574edf2fb860867a05e (diff)
parent71a96bd985dcaa116a0c59f5f19f811b44461849 (diff)
Merge pull request #241937 from SuperSandro2000/mastodon-update-script
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 74a1ce129ab40..4a7e6e1787307 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";
     hash = "$HASH";
   };
@@ -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