1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 stdenvNoCC,
6
7 # build system
8 hatchling,
9
10 # dependencies
11 langgraph-checkpoint,
12 ormsgpack,
13 psycopg,
14 psycopg-pool,
15
16 # testing
17 pgvector,
18 postgresql,
19 postgresqlTestHook,
20 pytestCheckHook,
21 pytest-asyncio,
22
23 # passthru
24 gitUpdater,
25}:
26
27buildPythonPackage rec {
28 pname = "langgraph-checkpoint-postgres";
29 version = "2.0.23";
30 pyproject = true;
31
32 src = fetchFromGitHub {
33 owner = "langchain-ai";
34 repo = "langgraph";
35 tag = "checkpointpostgres==${version}";
36 hash = "sha256-QAzT8T3bf3R3gwI/iWDYYDz0SxgLZsP61oMk72dYz4s=";
37 };
38
39 postgresqlTestSetupPost = ''
40 substituteInPlace tests/conftest.py \
41 --replace-fail "DEFAULT_URI = \"postgres://postgres:postgres@localhost:5441/postgres?sslmode=disable\"" "DEFAULT_URI = \"postgres:///$PGDATABASE\"" \
42 --replace-fail "DEFAULT_POSTGRES_URI = \"postgres://postgres:postgres@localhost:5441/\"" "DEFAULT_POSTGRES_URI = \"postgres:///\""
43 '';
44
45 sourceRoot = "${src.name}/libs/checkpoint-postgres";
46
47 build-system = [ hatchling ];
48
49 dependencies = [
50 langgraph-checkpoint
51 ormsgpack
52 psycopg
53 psycopg-pool
54 ];
55
56 pythonRelaxDeps = [
57 "langgraph-checkpoint"
58 "psycopg-pool"
59 ];
60
61 doCheck = !(stdenvNoCC.hostPlatform.isDarwin);
62
63 nativeCheckInputs = [
64 pytest-asyncio
65 pytestCheckHook
66 (postgresql.withPackages (p: with p; [ pgvector ]))
67 postgresqlTestHook
68 ];
69
70 preCheck = ''
71 export postgresqlTestUserOptions="LOGIN SUPERUSER"
72 '';
73
74 disabledTests = [
75 # psycopg.errors.FeatureNotSupported: extension "vector" is not available
76 # /nix/store/...postgresql-and-plugins-16.4/share/postgresql/extension/vector.control": No such file or directory.
77 "test_embed_with_path"
78 "test_embed_with_path_sync"
79 "test_scores"
80 "test_search_sorting"
81 "test_vector_store_initialization"
82 "test_vector_insert_with_auto_embedding"
83 "test_vector_update_with_embedding"
84 "test_vector_search_with_filters"
85 "test_vector_search_pagination"
86 "test_vector_search_edge_cases"
87 # Flaky under a parallel build (database in use)
88 "test_store_ttl"
89 ];
90
91 pythonImportsCheck = [ "langgraph.checkpoint.postgres" ];
92
93 passthru = {
94 # python updater script sets the wrong tag
95 skipBulkUpdate = true;
96 updateScript = gitUpdater {
97 rev-prefix = "checkpointpostgres==";
98 };
99 };
100
101 meta = {
102 description = "Library with a Postgres implementation of LangGraph checkpoint saver";
103 homepage = "https://github.com/langchain-ai/langgraph/tree/main/libs/checkpoint-postgres";
104 changelog = "https://github.com/langchain-ai/langgraph/releases/tag/${src.tag}";
105 license = lib.licenses.mit;
106 maintainers = with lib.maintainers; [
107 sarahec
108 ];
109 };
110}