From e17666dd16212e307289b45e788b281eab8dd22e Mon Sep 17 00:00:00 2001 From: natsukium Date: Sun, 11 May 2025 14:43:32 +0900 Subject: [PATCH] sudachidict: add updateScript --- pkgs/by-name/su/sudachidict/package.nix | 1 + pkgs/by-name/su/sudachidict/update.sh | 27 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 pkgs/by-name/su/sudachidict/update.sh diff --git a/pkgs/by-name/su/sudachidict/package.nix b/pkgs/by-name/su/sudachidict/package.nix index 8a885001a346..ccd670e522c2 100644 --- a/pkgs/by-name/su/sudachidict/package.nix +++ b/pkgs/by-name/su/sudachidict/package.nix @@ -47,6 +47,7 @@ lib.checkListOfEnum "${pname}: dict-type" [ "core" "full" "small" ] [ dict-type passthru = { dict-type = dict-type; + updateScript = ./update.sh; }; meta = { diff --git a/pkgs/by-name/su/sudachidict/update.sh b/pkgs/by-name/su/sudachidict/update.sh new file mode 100755 index 000000000000..4d89a50c00c1 --- /dev/null +++ b/pkgs/by-name/su/sudachidict/update.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl jq nix-update + +set -euo pipefail + +pushd "$(dirname "$0")" >/dev/null + +ORG="WorksApplications" +REPO="SudachiDict" +VERSION="$(curl -s "https://api.github.com/repos/$ORG/$REPO/releases/latest" | jq -r '.tag_name' | sed 's/^v//')" + +sed -i "s/version = \"[0-9]*\";/version = \"$VERSION\";/" package.nix + +DICT_TYPES=("core" "small" "full") + +for TYPE in "${DICT_TYPES[@]}"; do + URL="https://github.com/$ORG/$REPO/releases/download/v$VERSION/sudachi-dictionary-$VERSION-$TYPE.zip" + + PLAIN_HASH=$(nix-prefetch-url --type sha256 "$URL" --unpack) + HASH=$(nix hash convert --hash-algo sha256 --to sri "$PLAIN_HASH") + + sed -i -E "/(${TYPE} = fetchzip \{|^ *url = .*${TYPE}\.zip\";\$)/,/^ *hash = / s|hash = \"[^\"]*\"|hash = \"$HASH\"|" package.nix +done + +popd >/dev/null + +nix-update "python3Packages.sudachidict-core" --version=skip