2021-10-28 06:52:43 +00:00
|
|
|
{ stdenv, lib, makeWrapper, coreutils, nix-prefetch-git, fetchurl, nodejs-slim, prefetch-yarn-deps, cacert, callPackage, nix }:
|
2021-10-17 09:34:42 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
yarnpkg-lockfile-tar = fetchurl {
|
|
|
|
url = "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz";
|
2023-10-09 19:29:22 +00:00
|
|
|
hash = "sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==";
|
2021-10-17 09:34:42 +00:00
|
|
|
};
|
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
tests = callPackage ./tests {};
|
|
|
|
|
2021-10-17 09:34:42 +00:00
|
|
|
in {
|
|
|
|
prefetch-yarn-deps = stdenv.mkDerivation {
|
|
|
|
name = "prefetch-yarn-deps";
|
|
|
|
|
|
|
|
dontUnpack = true;
|
|
|
|
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2021-10-28 06:52:43 +00:00
|
|
|
buildInputs = [ coreutils nix-prefetch-git nodejs-slim nix ];
|
2021-10-17 09:34:42 +00:00
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
mkdir libexec
|
|
|
|
tar --strip-components=1 -xf ${yarnpkg-lockfile-tar} package/index.js
|
|
|
|
mv index.js libexec/yarnpkg-lockfile.js
|
2023-07-15 17:15:38 +00:00
|
|
|
cp ${./.}/*.js libexec/
|
|
|
|
patchShebangs libexec
|
2021-10-17 09:34:42 +00:00
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
mkdir -p $out/bin
|
|
|
|
cp -r libexec $out
|
|
|
|
makeWrapper $out/libexec/index.js $out/bin/prefetch-yarn-deps \
|
2021-10-28 06:52:43 +00:00
|
|
|
--prefix PATH : ${lib.makeBinPath [ coreutils nix-prefetch-git nix ]}
|
2023-07-15 17:15:38 +00:00
|
|
|
makeWrapper $out/libexec/fixup.js $out/bin/fixup-yarn-lock
|
2021-10-17 09:34:42 +00:00
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
2023-08-04 22:07:22 +00:00
|
|
|
|
|
|
|
passthru = { inherit tests; };
|
2021-10-17 09:34:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
fetchYarnDeps = let
|
|
|
|
f = {
|
|
|
|
name ? "offline",
|
2022-10-06 18:32:54 +00:00
|
|
|
src ? null,
|
2021-10-17 09:34:42 +00:00
|
|
|
hash ? "",
|
|
|
|
sha256 ? "",
|
2022-10-06 18:32:54 +00:00
|
|
|
...
|
|
|
|
}@args: let
|
2021-10-17 09:34:42 +00:00
|
|
|
hash_ =
|
|
|
|
if hash != "" then { outputHashAlgo = null; outputHash = hash; }
|
|
|
|
else if sha256 != "" then { outputHashAlgo = "sha256"; outputHash = sha256; }
|
2021-12-06 16:07:01 +00:00
|
|
|
else { outputHashAlgo = "sha256"; outputHash = lib.fakeSha256; };
|
2022-10-06 18:32:54 +00:00
|
|
|
in stdenv.mkDerivation ({
|
2021-10-17 09:34:42 +00:00
|
|
|
inherit name;
|
|
|
|
|
2022-10-06 18:32:54 +00:00
|
|
|
dontUnpack = src == null;
|
2021-10-17 09:34:42 +00:00
|
|
|
dontInstall = true;
|
|
|
|
|
|
|
|
nativeBuildInputs = [ prefetch-yarn-deps ];
|
|
|
|
GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
|
|
|
|
|
|
|
|
buildPhase = ''
|
2022-10-06 18:32:54 +00:00
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
yarnLock=''${yarnLock:=$PWD/yarn.lock}
|
2021-10-17 09:34:42 +00:00
|
|
|
mkdir -p $out
|
2022-10-06 18:32:54 +00:00
|
|
|
(cd $out; prefetch-yarn-deps --verbose --builder $yarnLock)
|
|
|
|
|
|
|
|
runHook postBuild
|
2021-10-17 09:34:42 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
outputHashMode = "recursive";
|
2022-10-06 18:32:54 +00:00
|
|
|
} // hash_ // (removeAttrs args ["src" "name" "hash" "sha256"]));
|
2021-10-17 09:34:42 +00:00
|
|
|
|
|
|
|
in lib.setFunctionArgs f (lib.functionArgs f) // {
|
2023-08-04 22:07:22 +00:00
|
|
|
inherit tests;
|
2021-10-17 09:34:42 +00:00
|
|
|
};
|
|
|
|
}
|