2024-07-03 06:27:59 +00:00
|
|
|
{
|
|
|
|
stdenv,
|
|
|
|
lib,
|
|
|
|
makeWrapper,
|
2024-07-19 15:41:58 +00:00
|
|
|
installShellFiles,
|
|
|
|
nodejsInstallManuals,
|
|
|
|
nodejsInstallExecutables,
|
2024-07-03 06:27:59 +00:00
|
|
|
coreutils,
|
|
|
|
nix-prefetch-git,
|
|
|
|
fetchurl,
|
2024-07-19 15:41:58 +00:00
|
|
|
jq,
|
|
|
|
nodejs,
|
2024-07-03 06:27:59 +00:00
|
|
|
nodejs-slim,
|
|
|
|
prefetch-yarn-deps,
|
2024-06-07 13:18:21 +00:00
|
|
|
fixup-yarn-lock,
|
|
|
|
yarn,
|
|
|
|
makeSetupHook,
|
2024-07-03 06:27:59 +00:00
|
|
|
cacert,
|
|
|
|
callPackage,
|
|
|
|
nix,
|
|
|
|
}:
|
2021-10-06 02:52:35 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
yarnpkg-lockfile-tar = fetchurl {
|
|
|
|
url = "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz";
|
2023-09-16 17:33:20 +00:00
|
|
|
hash = "sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==";
|
2021-10-06 02:52:35 +00:00
|
|
|
};
|
|
|
|
|
2024-07-03 06:27:59 +00:00
|
|
|
tests = callPackage ./tests { };
|
|
|
|
in
|
|
|
|
{
|
2021-10-06 02:52:35 +00:00
|
|
|
prefetch-yarn-deps = stdenv.mkDerivation {
|
|
|
|
name = "prefetch-yarn-deps";
|
|
|
|
|
|
|
|
dontUnpack = true;
|
2024-01-18 22:53:33 +00:00
|
|
|
dontBuild = true;
|
2021-10-06 02:52:35 +00:00
|
|
|
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2024-01-18 22:53:33 +00:00
|
|
|
buildInputs = [ nodejs-slim ];
|
2021-10-06 02:52:35 +00:00
|
|
|
|
2024-01-18 22:53:33 +00:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
mkdir -p $out/bin $out/libexec
|
2021-10-06 02:52:35 +00:00
|
|
|
|
|
|
|
tar --strip-components=1 -xf ${yarnpkg-lockfile-tar} package/index.js
|
2024-01-18 22:53:33 +00:00
|
|
|
mv index.js $out/libexec/yarnpkg-lockfile.js
|
2024-06-14 15:34:37 +00:00
|
|
|
cp ${./common.js} $out/libexec/common.js
|
|
|
|
cp ${./index.js} $out/libexec/index.js
|
2024-01-18 22:53:33 +00:00
|
|
|
|
|
|
|
patchShebangs $out/libexec
|
|
|
|
makeWrapper $out/libexec/index.js $out/bin/prefetch-yarn-deps \
|
2024-07-03 06:27:59 +00:00
|
|
|
--prefix PATH : ${
|
|
|
|
lib.makeBinPath [
|
|
|
|
coreutils
|
|
|
|
nix-prefetch-git
|
|
|
|
nix
|
|
|
|
]
|
|
|
|
}
|
2021-10-06 02:52:35 +00:00
|
|
|
|
2024-01-18 22:53:33 +00:00
|
|
|
runHook postInstall
|
2021-10-06 02:52:35 +00:00
|
|
|
'';
|
|
|
|
|
2024-07-03 06:27:59 +00:00
|
|
|
passthru = {
|
|
|
|
inherit tests;
|
|
|
|
};
|
2024-01-18 22:53:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
fixup-yarn-lock = stdenv.mkDerivation {
|
|
|
|
name = "fixup-yarn-lock";
|
|
|
|
|
|
|
|
dontUnpack = true;
|
|
|
|
dontBuild = true;
|
|
|
|
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
buildInputs = [ nodejs-slim ];
|
|
|
|
|
2021-10-06 02:52:35 +00:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
2024-01-18 22:53:33 +00:00
|
|
|
mkdir -p $out/bin $out/libexec
|
|
|
|
|
|
|
|
tar --strip-components=1 -xf ${yarnpkg-lockfile-tar} package/index.js
|
|
|
|
mv index.js $out/libexec/yarnpkg-lockfile.js
|
2024-06-14 15:34:37 +00:00
|
|
|
cp ${./common.js} $out/libexec/common.js
|
|
|
|
cp ${./fixup.js} $out/libexec/fixup.js
|
2024-01-18 22:53:33 +00:00
|
|
|
|
|
|
|
patchShebangs $out/libexec
|
2023-06-27 18:27:33 +00:00
|
|
|
makeWrapper $out/libexec/fixup.js $out/bin/fixup-yarn-lock
|
2021-10-06 02:52:35 +00:00
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
2023-06-29 15:11:41 +00:00
|
|
|
|
2024-07-03 06:27:59 +00:00
|
|
|
passthru = {
|
|
|
|
inherit tests;
|
|
|
|
};
|
2021-10-06 02:52:35 +00:00
|
|
|
};
|
|
|
|
|
2024-07-03 06:27:59 +00:00
|
|
|
fetchYarnDeps =
|
|
|
|
let
|
|
|
|
f =
|
|
|
|
{
|
|
|
|
name ? "offline",
|
|
|
|
src ? null,
|
|
|
|
hash ? "",
|
|
|
|
sha256 ? "",
|
|
|
|
...
|
|
|
|
}@args:
|
|
|
|
let
|
|
|
|
hash_ =
|
|
|
|
if hash != "" then
|
|
|
|
{
|
|
|
|
outputHashAlgo = null;
|
|
|
|
outputHash = hash;
|
|
|
|
}
|
|
|
|
else if sha256 != "" then
|
|
|
|
{
|
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
outputHash = sha256;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
outputHash = lib.fakeSha256;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation (
|
|
|
|
{
|
|
|
|
inherit name;
|
|
|
|
|
|
|
|
dontUnpack = src == null;
|
|
|
|
dontInstall = true;
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
prefetch-yarn-deps
|
|
|
|
cacert
|
|
|
|
];
|
|
|
|
GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
|
|
|
|
NODE_EXTRA_CA_CERTS = "${cacert}/etc/ssl/certs/ca-bundle.crt";
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
yarnLock=''${yarnLock:=$PWD/yarn.lock}
|
|
|
|
mkdir -p $out
|
|
|
|
(cd $out; prefetch-yarn-deps --verbose --builder $yarnLock)
|
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
outputHashMode = "recursive";
|
|
|
|
}
|
|
|
|
// hash_
|
|
|
|
// (removeAttrs args (
|
|
|
|
[
|
|
|
|
"name"
|
|
|
|
"hash"
|
|
|
|
"sha256"
|
|
|
|
]
|
|
|
|
++ (lib.optional (src == null) "src")
|
|
|
|
))
|
|
|
|
);
|
|
|
|
in
|
|
|
|
lib.setFunctionArgs f (lib.functionArgs f) // { inherit tests; };
|
2024-06-07 13:18:21 +00:00
|
|
|
|
|
|
|
yarnConfigHook = makeSetupHook {
|
|
|
|
name = "yarn-config-hook";
|
|
|
|
propagatedBuildInputs = [
|
|
|
|
yarn
|
|
|
|
fixup-yarn-lock
|
|
|
|
];
|
|
|
|
meta = {
|
|
|
|
description = "Install nodejs dependencies from an offline yarn cache produced by fetchYarnDeps";
|
|
|
|
};
|
|
|
|
} ./yarn-config-hook.sh;
|
2024-06-07 13:27:13 +00:00
|
|
|
|
|
|
|
yarnBuildHook = makeSetupHook {
|
|
|
|
name = "yarn-build-hook";
|
|
|
|
meta = {
|
|
|
|
description = "Run yarn build in buildPhase";
|
|
|
|
};
|
|
|
|
} ./yarn-build-hook.sh;
|
2024-07-19 15:41:58 +00:00
|
|
|
|
|
|
|
yarnInstallHook = makeSetupHook {
|
|
|
|
name = "yarn-install-hook";
|
|
|
|
propagatedBuildInputs = [
|
|
|
|
yarn
|
|
|
|
nodejsInstallManuals
|
|
|
|
nodejsInstallExecutables
|
|
|
|
];
|
|
|
|
substitutions = {
|
|
|
|
jq = lib.getExe jq;
|
|
|
|
};
|
|
|
|
} ./yarn-install-hook.sh;
|
2021-10-06 02:52:35 +00:00
|
|
|
}
|