proper deno dep management

This commit is contained in:
EatThePooh 2025-08-05 21:21:46 +07:00
parent f937a3454d
commit 6abdf04412
11 changed files with 74 additions and 184 deletions

View file

@ -1,9 +1,5 @@
let
lib = {
buildDenoCache = import ./deno/buildCache.nix { self = lib; };
readDenoScroll = import ./deno/readScroll.nix { self = lib; };
buildSharedDenoCache = import ./deno/buildSharedCache.nix { self = lib; };
makeDenoShelfSetup = import ./deno/makeShelfSetup.nix { self = lib; };
discoverScrolls = import ./discoverScrolls.nix { self = lib; };
};
in

View file

@ -1,78 +0,0 @@
{ self }:
{ pkgs, system, scrollsDir, subDir, baseCache ? null }:
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
pkgs.stdenv.mkDerivation {
name = if baseCache == null
then "${scroll.name}-scroll-env"
else "${scroll.name}-incremental-cache";
src = scrollsDir;
passAsFile = [ "knownHashesJson" ];
knownHashesJson = builtins.toJSON scroll.build.knownHashes;
nativeBuildInputs = [ pkgs.deno pkgs.jq ];
dontPatchShebangs = true;
buildPhase = ''
export DENO_DIR=$out
mkdir -p $DENO_DIR
# Start with base cache if provided
${if baseCache != null then ''
if [ -d "${baseCache}" ]; then
cp -r "${baseCache}"/* "$out/" 2>/dev/null || true
find "$out" -type f -exec chmod u+w {} \;
find "$out" -type d -exec chmod u+w {} \;
fi
'' else ""}
cd ${subDir}
echo "Building cache for ${scroll.name}..."
${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;
}

View file

@ -1,14 +0,0 @@
{ self }:
{ pkgs, system, scrollsDir, subDirs }:
let
emptyDenoCache = pkgs.runCommand "empty-deno-cache" {} ''
mkdir -p $out
'';
in
builtins.foldl' (accCache: subDir:
self.buildDenoCache {
inherit pkgs system scrollsDir subDir;
baseCache = accCache;
}
) emptyDenoCache subDirs

View file

@ -1,22 +0,0 @@
{ self }:
{ pkgs, sharedCache }:
pkgs.writeShellScript "deno-shelf-setup" ''
# DENO_DIR should be set by the caller
if [ -z "$DENO_DIR" ]; then
echo "Error: DENO_DIR environment variable must be set"
exit 1
fi
if [ ! -d "$DENO_DIR" ] || [ "${sharedCache}" -nt "$DENO_DIR/.cache_timestamp" ]; then
echo "Setting up shared Deno cache in $DENO_DIR..."
rm -rf "$DENO_DIR"
cp -r "${sharedCache}" "$DENO_DIR"
chmod -R u+w "$DENO_DIR"
touch "$DENO_DIR/.cache_timestamp"
echo "Shared Deno cache initialized"
else
echo "Deno cache is up to date"
fi
''

View file

@ -1,11 +0,0 @@
{ self }:
{ pkgs, system, scrollsDir, subDir }:
let
scroll = import "${scrollsDir}/${subDir}/scroll.nix";
in
{
env = self.buildDenoCache {
inherit pkgs system scrollsDir subDir;
};
meta = builtins.removeAttrs scroll [ "build" ];
}