154 lines
3.6 KiB
Nix
154 lines
3.6 KiB
Nix
|
|
{
|
||
|
|
lib,
|
||
|
|
stdenv,
|
||
|
|
fetchFromGitHub,
|
||
|
|
python3,
|
||
|
|
}:
|
||
|
|
# NOTE: First build will fail with a hash mismatch error.
|
||
|
|
# Copy the "got: sha256-XXX..." from the error and replace fakeHash below.
|
||
|
|
let
|
||
|
|
version = "3.0.6";
|
||
|
|
|
||
|
|
src = fetchFromGitHub {
|
||
|
|
owner = "plastic-labs";
|
||
|
|
repo = "honcho";
|
||
|
|
tag = "v${version}";
|
||
|
|
hash = lib.fakeHash;
|
||
|
|
};
|
||
|
|
|
||
|
|
pythonEnv = python3.withPackages (ps:
|
||
|
|
with ps; [
|
||
|
|
# Core web framework
|
||
|
|
fastapi
|
||
|
|
uvicorn
|
||
|
|
httptools
|
||
|
|
python-dotenv
|
||
|
|
sqlalchemy
|
||
|
|
fastapi-pagination
|
||
|
|
|
||
|
|
# Database & vector
|
||
|
|
pgvector
|
||
|
|
psycopg
|
||
|
|
greenlet
|
||
|
|
|
||
|
|
# LLM providers
|
||
|
|
openai
|
||
|
|
google-genai
|
||
|
|
|
||
|
|
# Utilities
|
||
|
|
httpx
|
||
|
|
rich
|
||
|
|
nanoid
|
||
|
|
alembic
|
||
|
|
pyjwt
|
||
|
|
tenacity
|
||
|
|
tiktoken
|
||
|
|
langfuse
|
||
|
|
pydantic
|
||
|
|
pydantic-settings
|
||
|
|
pdfplumber
|
||
|
|
typing-extensions
|
||
|
|
json-repair
|
||
|
|
scikit-learn
|
||
|
|
prometheus-client
|
||
|
|
cloudevents
|
||
|
|
|
||
|
|
# Vector store backends
|
||
|
|
turbopuffer
|
||
|
|
lancedb
|
||
|
|
pyarrow
|
||
|
|
|
||
|
|
# Cache
|
||
|
|
redis
|
||
|
|
cashews
|
||
|
|
|
||
|
|
# Observability
|
||
|
|
sentry-sdk
|
||
|
|
]);
|
||
|
|
in
|
||
|
|
stdenv.mkDerivation {
|
||
|
|
pname = "honcho";
|
||
|
|
inherit version src;
|
||
|
|
|
||
|
|
buildInputs = [pythonEnv];
|
||
|
|
|
||
|
|
buildPhase = ''
|
||
|
|
rm -rf sdks honcho-cli
|
||
|
|
'';
|
||
|
|
|
||
|
|
installPhase = ''
|
||
|
|
mkdir -p $out/{src,migrations,scripts,bin}
|
||
|
|
|
||
|
|
cp -r src/* $out/src/
|
||
|
|
cp -r migrations/* $out/migrations/
|
||
|
|
cp scripts/provision_db.py $out/scripts/
|
||
|
|
cp alembic.ini $out/
|
||
|
|
|
||
|
|
# API wrapper
|
||
|
|
cat > $out/bin/honcho-api << 'WRAPPER'
|
||
|
|
#!/bin/sh
|
||
|
|
exec ${pythonEnv}/bin/python -c "
|
||
|
|
import sys, os
|
||
|
|
app_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||
|
|
os.chdir(app_dir)
|
||
|
|
sys.path.insert(0, app_dir)
|
||
|
|
os.environ.setdefault('PYTHON_DOTENV_DISABLED', 'true')
|
||
|
|
os.environ.setdefault('HONCHO_CONFIG_TOML_DISABLED', 'true')
|
||
|
|
import uvicorn
|
||
|
|
port = int(os.environ.get('PORT', '8000'))
|
||
|
|
for i, arg in enumerate(sys.argv[1:]):
|
||
|
|
if arg.startswith('--port='):
|
||
|
|
port = int(arg.split('=',1)[1])
|
||
|
|
elif arg == '--port':
|
||
|
|
nxt = sys.argv[i+2:i+3]
|
||
|
|
if nxt: port = int(nxt[0])
|
||
|
|
uvicorn.run('src.main:app', host='0.0.0.0', port=port)
|
||
|
|
" "$@"
|
||
|
|
WRAPPER
|
||
|
|
chmod +x $out/bin/honcho-api
|
||
|
|
|
||
|
|
# Deriver wrapper
|
||
|
|
cat > $out/bin/honcho-deriver << 'WRAPPER'
|
||
|
|
#!/bin/sh
|
||
|
|
exec ${pythonEnv}/bin/python -c "
|
||
|
|
import sys, os
|
||
|
|
app_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||
|
|
os.chdir(app_dir)
|
||
|
|
sys.path.insert(0, app_dir)
|
||
|
|
os.environ.setdefault('PYTHON_DOTENV_DISABLED', 'true')
|
||
|
|
os.environ.setdefault('HONCHO_CONFIG_TOML_DISABLED', 'true')
|
||
|
|
from src.deriver.__main__ import *
|
||
|
|
" "$@"
|
||
|
|
WRAPPER
|
||
|
|
chmod +x $out/bin/honcho-deriver
|
||
|
|
|
||
|
|
# Migration wrapper
|
||
|
|
cat > $out/bin/honcho-migrate << 'WRAPPER'
|
||
|
|
#!/bin/sh
|
||
|
|
exec ${pythonEnv}/bin/python -c "
|
||
|
|
import sys, os, asyncio
|
||
|
|
app_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||
|
|
os.chdir(app_dir)
|
||
|
|
sys.path.insert(0, app_dir)
|
||
|
|
os.environ.setdefault('PYTHON_DOTENV_DISABLED', 'true')
|
||
|
|
os.environ.setdefault('HONCHO_CONFIG_TOML_DISABLED', 'true')
|
||
|
|
from src.db import init_db
|
||
|
|
asyncio.run(init_db())
|
||
|
|
" "$@"
|
||
|
|
WRAPPER
|
||
|
|
chmod +x $out/bin/honcho-migrate
|
||
|
|
'';
|
||
|
|
|
||
|
|
passthru = {
|
||
|
|
inherit pythonEnv;
|
||
|
|
python = pythonEnv;
|
||
|
|
};
|
||
|
|
|
||
|
|
meta = {
|
||
|
|
description = "Honcho — Memory system for stateful AI agents";
|
||
|
|
homepage = "https://honcho.dev";
|
||
|
|
license = lib.licenses.agpl3Only;
|
||
|
|
platforms = lib.platforms.linux;
|
||
|
|
};
|
||
|
|
}
|