114 lines
3.4 KiB
Nix
114 lines
3.4 KiB
Nix
{
|
||
lib,
|
||
stdenv,
|
||
fetchFromGitHub,
|
||
nodejs_20,
|
||
yarn,
|
||
fetchYarnDeps,
|
||
fixup-yarn-lock,
|
||
python3,
|
||
pkg-config,
|
||
# makeWrapper,
|
||
# openssl,
|
||
# sqlite,
|
||
vips,
|
||
vite,
|
||
}:
|
||
|
||
let
|
||
pname = "anything-llm";
|
||
version = "1.10.0";
|
||
|
||
src = fetchFromGitHub {
|
||
owner = "Mintplex-Labs";
|
||
repo = "anything-llm";
|
||
rev = "v${version}";
|
||
hash = "sha256-W7wpgEJxo+IfIVRAWJNTmJL4RezO4NdlQEpV6dJp5IA=";
|
||
fetchSubmodules = true;
|
||
};
|
||
|
||
offlineCacheFrontend = fetchYarnDeps {
|
||
yarnLock = "${src}/frontend/yarn.lock";
|
||
hash = "sha256-ebAV+1Ux4aL6hIodfaRVjEUFSWQplI7c7sybTEzucdw=";
|
||
};
|
||
|
||
offlineCacheServer = fetchYarnDeps {
|
||
yarnLock = "${src}/server/yarn.lock";
|
||
hash = "sha256-+agJhFItPGLBUGLhhdNATiHuId51sDWQbG/Z1FyIVWM=";
|
||
};
|
||
in
|
||
stdenv.mkDerivation {
|
||
inherit pname version src;
|
||
|
||
nativeBuildInputs = [
|
||
nodejs_20
|
||
yarn
|
||
python3
|
||
pkg-config
|
||
stdenv.cc # чтобы был компилятор/линкер
|
||
fixup-yarn-lock
|
||
vite
|
||
];
|
||
buildInputs = [
|
||
vips
|
||
nodejs_20.dev
|
||
];
|
||
|
||
# важно: чтобы sharp не пытался скачать vendor-libvips и не игнорировал системный
|
||
SHARP_FORCE_GLOBAL_LIBVIPS = "1"; # всегда пытаться использовать global libvips :contentReference[oaicite:0]{index=0}
|
||
npm_config_build_from_source = "sharp"; # просим sharp собираться из исходников :contentReference[oaicite:1]{index=1}
|
||
|
||
configurePhase = ''
|
||
export HOME="$(mktemp -d)"
|
||
|
||
pushd server
|
||
fixup-yarn-lock yarn.lock
|
||
yarn config --offline set yarn-offline-mirror "${offlineCacheServer}"
|
||
|
||
# 1) ставим deps без postinstall'ов (иначе sharp полезет в сеть)
|
||
yarn install --offline --frozen-lockfile --ignore-scripts --no-progress
|
||
|
||
# 2) теперь собираем sharp из исходников против system libvips
|
||
export PKG_CONFIG_PATH="${vips.dev}/lib/pkgconfig:${vips}/lib/pkgconfig:$PKG_CONFIG_PATH"
|
||
export LD_LIBRARY_PATH="${vips}/lib:$LD_LIBRARY_PATH"
|
||
export npm_config_nodedir="${nodejs_20.dev}"
|
||
|
||
# yarn v1: rebuild прогоняет lifecycle для native-модулей
|
||
${nodejs_20}/bin/npm rebuild sharp --build-from-source --nodedir="${nodejs_20.dev}"
|
||
popd
|
||
'';
|
||
|
||
postPatch = ''
|
||
# frontend: build without Qt/X11 postbuild
|
||
substituteInPlace frontend/package.json \
|
||
--replace '"build": "vite build && node scripts/postbuild.js"' '"build": "vite build"'
|
||
'';
|
||
|
||
buildPhase = ''
|
||
runHook preBuild
|
||
(export QT_QPA_PLATFORM=offscreen QTWEBENGINE_DISABLE_SANDBOX=1 QTWEBENGINE_CHROMIUM_FLAGS="--headless --disable-gpu --no-sandbox"
|
||
cd frontend && yarn build) # --offline
|
||
# server/collector build steps, если нужны, добавите отдельно
|
||
runHook postBuild
|
||
'';
|
||
|
||
installPhase = ''
|
||
runHook preInstall
|
||
mkdir -p $out/lib/${pname} $out/bin
|
||
cp -r frontend server collector $out/lib/${pname}/
|
||
|
||
makeWrapper ${nodejs_20}/bin/node $out/bin/anything-llm-server \
|
||
--chdir $out/lib/${pname}/server \
|
||
--set NODE_ENV production \
|
||
--set-default PORT 3001 \
|
||
--add-flags "index.js"
|
||
runHook postInstall
|
||
'';
|
||
|
||
meta = with lib; {
|
||
description = "AnythingLLM (server + frontend + collector)";
|
||
homepage = "https://github.com/Mintplex-Labs/anything-llm";
|
||
license = licenses.mit;
|
||
platforms = platforms.linux;
|
||
};
|
||
}
|