firefox-extensions: fix the damn uBlock update script

This commit is contained in:
2025-03-21 04:09:40 +00:00
parent 8bf9dec92f
commit 687141ee1f
2 changed files with 68 additions and 3 deletions

View File

@@ -0,0 +1,53 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash -p common-updater-scripts -p coreutils -p curl
NEWLINE=$'\n'
numeric_version() {
# TODO: consider `b<n>` or `rc<n>` suffixes?
echo "$1" | egrep --only-matching "[0-9.]+" | head -n1
}
sort_versions() {
local lines=
for v in $1; do
local n=$(numeric_version "$v")
lines="$lines$n $v$NEWLINE"
done
echo "$lines" | sort --version-sort --reverse | cut -d" " -f 2
}
set -ex
url="$1"
MAX_VERSIONS=${MAX_VERSIONS:-10}
# check that caller supplied all arguments
test -n "$url"
test -n "$UPDATE_NIX_OLD_VERSION"
# we need the bare git URL.
# strip `https://github.com/OWNER/NAME/releases/download/...` -> `https://github.com/OWNER/NAME`
repo_url="${url/\/releases*/}"
set +x
all_versions=$(list-git-tags --url="$repo_url")
all_versions=$(sort_versions "$all_versions")
# filter to the versions for which we can actually download an artifact.
# some packages (uBlock) publish releases even before all artifacts are available.
versions=()
for v in $all_versions; do
test_url=''${url//$UPDATE_NIX_OLD_VERSION/$v}
if $(set -x; curl --fail "$test_url"); then
versions+=("$v")
fi
if [[ ${#versions[@]} -ge $MAX_VERSIONS ]]; then
# if we have a bunch of versions already, then exit now instead of crawling through hundreds more tags we're just going to throw away.
break
fi
done
set -x
echo "${versions[*]}"

View File

@@ -2,18 +2,27 @@
callPackage, callPackage,
concatTextFile, concatTextFile,
fetchurl, fetchurl,
genericUpdater,
jq, jq,
lib, lib,
newScope, newScope,
nix-update-script, nix-update-script,
runCommand, runCommand,
static-nix-shell,
stdenv, stdenv,
strip-nondeterminism, strip-nondeterminism,
unzip, unzip,
writers, writers,
writeShellScript,
zip, zip,
}: }:
let let
addon-version-lister = static-nix-shell.mkBash {
pname = "addon-version-lister";
pkgs = [ "common-updater-scripts" "coreutils" "curl" ];
srcRoot = ./.;
};
wrapAddon = addon: args: wrapAddon = addon: args:
let let
extid = addon.passthru.extid; extid = addon.passthru.extid;
@@ -107,14 +116,17 @@ let
cp $src $out cp $src $out
''; '';
passthru.updateScript = nix-update-script { passthru.updateScript = genericUpdater {
# ignore beta versions versionLister = writeShellScript "${pname}-version-lister" ''
extraArgs = [ "--version-regex" "([0-9.]+)$" ]; ${lib.getExe addon-version-lister} ${url}
'';
}; };
passthru.extid = extid; passthru.extid = extid;
}; };
firefox-extensions = (lib.makeScope newScope (self: with self; { firefox-extensions = (lib.makeScope newScope (self: with self; {
inherit addon-version-lister;
unwrapped = lib.recurseIntoAttrs { unwrapped = lib.recurseIntoAttrs {
# get names from: # get names from:
# - ~/ref/nix-community/nur-combined/repos/rycee/pkgs/firefox-addons/generated-firefox-addons.nix # - ~/ref/nix-community/nur-combined/repos/rycee/pkgs/firefox-addons/generated-firefox-addons.nix