proper scrolls

This commit is contained in:
EatThePooh 2025-08-02 05:10:30 +07:00
parent d92bc3b437
commit 9df3f362fe
11 changed files with 146 additions and 36 deletions

View file

@ -10,39 +10,19 @@
flake-utils.lib.eachDefaultSystem (system: flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
toDenoTarget = system: denoWorkspace = import ./shelf/deno-workspace.nix {
let inherit pkgs system;
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}";
target = toDenoTarget system;
hjq = import ./shelf/hjq/package.nix {
inherit pkgs;
inherit target;
}; };
in in
{ {
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = [ ];
deno
hjq
];
shellHook = '' shellHook = ''
echo "🦕 Deno development environment loaded!" export DENO_DIR=$PWD/.deno_cache
echo "Deno version: $(deno --version | head -n1)" rm -rf $DENO_DIR
cp -r ${denoWorkspace} $DENO_DIR
chmod -R u+w "$DENO_DIR"
''; '';
DENO_DIR = "./.deno_cache";
}; };
# unfortunately this derivation is impure because
# managing deno's deps is HARD, so
# nix build --option sanbox relaxed
packages.default = hjq;
}); });
} }

63
shelf/deno-workspace.nix Normal file
View file

@ -0,0 +1,63 @@
{ pkgs, system }:
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}";
# currently unused, needed for deno compile
denort = pkgs.fetchzip {
url = "https://dl.deno.land/release/v${pkgs.deno.version}/denort-${target}.zip";
hash = "sha256-ukIk8K2CE+N+3eFs++RPiGZlhhRRVk1gjhdt77/s+4o=";
};
scrollsDir = ./deno;
lib = pkgs.lib;
packageDirs = builtins.attrNames (builtins.readDir scrollsDir);
# Separate FOD for cache only
unifiedCache = pkgs.stdenv.mkDerivation {
name = "deno-scrolls-cache";
src = scrollsDir;
nativeBuildInputs = [ pkgs.deno pkgs.jq ];
dontPatchShebangs = true;
buildPhase = ''
export DENO_DIR=$out
${lib.concatStringsSep "\n" (map (pkg:
let config = import (scrollsDir + "/${pkg}/scroll.nix");
in ''
echo "Caching ${pkg}..."
cd ${pkg}
${config.cache-command}
cd ..
''
) packageDirs)}
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
'';
installPhase = "true";
outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = "sha256-maP/JMY6n95A9FQx72YFwRtnprGXc97v1ZdPgt2GB8s=";
};
in
unifiedCache

10
shelf/deno/hjq/deno.json Normal file
View file

@ -0,0 +1,10 @@
{
"name": "hjq",
"exports": {
".": "./main.ts"
},
"imports": {
"hjson": "npm:hjson@^3.2.2",
"jq-web": "npm:jq-web@^0.6.2"
}
}

21
shelf/deno/hjq/deno.lock generated Normal file
View file

@ -0,0 +1,21 @@
{
"version": "4",
"specifiers": {
"npm:hjson@^3.2.2": "3.2.2",
"npm:jq-web@~0.6.2": "0.6.2"
},
"npm": {
"hjson@3.2.2": {
"integrity": "sha512-MkUeB0cTIlppeSsndgESkfFD21T2nXPRaBStLtf3cAYA2bVEFdXlodZB0TukwZiobPD1Ksax5DK4RTZeaXCI3Q=="
},
"jq-web@0.6.2": {
"integrity": "sha512-+7XvjBYwTx4vP5PYkf6Q6orubO/v+UgMU6By1GritrmShr9QpT3UKa4ANzXWQfhdqtBnQYXsm7ZNbdIHT6tYpQ=="
}
},
"workspace": {
"dependencies": [
"npm:hjson@^3.2.2",
"npm:jq-web@~0.6.2"
]
}
}

View file

@ -1,10 +1,12 @@
// a basic drop-in replacement for jq to handle HJSON // a basic drop-in replacement for jq to handle HJSON
// tries to preserve comments but doesn't do a very good job :( // tries to preserve comments but doesn't do a very good job :(
import Hjson from "npm:hjson"; import Hjson from "hjson";
import jqModule from "npm:jq-web"; import jqModule from "jq-web";
import fs from "node:fs"; import fs from "node:fs";
export const n = 42;
const jq = await jqModule; const jq = await jqModule;
var filter = process.argv[2]; var filter = process.argv[2];

View file

@ -22,6 +22,8 @@ pkgs.stdenv.mkDerivation rec {
unzip ${denort} unzip ${denort}
chmod +x denort chmod +x denort
popd popd
deno cache --reload main.ts
''; '';
buildPhase = '' buildPhase = ''
@ -29,7 +31,7 @@ pkgs.stdenv.mkDerivation rec {
export DENORT_BIN="$TMPDIR/denort/denort" export DENORT_BIN="$TMPDIR/denort/denort"
deno compile --target=${target} --output app main.ts deno compile --target=${target} --cached-only --output app main.ts
runHook postBuild runHook postBuild
''; '';

View file

@ -0,0 +1,3 @@
{
cache-command = "deno cache --reload main.ts";
}

View file

@ -0,0 +1,8 @@
{
"tasks": {
"start": "deno run --cached-only main.ts"
},
"patch": [
"../hjq"
]
}

15
shelf/deno/uses-hjq/deno.lock generated Normal file
View file

@ -0,0 +1,15 @@
{
"version": "4",
"specifiers": {
"npm:hjson@^3.2.2": "3.2.2",
"npm:jq-web@~0.6.2": "0.6.2"
},
"npm": {
"hjson@3.2.2": {
"integrity": "sha512-MkUeB0cTIlppeSsndgESkfFD21T2nXPRaBStLtf3cAYA2bVEFdXlodZB0TukwZiobPD1Ksax5DK4RTZeaXCI3Q=="
},
"jq-web@0.6.2": {
"integrity": "sha512-+7XvjBYwTx4vP5PYkf6Q6orubO/v+UgMU6By1GritrmShr9QpT3UKa4ANzXWQfhdqtBnQYXsm7ZNbdIHT6tYpQ=="
}
}
}

View file

@ -0,0 +1,3 @@
import {n} from 'hjq';
console.log("I use hjq:", n);

View file

@ -0,0 +1,3 @@
{
cache-command = "deno cache -I --reload main.ts";
}