Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alist: add update.nix #358335

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkgs/by-name/al/alist/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
stdenv,
installShellFiles,
versionCheckHook,
callPackage,
}:
buildGoModule rec {
pname = "alist";
Expand Down Expand Up @@ -88,6 +89,10 @@ buildGoModule rec {
versionCheckHook
];

passthru = {
updateScript = lib.getExe (callPackage ./update.nix { });
};

meta = {
description = "File list/WebDAV program that supports multiple storages";
homepage = "https://github.com/alist-org/alist";
Expand Down
52 changes: 52 additions & 0 deletions pkgs/by-name/al/alist/update.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
writeShellApplication,
nix,
nix-update,
curl,
jq,
common-updater-scripts,
}:

writeShellApplication {
name = "update-alist";
runtimeInputs = [
curl
jq
nix
common-updater-scripts
nix-update
];

text = ''
# get old info
NIXPKGS="$(pwd)"
PKG_PATH="$NIXPKGS"/pkgs/by-name/al/alist
oldVersion=$(nix-instantiate --eval --strict -A "alist.version" | jq -e -r)
oldVendorHash=$(nix-instantiate --eval --strict -A "alist.vendorHash" | jq -e -r )

get_latest_release() {
local repo=$1
curl --fail ''${GITHUB_TOKEN:+ -H "Authorization: bearer $GITHUB_TOKEN"} \
-s "https://api.github.com/repos/AlistGo/$repo/releases/latest" | jq -r ".tag_name"
}

version=$(get_latest_release "alist")
version="''${version#v}"
webVersion=$(get_latest_release "alist-web")

if [[ "$oldVersion" == "$version" ]]; then
echo "Already up to date!"
exit 0
fi

# TODO: Switch to nix-update after https://github.com/Mic92/nix-update/pull/296
update-source-version alist "$version" --source-key=src --version-key=version
vendorHash=$(nix-build --expr 'let src = (import '"$NIXPKGS"' (if (builtins.hasAttr "config" (builtins.functionArgs (import '"$NIXPKGS"'))) then { config.checkMeta = false; overlays = []; } else { }))."alist".goModules; in (src.overrideAttrs or (f: src // f src)) (_: { outputHash = ""; outputHashAlgo = "sha256"; })' --no-link 2>&1 >/dev/null | tail -n3 | grep -F got: | cut -d: -f2- | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')

if [[ "$oldVendorHash" != "$vendorHash" ]]; then
sed -i "s|$oldVendorHash|$vendorHash|" "$PKG_PATH"/package.nix
fi

update-source-version alist "$webVersion" --source-key=web --version-key=webVersion
Moraxyc marked this conversation as resolved.
Show resolved Hide resolved
'';
}
Loading