pnpm.fetchDeps: add serve script

This script allows users to reuse the cached dependencies outside of
derivations.

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
(cherry picked from commit 728d48285e)
This commit is contained in:
Sefa Eyeoglu 2024-06-02 19:55:18 +02:00 committed by Emily
parent 3f4a4d0672
commit b4f5b3fa1a
2 changed files with 40 additions and 2 deletions

View File

@ -1,6 +1,7 @@
{
stdenvNoCC,
fetchurl,
callPackage,
jq,
moreutils,
cacert,
@ -29,7 +30,7 @@
outputHashAlgo = "sha256";
};
in
stdenvNoCC.mkDerivation (
stdenvNoCC.mkDerivation (finalAttrs: (
args'
// {
name = "${pname}-pnpm-deps";
@ -69,12 +70,19 @@
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";

View File

@ -0,0 +1,30 @@
{ writeShellApplication, pnpm, pnpmDeps }:
writeShellApplication {
name = "serve-pnpm-store";
runtimeInputs = [
pnpm
];
text = ''
storePath=$(mktemp -d)
clean() {
echo "Cleaning up temporary store at '$storePath'..."
rm -rf "$storePath"
}
echo "Copying pnpm store '${pnpmDeps}' to temporary store..."
cp -Tr "${pnpmDeps}" "$storePath"
chmod -R +w "$storePath"
echo "Run 'pnpm install --store-dir \"$storePath\"' to install packages from this store."
trap clean EXIT
pnpm server start \
--store-dir "$storePath"
'';
}