dream2nix/lib/internal/fetchers/npm/default.nix

77 lines
1.6 KiB
Nix
Raw Normal View History

2022-10-06 20:42:04 +03:00
{
pkgs,
lib,
utils,
2023-05-19 11:48:24 +03:00
mkDerivation,
extractSource ?
import ../extractSource.nix {
2023-05-19 11:48:24 +03:00
inherit lib mkDerivation;
},
2022-10-06 20:42:04 +03:00
...
}: let
2021-12-09 08:54:22 +03:00
b = builtins;
in rec {
inputs = ["pname" "version"];
2021-12-09 08:54:22 +03:00
2021-11-01 09:48:23 +03:00
versionField = "version";
2021-12-09 08:54:22 +03:00
2021-12-09 11:47:08 +03:00
defaultUpdater = "npmNewestReleaseVersion";
2021-12-09 08:54:22 +03:00
# becuase some node packages contain submodules like `@hhhtj/draw.io`
# the amount of arguments can vary and a custom parser is needed
parseParams = params:
if b.length params == b.length inputs
then
2021-12-09 08:54:22 +03:00
lib.listToAttrs
(lib.forEach
(lib.range 0 ((lib.length inputs) - 1))
(
idx:
2021-12-09 08:54:22 +03:00
lib.nameValuePair
(lib.elemAt inputs idx)
(lib.elemAt params idx)
))
else if b.length params == (b.length inputs) + 1
then
parseParams [
"${b.elemAt params 0}/${b.elemAt params 1}"
(b.elemAt params 2)
]
else
throw ''
Wrong number of arguments provided in shortcut for fetcher 'npm'
Should be npm:${lib.concatStringsSep "/" inputs}
'';
2021-12-09 08:54:22 +03:00
2021-11-01 09:48:23 +03:00
# defaultUpdater = "";
outputs = {
pname,
version,
2022-10-06 20:42:04 +03:00
}: let
b = builtins;
2021-11-01 09:48:23 +03:00
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;}
2021-11-01 09:48:23 +03:00
);
fetched = hash: let
source =
2022-10-06 20:42:04 +03:00
(pkgs.fetchurl {
inherit url;
sha256 = hash;
})
.overrideAttrs (old: {
outputHashMode = "recursive";
});
in
extractSource {
inherit source;
};
};
2021-11-01 09:48:23 +03:00
}