deno per package cache derivations + hashes

This commit is contained in:
EatThePooh 2025-08-02 14:14:41 +07:00
parent 9c18a0c924
commit f459ec8b78
9 changed files with 203 additions and 133 deletions

View file

@ -0,0 +1,42 @@
{ pkgs, denoCacheDrvs }:
let
mergeOneCache = cache: ''
if [ -d "${cache}" ]; then
echo " Merging cache from ${cache}"
# Use cp with fallback, handle overlapping files gracefully
cp -rL "${cache}"/* "$out/" 2>/dev/null || true
else
echo " Warning: ${cache} is not a directory, skipping"
fi
'';
mergeCacheCmd = pkgs.runCommand "deno-shelf-shared-cache"
{
buildInputs = denoCacheDrvs;
} ''
mkdir -p $out
echo "Merging ${builtins.toString (builtins.length denoCacheDrvs)} Deno caches..."
${pkgs.lib.concatMapStringsSep "\n" mergeOneCache denoCacheDrvs}
echo "Deno caches merged. Final size: $(du -sh $out | cut -f1)"
'';
in
pkgs.writeShellScript "deno-shelf-setup" ''
export DENO_DIR=$PWD/.deno_cache
if [ ! -d "$DENO_DIR" ] || [ "${mergeCacheCmd}" -nt "$DENO_DIR/.cache_timestamp" ]; then
echo "Setting up mutable Deno cache..."
rm -rf "$DENO_DIR"
cp -r "${mergeCacheCmd}" "$DENO_DIR"
chmod -R u+w "$DENO_DIR"
touch "$DENO_DIR/.cache_timestamp"
echo "Deno cache initialized"
else
echo "Deno cache already up to date"
fi
''

64
nix/deno/read_scroll.nix Normal file
View file

@ -0,0 +1,64 @@
{ pkgs, system, scrollsDir, subDir }:
let
target =
let
arch = builtins.head (builtins.split "-" system);
os = builtins.elemAt (builtins.split "-" system) 1;
vendor = if os == "darwin" then "apple" else "unknown";
sys = if os == "darwin" then "darwin" else "linux-gnu";
in "${arch}-${vendor}-${sys}";
scroll = import "${scrollsDir}/${subDir}/scroll.nix";
hashFilesCat = builtins.concatStringsSep ""
(builtins.map builtins.readFile scroll.build.hashFiles);
sourceContentHash_ = builtins.convertHash {
hash = "sha1:${builtins.hashString "sha1" hashFilesCat}";
toHashFormat = "base64";
};
sourceContentHash = "sha1-${sourceContentHash_}";
outputHash =
scroll.build.knownHashes.${sourceContentHash}
or pkgs.lib.fakeSha256;
in
{
env = pkgs.stdenv.mkDerivation {
name = "${scroll.name}-scroll-env";
src = scrollsDir;
nativeBuildInputs = [ pkgs.deno pkgs.jq ];
dontPatchShebangs = true;
buildPhase = ''
export DENO_DIR=$out
cd ${subDir}
${scroll.build.cacheCommand}
cd ..
echo 'Go fuck yourself, SQLite!'
find $out -name "*-wal" -delete
find $out -name "*-shm" -delete
echo 'Go fuck yourself, JSON!'
find $out/npm -name "*.json" -type f 2>/dev/null | while read -r file; do
if ${pkgs.jq}/bin/jq empty "$file" 2>/dev/null; then
${pkgs.jq}/bin/jq -S . "$file" > "$file.tmp" && mv "$file.tmp" "$file"
fi
done
echo 'sourceContentHash: ${sourceContentHash}'
echo ""
echo "add me to knownHashes if you see a fake sha256 error ^"
echo "DON'T USE JSR DEPS UNLESS YOU MAKE THEM REPRODUCIBLE SOMEHOW"
echo ""
'';
installPhase = "true";
outputHashMode = "recursive";
outputHashAlgo = "sha256";
inherit outputHash;
};
meta = builtins.removeAttrs scroll [ "build" ];
}