improve deno cache FOD
This commit is contained in:
parent
9df3f362fe
commit
a4bc8c0230
3 changed files with 48 additions and 5 deletions
|
|
@ -12,6 +12,11 @@
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
denoWorkspace = import ./shelf/deno-workspace.nix {
|
denoWorkspace = import ./shelf/deno-workspace.nix {
|
||||||
inherit pkgs system;
|
inherit pkgs system;
|
||||||
|
# collective hash of all deno sources - resulting shared deno cache hash
|
||||||
|
knownDenoHashes = {
|
||||||
|
"UnKGEQo7oF1X5JeWyx7w0oCwqPQ=" =
|
||||||
|
"sha256-7csbrTbGd6J4a0Gkj9ndKhNxv90KeOHjr7DDNal3L4Q=";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{ pkgs, system }:
|
{ pkgs, system, knownDenoHashes }:
|
||||||
|
|
||||||
let
|
let
|
||||||
target =
|
target =
|
||||||
|
|
@ -19,7 +19,37 @@ let
|
||||||
lib = pkgs.lib;
|
lib = pkgs.lib;
|
||||||
packageDirs = builtins.attrNames (builtins.readDir scrollsDir);
|
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 {
|
unifiedCache = pkgs.stdenv.mkDerivation {
|
||||||
name = "deno-scrolls-cache";
|
name = "deno-scrolls-cache";
|
||||||
src = scrollsDir;
|
src = scrollsDir;
|
||||||
|
|
@ -50,13 +80,21 @@ let
|
||||||
${pkgs.jq}/bin/jq -S . "$file" > "$file.tmp" && mv "$file.tmp" "$file"
|
${pkgs.jq}/bin/jq -S . "$file" > "$file.tmp" && mv "$file.tmp" "$file"
|
||||||
fi
|
fi
|
||||||
done
|
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";
|
installPhase = "true";
|
||||||
|
|
||||||
outputHashMode = "recursive";
|
outputHashMode = "recursive";
|
||||||
outputHashAlgo = "sha256";
|
outputHashAlgo = "sha256";
|
||||||
outputHash = "sha256-maP/JMY6n95A9FQx72YFwRtnprGXc97v1ZdPgt2GB8s=";
|
# this is basically FOD on steroids cause it
|
||||||
|
# deliberately breaks on relevant source changes
|
||||||
|
inherit outputHash;
|
||||||
};
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"start": "deno run --cached-only main.ts"
|
"start": "deno run --cached-only main.ts"
|
||||||
},
|
},
|
||||||
"patch": [
|
"links": [
|
||||||
"../hjq"
|
"../hjq"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue