invidious: add update script

based on mpvScripts.sponsorblock's update script

schnusch d697ee65 970d249d

+89 -1
+5 -1
pkgs/servers/invidious/default.nix
··· 88 88 INVIDIOUS_CONFIG="database_url: sqlite3:///dev/null" $out/bin/invidious --help 89 89 ''; 90 90 91 - passthru.tests = { inherit (nixosTests) invidious; }; 91 + passthru = { 92 + inherit lsquic; 93 + tests = { inherit (nixosTests) invidious; }; 94 + updateScript = ./update.sh; 95 + }; 92 96 93 97 meta = with lib; { 94 98 description = "An open source alternative front-end to YouTube";
+84
pkgs/servers/invidious/update.sh
··· 1 + #!/usr/bin/env nix-shell 2 + #!nix-shell -i bash -p common-updater-scripts curl crystal2nix jq git gnused nix nix-prefetch-git nix-update 3 + git_url='https://github.com/iv-org/invidious.git' 4 + git_branch='master' 5 + git_dir='/var/tmp/invidious.git' 6 + nix_file="$(dirname "${BASH_SOURCE[0]}")/default.nix" 7 + pkg='invidious' 8 + 9 + set -euo pipefail 10 + 11 + info() { 12 + if [ -t 2 ]; then 13 + set -- '\033[32m%s\033[39m\n' "$@" 14 + else 15 + set -- '%s\n' "$@" 16 + fi 17 + printf "$@" >&2 18 + } 19 + 20 + old_rev=$(nix-instantiate --eval --strict --json -A "$pkg.src.rev" | jq -r) 21 + old_version=$(nix-instantiate --eval --strict --json -A "$pkg.version" | jq -r) 22 + today=$(LANG=C date -u +'%Y-%m-%d') 23 + 24 + info "fetching $git_url..." 25 + if [ ! -d "$git_dir" ]; then 26 + git init --initial-branch="$git_branch" "$git_dir" 27 + git -C "$git_dir" remote add origin "$git_url" 28 + fi 29 + git -C "$git_dir" fetch origin "$git_branch" 30 + 31 + # use latest commit before today, we should not call the version *today* 32 + # because there might still be commits coming 33 + # use the day of the latest commit we picked as version 34 + new_rev=$(git -C "$git_dir" log -n 1 --format='format:%H' --before="${today}T00:00:00Z" "origin/$git_branch") 35 + new_version="unstable-$(git -C "$git_dir" log -n 1 --format='format:%cs' "$new_rev")" 36 + info "latest commit before $today: $new_rev" 37 + 38 + if [ "$new_rev" = "$old_rev" ]; then 39 + info "$pkg is up-to-date." 40 + exit 41 + fi 42 + 43 + new_sha256=$(nix-prefetch-git --rev "$new_rev" "$git_dir" | jq -r .sha256) 44 + update-source-version "$pkg" \ 45 + "$new_version" \ 46 + "$new_sha256" \ 47 + --rev="$new_rev" 48 + git add "$nix_file" 49 + commit_msg="$pkg: $old_version -> $new_version" 50 + 51 + cd "${nix_file%/*}" 52 + if git -C "$git_dir" diff-tree --quiet "${old_rev}..${new_rev}" -- 'shard.lock'; then 53 + info "shard.lock did not change since $old_rev." 54 + else 55 + info "Updating shards.nix..." 56 + git -C "$git_dir" reset --hard "$new_rev" 57 + crystal2nix -- "$git_dir/shard.lock" # argv's index seems broken 58 + git add 'shards.nix' 59 + 60 + lsquic_old_version=$(nix-instantiate --eval --strict --json -A "${pkg}.lsquic.version" '../../..' | jq -r) 61 + lsquic_new_version=$(nix eval --raw -f 'shards.nix' lsquic.rev \ 62 + | sed -e 's/^v//' -e 's/-[0-9]*$//') 63 + if [ "$lsquic_old_version" != "$lsquic_new_version" ]; then 64 + info "Updating lsquic to $lsquic_new_version..." 65 + nix-update --version "$lsquic_new_version" -f '../../..' invidious.lsquic 66 + if git diff-index --quiet HEAD -- 'lsquic.nix'; then 67 + info "lsquic is up-to-date." 68 + else 69 + boringssl_new_version=$(curl -LSsf "https://github.com/litespeedtech/lsquic/raw/v${lsquic_new_version}/README.md" \ 70 + | grep -Pom1 '(?<=^git checkout ).*') 71 + boringssl_new_sha256=$(nix-prefetch-git --rev "$boringssl_new_version" 'https://boringssl.googlesource.com/boringssl' \ 72 + | jq -r .sha256) 73 + sed -e "0,/^ *version = .*/ s// version = \"$boringssl_new_version\";/" \ 74 + -e "0,/^ *sha256 = .*/ s// sha256 = \"$boringssl_new_sha256\";/" \ 75 + -i lsquic.nix 76 + git add 'lsquic.nix' 77 + commit_msg="$commit_msg 78 + 79 + lsquic: $lsquic_old_version -> $lsquic_new_version" 80 + fi 81 + fi 82 + fi 83 + 84 + git commit --verbose --message "$commit_msg"