2024-06-20 14:57:18 +00:00
|
|
|
{
|
2024-07-01 15:47:52 +00:00
|
|
|
lib,
|
2024-06-20 14:57:18 +00:00
|
|
|
stdenvNoCC,
|
|
|
|
callPackage,
|
|
|
|
jq,
|
|
|
|
moreutils,
|
|
|
|
cacert,
|
|
|
|
makeSetupHook,
|
|
|
|
pnpm,
|
2024-07-01 15:47:52 +00:00
|
|
|
yq,
|
2024-06-20 14:57:18 +00:00
|
|
|
}:
|
|
|
|
{
|
|
|
|
fetchDeps =
|
|
|
|
{
|
|
|
|
hash ? "",
|
|
|
|
pname,
|
2024-09-19 14:19:46 +00:00
|
|
|
pnpmWorkspace ? "",
|
|
|
|
prePnpmInstall ? "",
|
2024-06-20 14:57:18 +00:00
|
|
|
...
|
|
|
|
}@args:
|
|
|
|
let
|
|
|
|
args' = builtins.removeAttrs args [
|
|
|
|
"hash"
|
|
|
|
"pname"
|
|
|
|
];
|
|
|
|
hash' =
|
|
|
|
if hash != "" then
|
|
|
|
{ outputHash = hash; }
|
|
|
|
else
|
|
|
|
{
|
|
|
|
outputHash = "";
|
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
installFlags = lib.optionalString (pnpmWorkspace != "") "--filter=${pnpmWorkspace}";
|
2024-06-20 14:57:18 +00:00
|
|
|
in
|
|
|
|
stdenvNoCC.mkDerivation (finalAttrs: (
|
|
|
|
args'
|
|
|
|
// {
|
|
|
|
name = "${pname}-pnpm-deps";
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
2024-07-01 15:47:52 +00:00
|
|
|
cacert
|
2024-06-20 14:57:18 +00:00
|
|
|
jq
|
|
|
|
moreutils
|
|
|
|
pnpm
|
2024-07-01 15:47:52 +00:00
|
|
|
yq
|
2024-06-20 14:57:18 +00:00
|
|
|
];
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
impureEnvVars = lib.fetchers.proxyImpureEnvVars;
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
2024-07-01 15:47:52 +00:00
|
|
|
lockfileVersion="$(yq -r .lockfileVersion pnpm-lock.yaml)"
|
|
|
|
if [[ ''${lockfileVersion:0:1} -gt ${lib.versions.major pnpm.version} ]]; then
|
|
|
|
echo "ERROR: lockfileVersion $lockfileVersion in pnpm-lock.yaml is too new for the provided pnpm version ${lib.versions.major pnpm.version}!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
export HOME=$(mktemp -d)
|
|
|
|
pnpm config set store-dir $out
|
|
|
|
# Some packages produce platform dependent outputs. We do not want to cache those in the global store
|
|
|
|
pnpm config set side-effects-cache false
|
|
|
|
# As we pin pnpm versions, we don't really care about updates
|
|
|
|
pnpm config set update-notifier false
|
2024-09-19 14:19:46 +00:00
|
|
|
# Run any additional pnpm configuration commands that users provide.
|
|
|
|
${prePnpmInstall}
|
2024-06-20 14:57:18 +00:00
|
|
|
# pnpm is going to warn us about using --force
|
|
|
|
# --force allows us to fetch all dependencies including ones that aren't meant for our host platform
|
2024-09-19 14:19:46 +00:00
|
|
|
pnpm install \
|
|
|
|
--force \
|
|
|
|
--ignore-scripts \
|
|
|
|
${installFlags} \
|
|
|
|
--frozen-lockfile
|
2024-06-20 14:57:18 +00:00
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
fixupPhase = ''
|
|
|
|
runHook preFixup
|
|
|
|
|
|
|
|
# Remove timestamp and sort the json files
|
|
|
|
rm -rf $out/v3/tmp
|
|
|
|
for f in $(find $out -name "*.json"); do
|
|
|
|
jq --sort-keys "del(.. | .checkedAt?)" $f | sponge $f
|
|
|
|
done
|
|
|
|
|
|
|
|
runHook postFixup
|
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
serve = callPackage ./serve.nix {
|
|
|
|
inherit pnpm;
|
|
|
|
pnpmDeps = finalAttrs.finalPackage;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
dontConfigure = true;
|
|
|
|
dontBuild = true;
|
|
|
|
outputHashMode = "recursive";
|
|
|
|
}
|
|
|
|
// hash'
|
|
|
|
));
|
|
|
|
|
|
|
|
configHook = makeSetupHook {
|
|
|
|
name = "pnpm-config-hook";
|
|
|
|
propagatedBuildInputs = [ pnpm ];
|
|
|
|
} ./pnpm-config-hook.sh;
|
|
|
|
}
|