feat(pkgs): add nix-modrinth-prefetch

This commit is contained in:
Infinidoge 2022-08-29 01:20:49 -04:00
parent 1ac9b8179d
commit e355a3341f
2 changed files with 15 additions and 0 deletions

View file

@ -0,0 +1,13 @@
{ runtimeShell, writeShellScriptBin, curl, jq, gnused }:
writeShellScriptBin "nix-modrinth-prefetch" ''
input=$(${curl}/bin/curl --no-progress-meter https://api.modrinth.com/v2/version/$1)
if [[ $input == "" ]]; then
echo "Invalid version"
exit 1
fi
echo $input \
| ${jq}/bin/jq -c '.files | (.[] | select(.primary == true)) // .[0] | {url: .url, sha512: .hashes.sha512}' \
| ${gnused}/bin/sed 's/{"url":"\(.\+\)","sha512":"\(.\+\)"}/fetchurl { url = "\1"; sha512 = "\2"; }/'
''