From 9f290b4a88da6aac3ea5c392e94f0eaff2c3f5f0 Mon Sep 17 00:00:00 2001 From: EatThePooh Date: Wed, 8 Oct 2025 14:29:38 +0700 Subject: [PATCH] handle registry files in shared cache derivation --- flake-module.nix | 61 +++++++++++++++++++++++++++++++----------------- flake.nix | 2 +- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/flake-module.nix b/flake-module.nix index dbd9c43..bb0d82f 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -65,8 +65,9 @@ in match = builtins.match "(@?[^@]+)@([^_]+).*" key; name = builtins.elemAt match 0; version = builtins.elemAt match 1; - in - pkgs.stdenv.mkDerivation { + cachePath = "npm/${registryHostname}/${name}"; + in { + drv = pkgs.stdenv.mkDerivation { pname = "deno-npm-${builtins.replaceStrings ["@" "/"] ["" "-"] name}"; version = version; src = mkTarballDrv { @@ -77,28 +78,16 @@ in installPhase = '' runHook preInstall - export OUT_PATH="$out/npm/${registryHostname}/${name}/${version}" + export OUT_PATH="$out/${cachePath}/${version}" mkdir -p $OUT_PATH tar -xzf $src -C $OUT_PATH --strip-components=1 - - SUBSET_FILTER='to_entries | map(select(.key == "version" or .key == "bin" or .key == "dependencies" or .key == "peerDependencies")) | from_entries' - PACKAGE_SUBSET=$(${pkgs.jq}/bin/jq "$SUBSET_FILTER" $OUT_PATH/package.json) - - cat > $OUT_PATH/../registry.json < $out/$dep/registry.json < $out/$dep/registry.json.tmp + + mv $out/$dep/registry.json.tmp $out/$dep/registry.json + done < <(find $out/$dep -mindepth 1 -maxdepth 1 -type d | xargs -n1 basename) + done < <(echo "${builtins.concatStringsSep "\n" (map (d: "${d.cachePath}|${d.name}") allNpmDeps)}" | sort -u) + + runHook postInstall + ''; denoWithCache = { pkgs, baseDeno, sharedCache }: pkgs.writeShellScriptBin "deno" '' diff --git a/flake.nix b/flake.nix index a9f186c..e939da4 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Builds a shared cache for Deno packages based on lock files"; + description = "Provides a Deno executable wrapper pointing to pre-built NPM dependency cache based on lock files"; outputs = { ... }: { flakeModule = ./flake-module.nix;