improve deno cache FOD
This commit is contained in:
parent
9df3f362fe
commit
a4bc8c0230
3 changed files with 48 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
|||
{ pkgs, system }:
|
||||
{ pkgs, system, knownDenoHashes }:
|
||||
|
||||
let
|
||||
target =
|
||||
|
|
@ -18,8 +18,38 @@ let
|
|||
scrollsDir = ./deno;
|
||||
lib = pkgs.lib;
|
||||
packageDirs = builtins.attrNames (builtins.readDir scrollsDir);
|
||||
|
||||
# Separate FOD for cache only
|
||||
|
||||
# hash only dependency-relevant files (lock files and configs)
|
||||
hashDependencyFiles = dir:
|
||||
let
|
||||
entries = builtins.readDir dir;
|
||||
|
||||
# Only process directories and dependency-relevant files
|
||||
relevantEntry = name: type:
|
||||
if type == "directory"
|
||||
then hashDependencyFiles (dir + "/${name}")
|
||||
else if (lib.hasSuffix ".lock" name ||
|
||||
lib.hasSuffix ".json" name ||
|
||||
lib.hasSuffix ".jsonc" name)
|
||||
then builtins.readFile (dir + "/${name}")
|
||||
else null;
|
||||
|
||||
contentMap = lib.filterAttrs (_: v: v != null)
|
||||
(builtins.mapAttrs relevantEntry entries);
|
||||
in builtins.toJSON contentMap;
|
||||
|
||||
sourceContentHash = builtins.convertHash {
|
||||
hash = "sha1:${builtins.hashString "sha1" (hashDependencyFiles scrollsDir)}";
|
||||
toHashFormat = "base64";
|
||||
};
|
||||
|
||||
# we assume that same lock+config files yield same deno caches here
|
||||
# however, jsons need to be sorted and some sqlite files deleted
|
||||
|
||||
# jsr gentlemen specifically require their package metadata
|
||||
# to have multiple timestamps, so they can fuck off
|
||||
outputHash = knownDenoHashes.${sourceContentHash} or lib.fakeSha256;
|
||||
|
||||
unifiedCache = pkgs.stdenv.mkDerivation {
|
||||
name = "deno-scrolls-cache";
|
||||
src = scrollsDir;
|
||||
|
|
@ -50,13 +80,21 @@ let
|
|||
${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";
|
||||
outputHash = "sha256-maP/JMY6n95A9FQx72YFwRtnprGXc97v1ZdPgt2GB8s=";
|
||||
# this is basically FOD on steroids cause it
|
||||
# deliberately breaks on relevant source changes
|
||||
inherit outputHash;
|
||||
};
|
||||
|
||||
in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue