proper deno dep management
This commit is contained in:
parent
f937a3454d
commit
6abdf04412
11 changed files with 74 additions and 184 deletions
57
flake.lock
generated
57
flake.lock
generated
|
|
@ -1,5 +1,26 @@
|
|||
{
|
||||
"nodes": {
|
||||
"deno-with-packages": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1754403929,
|
||||
"narHash": "sha256-2+VxvvvOQOmidNGEbJibuYyyFufEvnr37evnZxcf7ao=",
|
||||
"owner": "voleum-org",
|
||||
"repo": "deno-with-packages",
|
||||
"rev": "47ad6f8ad05062db9a2b3dc421f8a0ea5484ce41",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "voleum-org",
|
||||
"repo": "deno-with-packages",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
|
|
@ -18,6 +39,24 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_2": {
|
||||
"inputs": {
|
||||
"systems": "systems_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1753939845,
|
||||
|
|
@ -36,7 +75,8 @@
|
|||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"deno-with-packages": "deno-with-packages",
|
||||
"flake-utils": "flake-utils_2",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
|
|
@ -54,6 +94,21 @@
|
|||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems_2": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
|
|
|
|||
|
|
@ -4,13 +4,15 @@
|
|||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
deno-with-packages.url = "github:voleum-org/deno-with-packages";
|
||||
deno-with-packages.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
outputs = { self, nixpkgs, flake-utils, deno-with-packages }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
lib = import ./nix;
|
||||
lib = import ./nix // deno-with-packages.lib.${system};
|
||||
shelf = import ./shelf {
|
||||
inherit pkgs system lib;
|
||||
};
|
||||
|
|
@ -22,7 +24,7 @@
|
|||
buildInputs = [ pkgs.deno ];
|
||||
shellHook = ''
|
||||
export DENO_DIR=$PWD/.deno_cache
|
||||
${shelf.setupScript}
|
||||
${shelf.setupScript}/bin/install-deno-cache
|
||||
|
||||
echo "Availabe scrolls:"
|
||||
echo ${pkgs.lib.escapeShellArg (builtins.toJSON shelf.scrolls)} | jq .
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
''
|
||||
|
|
@ -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" ];
|
||||
}
|
||||
|
|
@ -5,24 +5,23 @@ let
|
|||
scrollDirs = lib.discoverScrolls {
|
||||
scrollsDir = denoScrollsDir;
|
||||
};
|
||||
|
||||
mkScroll = subDir: lib.readDenoScroll {
|
||||
inherit pkgs system subDir;
|
||||
scrollsDir = denoScrollsDir;
|
||||
};
|
||||
|
||||
mkScroll = subDir: import "${denoScrollsDir}/${subDir}/scroll.nix";
|
||||
|
||||
scrolls = builtins.map mkScroll scrollDirs;
|
||||
|
||||
sharedCache = lib.buildSharedDenoCache {
|
||||
inherit pkgs system;
|
||||
scrollsDir = denoScrollsDir;
|
||||
subDirs = scrollDirs;
|
||||
lockfiles = builtins.map (s: s.build.lockFile) scrolls;
|
||||
|
||||
denoSharedCache = lib.denoSharedCache {
|
||||
inherit pkgs lockfiles;
|
||||
};
|
||||
in
|
||||
{
|
||||
setupScript = lib.makeDenoShelfSetup {
|
||||
inherit pkgs sharedCache;
|
||||
setupScript = lib.installDenoCache {
|
||||
inherit pkgs;
|
||||
cache = denoSharedCache;
|
||||
};
|
||||
|
||||
scrolls = builtins.map (s: s.meta) scrolls;
|
||||
scrolls =
|
||||
builtins.map (s: builtins.removeAttrs s [ "build" ]) scrolls;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
{
|
||||
name = "hjq";
|
||||
|
||||
description = "Drop-in jq replacement for HJSON that tries to preserve comments";
|
||||
|
||||
inputs = {
|
||||
stdin = {
|
||||
format = "HJSON";
|
||||
react = "push";
|
||||
};
|
||||
jqFilter = {
|
||||
format = "string";
|
||||
react = "push";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = {
|
||||
stdout = {
|
||||
format = "HJSON";
|
||||
react = "push";
|
||||
};
|
||||
};
|
||||
|
||||
build = {
|
||||
hashFiles = [ ./deno.json ./deno.lock ];
|
||||
cacheCommand = "deno cache --frozen main.ts";
|
||||
knownHashes = {
|
||||
"sha1-gSeoE0sSj+dFQ7SUoyaQV0X/KJE=" =
|
||||
"sha256-0ZfdWVfShbhgAoSse9vEpFPRh5XTTVjgxGMmezwon1I=";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
"tasks": {
|
||||
"start": "deno run --cached-only main.ts"
|
||||
},
|
||||
"patch": [
|
||||
"links": [
|
||||
"../hjq"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,6 @@
|
|||
};
|
||||
|
||||
build = {
|
||||
hashFiles = [ ./deno.json ./deno.lock ];
|
||||
cacheCommand = "deno cache --frozen main.ts";
|
||||
knownHashes = {
|
||||
"sha1-uO43Rt1F6+Ud1wk2p9LQhfP180M=" =
|
||||
"sha256-x/Fvn/l3J7C0D7AftlbRk7iuc6o9qPakdnHb72TSxec=";
|
||||
} ;
|
||||
lockFile = ./deno.lock;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue