add npm fetcher

This commit is contained in:
DavHau 2021-11-01 13:48:23 +07:00
parent 03ef2e4c7a
commit 5a00d557b9
2 changed files with 54 additions and 23 deletions

View File

@ -0,0 +1,41 @@
{
fetchurl,
lib,
python3,
utils,
...
}:
{
inputs = [
"pname"
"version"
];
versionField = "version";
# defaultUpdater = "";
outputs = { pname, version, ... }@inp:
let
b = builtins;
submodule = lib.last (lib.splitString "/" pname);
url = "https://registry.npmjs.org/${pname}/-/${submodule}-${version}.tgz";
in
{
calcHash = algo: utils.hashPath algo (
b.fetchurl { inherit url; }
);
fetched = hash:
(fetchurl {
inherit url;
sha256 = hash;
}).overrideAttrs (old: {
outputHashMode = "recursive";
});
};
}

View File

@ -1,5 +1,5 @@
{
http,
fetchurl,
python3,
utils,
@ -19,34 +19,24 @@
outputs = { pname, version, extension ? "tar.gz", ... }@inp:
let
b = builtins;
firstChar = builtins.substring 0 1 pname;
url =
"https://files.pythonhosted.org/packages/source/"
+ "${firstChar}/${pname}/${pname}-${version}.${extension}";
in
{
calcHash = algo: utils.hashPath algo (
let
firstChar = builtins.substring 0 1 pname;
result = b.http {
url =
"https://files.pythonhosted.org/packages/source/"
+ "${firstChar}/${pname}/${pname}-${version}.${extension}";
};
in
result
b.fetchurl { inherit url; }
);
fetched = hash:
let
firstChar = builtins.substring 0 1 pname;
result = (http {
url =
"https://files.pythonhosted.org/packages/source/"
+ "${firstChar}/${pname}/${pname}-${version}.${extension}";
(fetchurl {
inherit url;
sha256 = hash;
}).overrideAttrs (old: {
outputHashMode = "recursive";
});
in
result;
};
}