mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-27 16:33:05 +03:00
refactor: move updaters to use modules
This commit is contained in:
parent
f44016a2d4
commit
3d400cc706
6
src/modules/functions.updaters/default.nix
Normal file
6
src/modules/functions.updaters/default.nix
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
imports = [
|
||||
./implementation.nix
|
||||
./interface.nix
|
||||
];
|
||||
}
|
@ -1,21 +1,8 @@
|
||||
{
|
||||
curl,
|
||||
gnugrep,
|
||||
jq,
|
||||
lib,
|
||||
python3,
|
||||
writeText,
|
||||
# dream2nix inputs
|
||||
callPackageDream,
|
||||
framework,
|
||||
...
|
||||
}: let
|
||||
inherit (framework) utils fetchers;
|
||||
{config, ...}: let
|
||||
inherit (config) utils fetchers updaters;
|
||||
|
||||
lockUtils = utils.dream-lock;
|
||||
|
||||
updaters = callPackageDream ./updaters.nix {};
|
||||
|
||||
getUpdaterName = {dreamLock}: let
|
||||
lock = (utils.dream-lock.readDreamLock {inherit dreamLock;}).lock;
|
||||
source = lockUtils.getMainPackageSource lock;
|
||||
@ -34,5 +21,7 @@
|
||||
in
|
||||
updater' source;
|
||||
in {
|
||||
inherit getUpdaterName makeUpdateScript updaters;
|
||||
config.functions.updaters = {
|
||||
inherit getUpdaterName makeUpdateScript;
|
||||
};
|
||||
}
|
14
src/modules/functions.updaters/interface.nix
Normal file
14
src/modules/functions.updaters/interface.nix
Normal file
@ -0,0 +1,14 @@
|
||||
{config, ...}: let
|
||||
inherit (config.dlib) mkFunction;
|
||||
l = config.lib // builtins;
|
||||
t = l.types;
|
||||
in {
|
||||
options.functions.updaters = {
|
||||
getUpdaterName = mkFunction {
|
||||
type = t.either t.str t.null;
|
||||
};
|
||||
makeUpdateScript = mkFunction {
|
||||
type = t.path;
|
||||
};
|
||||
};
|
||||
}
|
@ -45,6 +45,7 @@ in {
|
||||
./functions.default-fetcher
|
||||
./functions.combined-fetcher
|
||||
./functions.translators
|
||||
./functions.updaters
|
||||
./apps
|
||||
./builders
|
||||
./discoverers
|
||||
@ -62,6 +63,7 @@ in {
|
||||
./dlib.parsing
|
||||
./dlib.construct
|
||||
./dlib.simpleTranslate2
|
||||
./updaters
|
||||
./externals
|
||||
./dream2nix-interface
|
||||
];
|
||||
|
6
src/modules/updaters/default.nix
Normal file
6
src/modules/updaters/default.nix
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
imports = [
|
||||
./implementation.nix
|
||||
./interface.nix
|
||||
];
|
||||
}
|
17
src/modules/updaters/implementation.nix
Normal file
17
src/modules/updaters/implementation.nix
Normal file
@ -0,0 +1,17 @@
|
||||
{config, ...}: let
|
||||
l = config.lib // builtins;
|
||||
updatersDir = ../../updaters;
|
||||
updaterNames = l.attrNames (
|
||||
l.filterAttrs
|
||||
(_: type: type == "directory")
|
||||
(l.readDir updatersDir)
|
||||
);
|
||||
updaterModules =
|
||||
l.genAttrs
|
||||
updaterNames
|
||||
(name: import "${updatersDir}/${name}" config);
|
||||
in {
|
||||
config = {
|
||||
updaters = updaterModules;
|
||||
};
|
||||
}
|
10
src/modules/updaters/interface.nix
Normal file
10
src/modules/updaters/interface.nix
Normal file
@ -0,0 +1,10 @@
|
||||
{config, ...}: let
|
||||
l = config.lib // builtins;
|
||||
t = l.types;
|
||||
in {
|
||||
options = {
|
||||
updaters = l.mkOption {
|
||||
type = t.lazyAttrsOf (t.functionTo t.path);
|
||||
};
|
||||
};
|
||||
}
|
12
src/updaters/githubNewestReleaseTag/default.nix
Normal file
12
src/updaters/githubNewestReleaseTag/default.nix
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
pkgs,
|
||||
utils,
|
||||
...
|
||||
}: {
|
||||
owner,
|
||||
repo,
|
||||
...
|
||||
}:
|
||||
utils.writePureShellScript (with pkgs; [curl jq]) ''
|
||||
curl -s "https://api.github.com/repos/${owner}/${repo}/releases?per_page=1" | jq -r '.[0].tag_name'
|
||||
''
|
9
src/updaters/npmNewestReleaseVersion/default.nix
Normal file
9
src/updaters/npmNewestReleaseVersion/default.nix
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
pkgs,
|
||||
utils,
|
||||
...
|
||||
}: {pname, ...}:
|
||||
# api docs: https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#get
|
||||
utils.writePureShellScript (with pkgs; [curl jq]) ''
|
||||
curl -s https://registry.npmjs.com/${pname} | jq -r '."dist-tags".latest'
|
||||
''
|
8
src/updaters/pypiNewestReleaseTag/default.nix
Normal file
8
src/updaters/pypiNewestReleaseTag/default.nix
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
pkgs,
|
||||
utils,
|
||||
...
|
||||
}: {pname, ...}:
|
||||
utils.writePureShellScript (with pkgs; [curl jq]) ''
|
||||
curl -s https://pypi.org/pypi/${pname}/json | jq -r '.info.version'
|
||||
''
|
@ -1,50 +0,0 @@
|
||||
{
|
||||
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="")'
|
||||
'';
|
||||
}
|
22
src/updaters/urlRegexPython/default.nix
Normal file
22
src/updaters/urlRegexPython/default.nix
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
pkgs,
|
||||
utils,
|
||||
...
|
||||
}:
|
||||
# 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 = pkgs.writeText "regex" regex;
|
||||
in
|
||||
utils.writePureShellScript (with pkgs; [curl gnugrep python3]) ''
|
||||
curl -s ${url} \
|
||||
| python3 -c \
|
||||
'import re, sys; print(re.search(open("${reFile}").read(), sys.stdin.read()).group("ver"), end="")'
|
||||
''
|
Loading…
Reference in New Issue
Block a user