core/pkgs/build-support/node/fetch-yarn-deps/default.nix

156 lines
3.4 KiB
Nix
Raw Normal View History

2024-06-30 08:16:52 +00:00
{
stdenv,
lib,
makeWrapper,
coreutils,
nix-prefetch-git,
fetchurl,
nodejs-slim,
prefetch-yarn-deps,
cacert,
callPackage,
nix,
}:
2024-05-02 00:46:19 +00:00
let
yarnpkg-lockfile-tar = fetchurl {
url = "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz";
hash = "sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==";
};
2024-06-30 08:16:52 +00:00
tests = callPackage ./tests { };
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
in
{
2024-05-02 00:46:19 +00:00
prefetch-yarn-deps = stdenv.mkDerivation {
name = "prefetch-yarn-deps";
dontUnpack = true;
dontBuild = true;
nativeBuildInputs = [ makeWrapper ];
buildInputs = [ nodejs-slim ];
installPhase = ''
runHook preInstall
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
cp ${./.}/common.js ${./.}/index.js $out/libexec/
patchShebangs $out/libexec
makeWrapper $out/libexec/index.js $out/bin/prefetch-yarn-deps \
2024-06-30 08:16:52 +00:00
--prefix PATH : ${
lib.makeBinPath [
coreutils
nix-prefetch-git
nix
]
}
2024-05-02 00:46:19 +00:00
runHook postInstall
'';
2024-06-30 08:16:52 +00:00
passthru = {
inherit tests;
};
2024-05-02 00:46:19 +00:00
};
fixup-yarn-lock = stdenv.mkDerivation {
name = "fixup-yarn-lock";
dontUnpack = true;
dontBuild = true;
nativeBuildInputs = [ makeWrapper ];
buildInputs = [ nodejs-slim ];
installPhase = ''
runHook preInstall
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
cp ${./.}/common.js ${./.}/fixup.js $out/libexec/
patchShebangs $out/libexec
makeWrapper $out/libexec/fixup.js $out/bin/fixup-yarn-lock
runHook postInstall
'';
2024-06-30 08:16:52 +00:00
passthru = {
inherit tests;
};
2024-05-02 00:46:19 +00:00
};
2024-06-30 08:16:52 +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 [
"src"
"name"
"hash"
"sha256"
])
);
in
lib.setFunctionArgs f (lib.functionArgs f) // { inherit tests; };
2024-05-02 00:46:19 +00:00
}