tangled
alpha
login
or
join now
tjh.dev
/
nixpkgs
Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
0
fork
atom
overview
issues
pulls
pipelines
mastodon: simplify update script
Sandro Jäckel
2 years ago
71a96bd9
73636cc3
+14
-41
3 changed files
expand all
collapse all
unified
split
pkgs
servers
mastodon
default.nix
update.nix
update.sh
+2
-1
pkgs/servers/mastodon/default.nix
···
156
156
157
157
passthru = {
158
158
tests.mastodon = nixosTests.mastodon;
159
159
-
updateScript = callPackage ./update.nix {};
159
159
+
# run with: nix-shell ./maintainers/scripts/update.nix --argstr package mastodon
160
160
+
updateScript = ./update.sh;
160
161
};
161
162
162
163
meta = with lib; {
-29
pkgs/servers/mastodon/update.nix
···
1
1
-
{ runCommand
2
2
-
, lib
3
3
-
, makeWrapper
4
4
-
, yarn2nix
5
5
-
, bundix
6
6
-
, coreutils
7
7
-
, diffutils
8
8
-
, nix-prefetch-github
9
9
-
, gnused
10
10
-
, jq
11
11
-
}:
12
12
-
let
13
13
-
binPath = lib.makeBinPath [ yarn2nix bundix coreutils diffutils nix-prefetch-github gnused jq ];
14
14
-
in
15
15
-
runCommand "mastodon-update-script"
16
16
-
{
17
17
-
nativeBuildInputs = [ makeWrapper ];
18
18
-
19
19
-
meta = {
20
20
-
maintainers = with lib.maintainers; [ happy-river ];
21
21
-
description = "Utility to generate Nix expressions for Mastodon's dependencies";
22
22
-
platforms = lib.platforms.unix;
23
23
-
};
24
24
-
} ''
25
25
-
mkdir -p $out/bin
26
26
-
cp ${./update.sh} $out/bin/update.sh
27
27
-
patchShebangs $out/bin/update.sh
28
28
-
wrapProgram $out/bin/update.sh --prefix PATH : ${binPath}
29
29
-
''
+12
-11
pkgs/servers/mastodon/update.sh
···
1
1
-
#!/usr/bin/env bash
1
1
+
#!/usr/bin/env nix-shell
2
2
+
#! nix-shell -i bash -p yarn2nix bundix coreutils diffutils nix-prefetch-github gnused jq
2
3
set -e
3
4
4
5
OWNER=mastodon
···
41
42
esac
42
43
done
43
44
44
44
-
if [[ -z "$VERSION" || -n "$POSITIONAL" ]]; then
45
45
-
echo "Usage: update.sh [--owner OWNER] [--repo REPO] --ver VERSION [--rev REVISION] [--patches PATCHES]"
46
46
-
echo "OWNER and repo must be paths on github."
47
47
-
echo "If VERSION is not a revision acceptable to 'git checkout', you must provide one in REVISION."
45
45
+
if [[ -n "$POSITIONAL" ]]; then
46
46
+
echo "Usage: update.sh [--owner OWNER] [--repo REPO] [--ver VERSION] [--rev REVISION] [--patches PATCHES]"
47
47
+
echo "OWNER and REPO must be paths on github."
48
48
+
echo "If REVISION is not provided, the latest tag from github.com/mastodon/mastodon is fetched and VERSION is calculated from it."
48
49
echo "If OWNER and REPO are not provided, it defaults they default to mastodon and mastodon."
49
50
echo "PATCHES, if provided, should be one or more Nix expressions separated by spaces."
50
51
exit 1
51
52
fi
52
53
53
54
if [[ -z "$REVISION" ]]; then
54
54
-
REVISION="$VERSION"
55
55
+
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')"
56
56
+
VERSION="$(echo "$REVISION" | cut -c2-)"
55
57
fi
56
58
57
59
rm -f gemset.nix version.nix source.nix
58
58
-
TARGET_DIR="$PWD"
59
59
-
60
60
+
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
60
61
61
62
WORK_DIR=$(mktemp -d)
62
63
···
85
86
# This file was generated by pkgs.mastodon.updateScript.
86
87
{ fetchFromGitHub, applyPatches }: let
87
88
src = fetchFromGitHub {
88
88
-
owner = "mastodon";
89
89
-
repo = "mastodon";
89
89
+
owner = "$OWNER";
90
90
+
repo = "$REPO";
90
91
rev = "$REVISION";
91
92
sha256 = "$SHA";
92
93
};
···
99
100
100
101
echo "Creating gemset.nix"
101
102
bundix --lockfile="$SOURCE_DIR/Gemfile.lock" --gemfile="$SOURCE_DIR/Gemfile"
102
102
-
echo "" >> "$TARGET_DIR/gemset.nix" # Create trailing newline to please EditorConfig checks
103
103
+
echo "" >> gemset.nix # Create trailing newline to please EditorConfig checks