From b4f5b3fa1a7dacceb2efc92ed42eeaf2971a7773 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sun, 2 Jun 2024 19:55:18 +0200 Subject: [PATCH] pnpm.fetchDeps: add serve script This script allows users to reuse the cached dependencies outside of derivations. Signed-off-by: Sefa Eyeoglu (cherry picked from commit 728d48285e5c17ed9764bc7067b9cece3ae81f15) --- .../tools/pnpm/fetch-deps/default.nix | 12 ++++++-- .../tools/pnpm/fetch-deps/serve.nix | 30 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 pkgs/development/tools/pnpm/fetch-deps/serve.nix diff --git a/pkgs/development/tools/pnpm/fetch-deps/default.nix b/pkgs/development/tools/pnpm/fetch-deps/default.nix index 3a74f4cfe389..83972abf8b08 100644 --- a/pkgs/development/tools/pnpm/fetch-deps/default.nix +++ b/pkgs/development/tools/pnpm/fetch-deps/default.nix @@ -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"; diff --git a/pkgs/development/tools/pnpm/fetch-deps/serve.nix b/pkgs/development/tools/pnpm/fetch-deps/serve.nix new file mode 100644 index 000000000000..a44022d841dc --- /dev/null +++ b/pkgs/development/tools/pnpm/fetch-deps/serve.nix @@ -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" + ''; +}