add finders for finding new package versions

This commit is contained in:
DavHau 2021-10-03 23:34:33 +07:00
parent 9adf141700
commit 66c1ce3c0d
3 changed files with 81 additions and 2 deletions

View File

@ -41,10 +41,12 @@ let
inherit (config) allowBuiltinFetchers;
};
# updater modules to find newest package versions
finders = callPackageDream ./finders {};
# the translator modules and utils for all subsystems
translators = callPackageDream ./translators {};
# the location of the dream2nix framework for self references (update scripts, etc.)
location = ./.;
@ -52,7 +54,7 @@ in
rec {
inherit apps builders fetchers location translators;
inherit apps builders fetchers finders location translators;
# automatically find a suitable builder for a given generic lock
findBuilder = dreamLock:

64
src/finders/default.nix Normal file
View File

@ -0,0 +1,64 @@
{
curl,
gnugrep,
jq,
lib,
python3,
writeText,
# dream2nix inputs
utils,
...
}:
{
githubNewestReleaseTag =
{
owner,
repo,
...
}:
utils.writePureShellScript [ curl jq ] ''
curl -s "https://api.github.com/repos/${owner}/${repo}/releases?per_page=1" | jq -r '.[0].tag_name'
'';
pypiNewestReleaseVersion =
{
pname,
...
}:
utils.writePureShellScript [ curl jq ] ''
curl -s https://pypi.org/pypi/${pname}/json | jq -r '.info.version'
'';
npmNewestReleaseVersion =
{
pname,
...
}:
# api docs: https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#get
utils.writePureShellScript [ curl jq ] ''
curl -s https://registry.npmjs.com/${pname} | jq -r '."dist-tags".latest'
'';
urlRegexPython =
# Don't forget to use double quoted strings
# or double escape ('\\' instead of '\').
# Expects named group 'rev' to be defined.
# Example regex:
# ''[Pp]ython-(?P<ver>[\d\.]+)\.tgz''
{
url,
regex,
...
}:
let
reFile = writeText "regex" regex;
in
utils.writePureShellScript [ curl gnugrep python3 ] ''
curl -s ${url} \
| python3 -c \
'import re, sys; print(re.search(open("${reFile}").read(), sys.stdin.read()).group("ver"), end="")'
'';
}

View File

@ -1,7 +1,9 @@
{
coreutils,
lib,
nix,
runCommand,
writeScriptBin,
...
}:
let
@ -60,4 +62,15 @@ rec {
in
b.readFile hashFile;
writePureShellScript = availablePrograms: script: writeScriptBin "run" ''
export PATH="${lib.makeBinPath availablePrograms}"
tmpdir=$(${coreutils}/bin/mktemp -d)
cd $tmpdir
${script}
cd
${coreutils}/bin/rm -rf $tmpdir
'';
}