diff --git a/src/modules/functions.updaters/default.nix b/src/modules/functions.updaters/default.nix new file mode 100644 index 00000000..e0a7730f --- /dev/null +++ b/src/modules/functions.updaters/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./implementation.nix + ./interface.nix + ]; +} diff --git a/src/updaters/default.nix b/src/modules/functions.updaters/implementation.nix similarity index 68% rename from src/updaters/default.nix rename to src/modules/functions.updaters/implementation.nix index 2323bfba..3a8fc8e9 100644 --- a/src/updaters/default.nix +++ b/src/modules/functions.updaters/implementation.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; + }; } diff --git a/src/modules/functions.updaters/interface.nix b/src/modules/functions.updaters/interface.nix new file mode 100644 index 00000000..b9d903eb --- /dev/null +++ b/src/modules/functions.updaters/interface.nix @@ -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; + }; + }; +} diff --git a/src/modules/top-level.nix b/src/modules/top-level.nix index de6e8dce..5d502173 100644 --- a/src/modules/top-level.nix +++ b/src/modules/top-level.nix @@ -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 ]; diff --git a/src/modules/updaters/default.nix b/src/modules/updaters/default.nix new file mode 100644 index 00000000..e0a7730f --- /dev/null +++ b/src/modules/updaters/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./implementation.nix + ./interface.nix + ]; +} diff --git a/src/modules/updaters/implementation.nix b/src/modules/updaters/implementation.nix new file mode 100644 index 00000000..aa41429a --- /dev/null +++ b/src/modules/updaters/implementation.nix @@ -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; + }; +} diff --git a/src/modules/updaters/interface.nix b/src/modules/updaters/interface.nix new file mode 100644 index 00000000..4d87d7dd --- /dev/null +++ b/src/modules/updaters/interface.nix @@ -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); + }; + }; +} diff --git a/src/updaters/githubNewestReleaseTag/default.nix b/src/updaters/githubNewestReleaseTag/default.nix new file mode 100644 index 00000000..67299ed5 --- /dev/null +++ b/src/updaters/githubNewestReleaseTag/default.nix @@ -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' +'' diff --git a/src/updaters/npmNewestReleaseVersion/default.nix b/src/updaters/npmNewestReleaseVersion/default.nix new file mode 100644 index 00000000..5edf83ae --- /dev/null +++ b/src/updaters/npmNewestReleaseVersion/default.nix @@ -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' +'' diff --git a/src/updaters/pypiNewestReleaseTag/default.nix b/src/updaters/pypiNewestReleaseTag/default.nix new file mode 100644 index 00000000..eb1bf9fc --- /dev/null +++ b/src/updaters/pypiNewestReleaseTag/default.nix @@ -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' +'' diff --git a/src/updaters/updaters.nix b/src/updaters/updaters.nix deleted file mode 100644 index bf446230..00000000 --- a/src/updaters/updaters.nix +++ /dev/null @@ -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[\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="")' - ''; -} diff --git a/src/updaters/urlRegexPython/default.nix b/src/updaters/urlRegexPython/default.nix new file mode 100644 index 00000000..4a0822fe --- /dev/null +++ b/src/updaters/urlRegexPython/default.nix @@ -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[\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="")' + ''