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.1.1";
30 pyproject = true;
31
32 src = fetchFromGitHub {
33 owner = "langchain-ai";
34 repo = "langgraph";
35 tag = "checkpoint==${version}";
36 hash = "sha256-UY3AChShKfOrtOQzOm5vi3Yy3rlBc+TAje9L2L6My/U=";
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 # Temporarily disabled until the following is solved:
62 # https://github.com/NixOS/nixpkgs/pull/425384
63 doCheck = false;
64 # doCheck = !(stdenvNoCC.hostPlatform.isDarwin);
65
66 nativeCheckInputs = [
67 pytest-asyncio
68 pytestCheckHook
69 (postgresql.withPackages (p: with p; [ pgvector ]))
70 postgresqlTestHook
71 ];
72
73 preCheck = ''
74 export postgresqlTestUserOptions="LOGIN SUPERUSER"
75 '';
76
77 disabledTests = [
78 # psycopg.errors.FeatureNotSupported: extension "vector" is not available
79 # /nix/store/...postgresql-and-plugins-16.4/share/postgresql/extension/vector.control": No such file or directory.
80 "test_embed_with_path"
81 "test_embed_with_path_sync"
82 "test_scores"
83 "test_search_sorting"
84 "test_vector_store_initialization"
85 "test_vector_insert_with_auto_embedding"
86 "test_vector_update_with_embedding"
87 "test_vector_search_with_filters"
88 "test_vector_search_pagination"
89 "test_vector_search_edge_cases"
90 # Flaky under a parallel build (database in use)
91 "test_store_ttl"
92 ];
93
94 pythonImportsCheck = [ "langgraph.checkpoint.postgres" ];
95
96 passthru.updateScript = gitUpdater {
97 rev-prefix = "checkpointpostgres==";
98 };
99
100 meta = {
101 description = "Library with a Postgres implementation of LangGraph checkpoint saver";
102 homepage = "https://github.com/langchain-ai/langgraph/tree/main/libs/checkpoint-postgres";
103 changelog = "https://github.com/langchain-ai/langgraph/releases/tag/${src.tag}";
104 license = lib.licenses.mit;
105 maintainers = with lib.maintainers; [
106 sarahec
107 ];
108 };
109}