Skip to content

postgresql.withPackages.pg_config: fix paths#407920

Closed
wolfgangwalther wants to merge 3 commits intoNixOS:stagingfrom
wolfgangwalther:postgresql-with-pg-config
Closed

postgresql.withPackages.pg_config: fix paths#407920
wolfgangwalther wants to merge 3 commits intoNixOS:stagingfrom
wolfgangwalther:postgresql-with-pg-config

Conversation

@wolfgangwalther
Copy link
Contributor

Previously, pg_config would report the paths of the underlying postgresql derivation and not the paths of the buildEnv that postgresql.withPackages creates.

That's a problem when users of pg_config use it to find PostgreSQL's sharedir, in which they'd like to find the extensions added via withPackages. Those are only linked into the created buildEnv, but not available in the postgresql derivation.

By providing our own nix-support/pg_config.env file, we can swap out those paths. We also do the same for the -man output, because this output is linked into buildEnv as well. Other paths, which are not available in the buildEnv environment, will still link to the original postgresql derivation. Win-win!

This came up in #404027, where it's currently required to pass the following cmakeFlags:

    "-DPG_CONFIG=${pgWithExtensions.pg_config}/bin/pg_config"
    "-DPostgreSQL_EXTENSION_DIR=${lib.getDev pgWithExtensions}/share/postgresql/extension/"
    "-DPostgreSQL_PACKAGE_LIBRARY_DIR=${lib.getDev pgWithExtensions}/lib/"

Even though pg_config is made available, the two paths still need to be specified explicitly, because they point to the wrong location.

Note: This is a fix, that should allow omnigres to only require the first line about pg_config. However, it currently still breaks the otherwise succeeding build in that PR with, what I suspect, an upstream bug in their cmake files. I still think we should do this, because it's the correct thing to do.

(review with whitespace disabled, most of that is just indentation)

Things done

  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@wolfgangwalther wolfgangwalther requested a review from Ma27 May 17, 2025 12:25
@wolfgangwalther wolfgangwalther force-pushed the postgresql-with-pg-config branch from 735daab to 0734b85 Compare May 17, 2025 12:25
@wolfgangwalther wolfgangwalther changed the title postgresql.withPackages.pg_config: Fix paths postgresql.withPackages.pg_config: fix paths May 17, 2025
@nix-owners nix-owners bot requested a review from thoughtpolice May 17, 2025 12:27
@github-actions github-actions bot added 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels May 17, 2025
@wolfgangwalther wolfgangwalther force-pushed the postgresql-with-pg-config branch 2 times, most recently from 862d249 to bb5cd4d Compare May 17, 2025 21:06
@wolfgangwalther wolfgangwalther force-pushed the postgresql-with-pg-config branch from bb5cd4d to aea8669 Compare May 20, 2025 19:08
@wolfgangwalther
Copy link
Contributor Author

Note: This is a fix, that should allow omnigres to only require the first line about pg_config. However, it currently still breaks the otherwise succeeding build in that PR with, what I suspect, an upstream bug in their cmake files. I still think we should do this, because it's the correct thing to do.

Since #404027 is now merged, we'll need to figure out the build failure here. postgresqlPackages.omnigres now fails with a lot of these:

CMake Error at cmake/PostgreSQLExtension.cmake:234 (file):
  file COPY cannot make directory
  "/build/source/build/pg-share/timezonesets": File exists.
Call Stack (most recent call first):
  extensions/omni_worker/CMakeLists.txt:22 (add_postgresql_extension)

@yrashk could you have a look at this? To me, this seems like the build system might be at fault.

@nix-owners nix-owners bot requested a review from schonfinkel May 20, 2025 19:15
@schonfinkel
Copy link
Member

@wolfgangwalther I'll try to build this branch and gather some more logs for @yrashk

@wolfgangwalther
Copy link
Contributor Author

So, I can fix this omnigres build failure with:

        pathsToLink = [
          "/"
          "/bin"
+          "/share/postgresql/timezonesets"
+          "/share/postgresql/tsearch_data"
        ];

Thus, the reason for the failure seems to be that Omnigres' build system assume that it can just copy SHAREDIR (.../share/postgresql) to a temporary folder. But in our case, the subfolders like .../timezonesets and .../tsearch_data are actually symlinks into the nix store. Thus, the build system can then not create its own files in those directories.

So what upstream should really be doing is:

  • Create the directory structure it needs, and then
  • Copy all the files in there

(and avoid copying directories)

Or alternatively, it should treat symlinks correctly... although the code looks like it already intends to do so:

https://github.com/omnigres/omnigres/blob/91c1075fea15b76f0e3ba7b57e5261323fb7c872/cmake/PostgreSQLExtension.cmake#L234C66-L234C86

@schonfinkel
Copy link
Member

schonfinkel commented May 23, 2025

So, I can fix this omnigres build failure with:

        pathsToLink = [
          "/"
          "/bin"
+          "/share/postgresql/timezonesets"
+          "/share/postgresql/tsearch_data"
        ];

Thus, the reason for the failure seems to be that Omnigres' build system assume that it can just copy SHAREDIR (.../share/postgresql) to a temporary folder. But in our case, the subfolders like .../timezonesets and .../tsearch_data are actually symlinks into the nix store. Thus, the build system can then not create its own files in those directories.

So what upstream should really be doing is:

  • Create the directory structure it needs, and then
  • Copy all the files in there

(and avoid copying directories)

Or alternatively, it should treat symlinks correctly... although the code looks like it already intends to do so:

https://github.com/omnigres/omnigres/blob/91c1075fea15b76f0e3ba7b57e5261323fb7c872/cmake/PostgreSQLExtension.cmake#L234C66-L234C86

I wonder if it makes sense putting these symlinks in the omnigres derivation while the build changes are not in the main branch of omnigres.

@Ma27
Copy link
Member

Ma27 commented Jun 7, 2025

I wonder if it makes sense putting these symlinks in the omnigres derivation while the build changes are not in the main branch of omnigres.

Isn't it simpler to just continue using the CMake flags mentioned above?

Copy link
Member

@Ma27 Ma27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks reasonable code-wise.

Do we know more about the potential blast-radius, i.e. other build-systems that fail funnily when getting a symlink instead of a directory from pg_config? Omnigres seems to be one instance already and I'm a little afraid that there are more (considering all the fun we had with pg_config in the past months).

And if that's the case I do wonder if two cmake flags aren't the cheaper and more sustainable option for us.

That also means, if omnigres is an outlier, I'm absolutely in favor.

@wolfgangwalther
Copy link
Contributor Author

Do we know more about the potential blast-radius, i.e. other build-systems that fail funnily when getting a symlink instead of a directory from pg_config?

Not really. Omnigres is the only build system that relies on a PostgreSQL with extensions. Every other extension we know of builds with a pg_config based on postgresql directly.

Isn't it simpler to just continue using the CMake flags mentioned above?

IIRC, they will then fail the same way. The two things are unrelated, I think: CMake needs pg_config to return proper paths to be able to remove the two flags. But when it receives the proper paths, it fails in a different place with the symlink stuff.

After having thought about this for a while, I think we can just add to pathsToLink as mentioned above, this should be fine. /share/postgresql/extension is already a real directory and not symlinked, because this is where the extensions are "bundled" by withPackages. If, in theory, an extension would provide timezonesets or tsearch_data (not sure whether any do, ever) then it would "heal" itself as well, for those. So we can just force creating the directory there.

@wolfgangwalther wolfgangwalther force-pushed the postgresql-with-pg-config branch from aea8669 to 18f29ae Compare June 8, 2025 08:56
@wolfgangwalther
Copy link
Contributor Author

After having thought about this for a while, I think we can just add to pathsToLink as mentioned above, this should be fine. /share/postgresql/extension is already a real directory and not symlinked, because this is where the extensions are "bundled" by withPackages. If, in theory, an extension would provide timezonesets or tsearch_data (not sure whether any do, ever) then it would "heal" itself as well, for those. So we can just force creating the directory there.

Did that. This makes Omnigres build. I still think that their build system should do better there, though.

@wolfgangwalther
Copy link
Contributor Author

Hm, omnigres on darwin is still broken with this now:

[ 28%] Building C object _deps/h2o-build/CMakeFiles/libh2o-evloop.dir/deps/cloexec/cloexec.c.o
Undefined symbols for architecture arm64:
  "_BlessTupleDesc", referenced from:
      _execute_parameterized in omni_sql.c.o

[... lots of others ...]

  "_work_mem", referenced from:
      _raw_statements in omni_sql.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [extensions/omni_httpc/omni_sql/CMakeFiles/omni_sql.dir/build.make:102: extensions/omni_httpc/omni_sql/omni_sql--0.5.1.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:5109: extensions/omni_httpc/omni_sql/CMakeFiles/omni_sql.dir/all] Error 2

@schonfinkel schonfinkel self-requested a review June 8, 2025 20:13
@Ma27
Copy link
Member

Ma27 commented Jun 9, 2025

Did that. This makes Omnigres build. I still think that their build system should do better there, though.

Maybe file a bug upstream first?

I think I'd prefer to have them look at this before we add package-specific hacks into our builders.

@wolfgangwalther
Copy link
Contributor Author

Maybe file a bug upstream first?

I think @yrashk is aware, according to his reaction to #407920 (comment). But I could also file an issue, if that's preferred, @yrashk?

Copy link
Member

@Ma27 Ma27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One optional suggestion.

I guess I'll rebuild the extensions with it now and see if I catch something obvious. But if that's not the case, I'd say that we should ship it: I'm very much in favor of getting rid fo the pathsToLink-hack asap, but I do agree that this is a valid correctness fix.

That being said, if a bit more testing was successful, I'd prefer to merge it rather quick because that's still the kind of change I'd like to see on unstable for a while instead of pushing this right before 25.11.

EDIT: right, this doesn't even rebuild most extensions.

@Ma27
Copy link
Member

Ma27 commented Jun 9, 2025

EDIT: right, this doesn't even rebuild most extensions.

OK yeah rebuilt a bunch of things with postgresql.withPackages instead of postgresql to see if theyr build-systems fail (this is e.g. relevant when building these outside of Nix with a nixpkgs-supplied postgresql and it looks good.

@wolfgangwalther feel free to apply my suggestion if you agree and merge.

@wolfgangwalther
Copy link
Contributor Author

feel free to apply my suggestion if you agree and merge.

Before we can merge, we'll need to figure out the build failure in #407920 (comment), because even with the pathsToLink, this PR still breaks omnigres on darwin.

Previously, pg_config would report the paths of the underlying
postgresql derivation and not the paths of the buildEnv that
postgresql.withPackages creates.

That's a problem when users of pg_config use it to find PostgreSQL's
sharedir, in which they'd like to find the extensions added via
withPackages. Those are only linked into the created buildEnv, but not
available in the postgresql derivation.

By providing our own nix-support/pg_config.env file, we can swap out
those paths. We also do the same for the -man output, because this
output is linked into buildEnv as well. Other paths, which are not
available in the buildEnv environment, will still link to the original
postgresql derivation. Win-win!
@wolfgangwalther wolfgangwalther force-pushed the postgresql-with-pg-config branch from 18f29ae to ef5af85 Compare June 9, 2025 18:59
@wolfgangwalther
Copy link
Contributor Author

The problem is that pg_config.nix does a replaceVarsWith for postgresql-dev = lib.getDev finalPackage. This is to get the PGXS path correct. But the withPackages result does not have a dev output, so this returns the default output.

Before this PR, the wrong pg_config returns the right PGXS path:

PGXS = /nix/store/578hp6h741gwi4wh1nx6rflsnicp2hwn-postgresql-17.5-dev/lib/pgxs/src/makefiles/pgxs.mk

After this PR, the right pg_config returns the wrong PGXS path:

PGXS = /nix/store/06ikdy05psn72zbzdrg7yw2difssv11g-postgresql-and-plugins-17.5/lib/pgxs/src/makefiles/pgxs.mk

(this just doesn't exist)

I wonder why the build system doesn't fail much earlier.

@wolfgangwalther
Copy link
Contributor Author

I am able to fix the build failure by passing postgresql's dev output through on withPackages. This makes sense, because we want the result of withPackages to behave as much as a regular postgresql as possible.

This fixes PGXS and also eventually the omnigres build - but unfortunately, omnigres is now confused again about where to find plpython3. To fix that, I need to revert the removal of the cmake flags.

So while the end-result is a much more correct pg_config output for withPackages (and still something that we should do, because being correct here should avoid problems down the road...) - it's still not satisfying.

@wolfgangwalther
Copy link
Contributor Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 407920
Commit: 4aa8b35fdc04513021245eeab968662a7c490576


x86_64-linux

⏩ 4 packages marked as broken and skipped:
  • froide
  • froide.dist
  • python312Packages.froide
  • python312Packages.froide.dist
❌ 20 packages failed to build:
  • open-webui
  • open-webui.dist
  • private-gpt
  • private-gpt.dist
  • python312Packages.llama-index-vector-stores-postgres
  • python312Packages.llama-index-vector-stores-postgres.dist
  • python312Packages.pgvector
  • python312Packages.pgvector.dist
  • python312Packages.private-gpt
  • python312Packages.private-gpt.dist
  • python312Packages.txtai
  • python312Packages.txtai.dist
  • python313Packages.llama-index-vector-stores-postgres
  • python313Packages.llama-index-vector-stores-postgres.dist
  • python313Packages.pgvector
  • python313Packages.pgvector.dist
  • python313Packages.private-gpt
  • python313Packages.private-gpt.dist
  • python313Packages.txtai
  • python313Packages.txtai.dist
✅ 19 packages built:
  • postgresql14Packages.omnigres
  • postgresql15Packages.omnigres
  • postgresql16Packages.omnigres
  • postgresqlPackages.omnigres (postgresql17Packages.omnigres)
  • postgresql_13_jit
  • postgresql_14_jit
  • postgresql_15_jit
  • postgresql_16_jit
  • postgresql_jit (postgresql_17_jit)
  • python312Packages.langgraph
  • python312Packages.langgraph-checkpoint-postgres
  • python312Packages.langgraph-checkpoint-postgres.dist
  • python312Packages.langgraph-prebuilt
  • python312Packages.langgraph-prebuilt.dist
  • python312Packages.langgraph.dist
  • python313Packages.langgraph-checkpoint-postgres
  • python313Packages.langgraph-checkpoint-postgres.dist
  • python313Packages.langgraph-prebuilt
  • python313Packages.langgraph-prebuilt.dist

aarch64-linux

⏩ 4 packages marked as broken and skipped:
  • froide
  • froide.dist
  • python312Packages.froide
  • python312Packages.froide.dist
❌ 18 packages failed to build:
  • private-gpt
  • private-gpt.dist
  • python312Packages.llama-index-vector-stores-postgres
  • python312Packages.llama-index-vector-stores-postgres.dist
  • python312Packages.pgvector
  • python312Packages.pgvector.dist
  • python312Packages.private-gpt
  • python312Packages.private-gpt.dist
  • python312Packages.txtai
  • python312Packages.txtai.dist
  • python313Packages.llama-index-vector-stores-postgres
  • python313Packages.llama-index-vector-stores-postgres.dist
  • python313Packages.pgvector
  • python313Packages.pgvector.dist
  • python313Packages.private-gpt
  • python313Packages.private-gpt.dist
  • python313Packages.txtai
  • python313Packages.txtai.dist
✅ 19 packages built:
  • postgresql14Packages.omnigres
  • postgresql15Packages.omnigres
  • postgresql16Packages.omnigres
  • postgresqlPackages.omnigres (postgresql17Packages.omnigres)
  • postgresql_13_jit
  • postgresql_14_jit
  • postgresql_15_jit
  • postgresql_16_jit
  • postgresql_jit (postgresql_17_jit)
  • python312Packages.langgraph
  • python312Packages.langgraph-checkpoint-postgres
  • python312Packages.langgraph-checkpoint-postgres.dist
  • python312Packages.langgraph-prebuilt
  • python312Packages.langgraph-prebuilt.dist
  • python312Packages.langgraph.dist
  • python313Packages.langgraph-checkpoint-postgres
  • python313Packages.langgraph-checkpoint-postgres.dist
  • python313Packages.langgraph-prebuilt
  • python313Packages.langgraph-prebuilt.dist

x86_64-darwin

✅ 9 packages built:
  • postgresql14Packages.omnigres
  • postgresql15Packages.omnigres
  • postgresql16Packages.omnigres
  • postgresqlPackages.omnigres (postgresql17Packages.omnigres)
  • postgresql_13_jit
  • postgresql_14_jit
  • postgresql_15_jit
  • postgresql_16_jit
  • postgresql_jit (postgresql_17_jit)

aarch64-darwin

✅ 9 packages built:
  • postgresql14Packages.omnigres
  • postgresql15Packages.omnigres
  • postgresql16Packages.omnigres
  • postgresqlPackages.omnigres (postgresql17Packages.omnigres)
  • postgresql_13_jit
  • postgresql_14_jit
  • postgresql_15_jit
  • postgresql_16_jit
  • postgresql_jit (postgresql_17_jit)

Error logs: `x86_64-linux`
python312Packages.pgvector
E   [SQL: CREATE EXTENSION IF NOT EXISTS vector]
E   (Background on this error at: https://sqlalche.me/e/20/tw8g)
=========================== short test summary info ============================
ERROR tests/test_django.py - django.db.utils.NotSupportedError: extension "vector" is not available
ERROR tests/test_peewee.py - peewee.NotSupportedError: extension "vector" is not available
ERROR tests/test_psycopg.py - psycopg.errors.FeatureNotSupported: extension "vector" is not available
ERROR tests/test_psycopg2.py - psycopg2.errors.FeatureNotSupported: extension "vector" is not available
ERROR tests/test_sqlmodel.py - sqlalchemy.exc.NotSupportedError: (psycopg2.errors.FeatureNotSupported) ext...
!!!!!!!!!!!!!!!!!!! Interrupted: 5 errors during collection !!!!!!!!!!!!!!!!!!!!
============================== 5 errors in 2.75s ===============================
stopping postgresql
waiting for server to shut down...2025-06-11 14:33:35.043 UTC [284] LOG:  received fast shutdown request
.2025-06-11 14:33:35.045 UTC [284] LOG:  aborting any active transactions
2025-06-11 14:33:35.047 UTC [284] LOG:  background worker "logical replication launcher" (PID 290) exited with exit code 1
2025-06-11 14:33:35.047 UTC [285] LOG:  shutting down
2025-06-11 14:33:35.049 UTC [285] LOG:  checkpoint starting: shutdown immediate
2025-06-11 14:33:35.730 UTC [285] LOG:  checkpoint complete: wrote 934 buffers (5.7%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.104 s, sync=0.568 s, total=0.683 s; sync files=308, longest=0.018 s, average=0.002 s; distance=4259 kB, estimate=4259 kB; lsn=0/1915758, redo lsn=0/1915758
2025-06-11 14:33:35.739 UTC [284] LOG:  database system is shut down
 done
server stopped
python313Packages.pgvector
E   [SQL: CREATE EXTENSION IF NOT EXISTS vector]
E   (Background on this error at: https://sqlalche.me/e/20/tw8g)
=========================== short test summary info ============================
ERROR tests/test_django.py - django.db.utils.NotSupportedError: extension "vector" is not available
ERROR tests/test_peewee.py - peewee.NotSupportedError: extension "vector" is not available
ERROR tests/test_psycopg.py - psycopg.errors.FeatureNotSupported: extension "vector" is not available
ERROR tests/test_psycopg2.py - psycopg2.errors.FeatureNotSupported: extension "vector" is not available
ERROR tests/test_sqlmodel.py - sqlalchemy.exc.NotSupportedError: (psycopg2.errors.FeatureNotSupported) ext...
!!!!!!!!!!!!!!!!!!! Interrupted: 5 errors during collection !!!!!!!!!!!!!!!!!!!!
============================== 5 errors in 2.67s ===============================
stopping postgresql
waiting for server to shut down....2025-06-11 14:33:35.097 UTC [284] LOG:  received fast shutdown request
2025-06-11 14:33:35.098 UTC [284] LOG:  aborting any active transactions
2025-06-11 14:33:35.100 UTC [284] LOG:  background worker "logical replication launcher" (PID 290) exited with exit code 1
2025-06-11 14:33:35.100 UTC [285] LOG:  shutting down
2025-06-11 14:33:35.102 UTC [285] LOG:  checkpoint starting: shutdown immediate
2025-06-11 14:33:35.795 UTC [285] LOG:  checkpoint complete: wrote 934 buffers (5.7%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.100 s, sync=0.585 s, total=0.695 s; sync files=308, longest=0.018 s, average=0.002 s; distance=4259 kB, estimate=4259 kB; lsn=0/1915758, redo lsn=0/1915758
2025-06-11 14:33:35.803 UTC [284] LOG:  database system is shut down
 done
server stopped

Error logs: `aarch64-linux`
python312Packages.pgvector
E   [SQL: CREATE EXTENSION IF NOT EXISTS vector]
E   (Background on this error at: https://sqlalche.me/e/20/tw8g)
=========================== short test summary info ============================
ERROR tests/test_django.py - django.db.utils.NotSupportedError: extension "vector" is not available
ERROR tests/test_peewee.py - peewee.NotSupportedError: extension "vector" is not available
ERROR tests/test_psycopg.py - psycopg.errors.FeatureNotSupported: extension "vector" is not available
ERROR tests/test_psycopg2.py - psycopg2.errors.FeatureNotSupported: extension "vector" is not available
ERROR tests/test_sqlmodel.py - sqlalchemy.exc.NotSupportedError: (psycopg2.errors.FeatureNotSupported) ext...
!!!!!!!!!!!!!!!!!!! Interrupted: 5 errors during collection !!!!!!!!!!!!!!!!!!!!
============================== 5 errors in 2.73s ===============================
stopping postgresql
waiting for server to shut down....2025-06-11 14:33:33.351 UTC [282] LOG:  received fast shutdown request
2025-06-11 14:33:33.354 UTC [282] LOG:  aborting any active transactions
2025-06-11 14:33:33.356 UTC [282] LOG:  background worker "logical replication launcher" (PID 288) exited with exit code 1
2025-06-11 14:33:33.357 UTC [283] LOG:  shutting down
2025-06-11 14:33:33.357 UTC [283] LOG:  checkpoint starting: shutdown immediate
2025-06-11 14:33:33.425 UTC [283] LOG:  checkpoint complete: wrote 934 buffers (5.7%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.019 s, sync=0.048 s, total=0.068 s; sync files=308, longest=0.003 s, average=0.001 s; distance=4259 kB, estimate=4259 kB; lsn=0/1915748, redo lsn=0/1915748
2025-06-11 14:33:33.439 UTC [282] LOG:  database system is shut down
 done
server stopped
python313Packages.pgvector
E   [SQL: CREATE EXTENSION IF NOT EXISTS vector]
E   (Background on this error at: https://sqlalche.me/e/20/tw8g)
=========================== short test summary info ============================
ERROR tests/test_django.py - django.db.utils.NotSupportedError: extension "vector" is not available
ERROR tests/test_peewee.py - peewee.NotSupportedError: extension "vector" is not available
ERROR tests/test_psycopg.py - psycopg.errors.FeatureNotSupported: extension "vector" is not available
ERROR tests/test_psycopg2.py - psycopg2.errors.FeatureNotSupported: extension "vector" is not available
ERROR tests/test_sqlmodel.py - sqlalchemy.exc.NotSupportedError: (psycopg2.errors.FeatureNotSupported) ext...
!!!!!!!!!!!!!!!!!!! Interrupted: 5 errors during collection !!!!!!!!!!!!!!!!!!!!
============================== 5 errors in 2.67s ===============================
stopping postgresql
waiting for server to shut down....2025-06-11 14:33:34.234 UTC [282] LOG:  received fast shutdown request
2025-06-11 14:33:34.235 UTC [282] LOG:  aborting any active transactions
2025-06-11 14:33:34.237 UTC [282] LOG:  background worker "logical replication launcher" (PID 288) exited with exit code 1
2025-06-11 14:33:34.238 UTC [283] LOG:  shutting down
2025-06-11 14:33:34.238 UTC [283] LOG:  checkpoint starting: shutdown immediate
2025-06-11 14:33:34.306 UTC [283] LOG:  checkpoint complete: wrote 934 buffers (5.7%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.019 s, sync=0.049 s, total=0.069 s; sync files=308, longest=0.002 s, average=0.001 s; distance=4259 kB, estimate=4259 kB; lsn=0/1915748, redo lsn=0/1915748
2025-06-11 14:33:34.322 UTC [282] LOG:  database system is shut down
 done
server stopped

This breaks python3Packages.pgvector it seems. Didn't investigate further, yet.

Copy link
Member

@Ma27 Ma27 Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought these were supposed to disappear?

EDIT: OK, I missed the part from your previosu comment.
But I must ask: why bother? It looks like we end up with the exact same state as before, but with package-specific hacks in our builder. At this stage I wonder if it's preferable to let upstream figure out how to fix their build-system and then we can apply the correctness-fix, but without the pathsToLink-hacks.

Right now this is effectively dead code from the beginning and if omnigres stays that way, it's always kinda undefined if we can kill it in the future or not (which is exactly what I don't want for e.g. the pathsToLInk stuff).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, at this stage I can't really tell whether I had to reintroduce this because omnigres' build system is at fault - or because I'm still doing something wrong with this correctness fix. The fact that python3Packages.pgvector breaks with something similar is an indication, that I might still be missing something.

So, my goal is to find the problem there, eventually, and then see what remains. Can we then remove the cmake flags? Maybe even the pathsToLink? I can't tell right now, but I won't abandon the PR, yet :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I owe you an apology: to me, the previous comments read as if the plan was to go with both the CMake flags and the changes to the postgresql build-system (+finding a fix for pgvector) which I do think is a bad idea for the reasons outlined above.

I do agree that doing this fix is valid, but I'd like to only see it in nixpkgs if the fix is actualyl solving the problem (this is especially true for the pathsToLink-part).

If that was the plan all along, then go ahead ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Longer term, the need for Omnigres' build environment to do the copying will go away – Postgres 18 seemingly solves the problems of shipping extensions outside of the hard-coded path. However, we still support Postgres 14 and it will take a few years until 18 will be the minimum supported version.

I think for us, a shorter term good solution would be to split building of extensions and their in-source-tree use (for tests and live experiments).

Building Omnigres extensions does not require a copy of the directory. Testing does – but only in the sense that we did not want to pollute the build directory with built artifacts.

Now I wonder if we can reverse on this decision and move the problem into a different place. We can install extensions into the hard-coded directory (returned by pg_config) and add a target to clean it up (perhaps by reinstalling the version of Postgres we prepared).

With respect to Nixpkgs, in this case, as long as the extensions and libdir directories returned by pg_config would be writable, this should work!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With respect to Nixpkgs, in this case, as long as the extensions and libdir directories returned by pg_config would be writable, this should work!

In Nixpkgs, all paths returned by pg_config will always be read-only. There is no way for a writeable path here.

But we already pass some writeable directories as install paths. Could omnigres do this as an installCheck? Aka install in the proper location and then do the tests with the installed result?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do currently take PostgreSQL_TARGET_PACKAGE_LIBRARY_DIR as an override for pg_config --pkglibdir and PostgreSQL_TARGET_EXTENSION_DIR as an override for $(pg_config --sharedir)/extension.

Does this help?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, that's what I mean. We're already using that to set the install location. But I don't think omnigres is using this for more than installation, right?

We currently have two issues with omnigres' build:

  • We need to force the SHAREDIR returned by pg_config to contain proper directories for /share/postgresql/extensions, /share/postgresql/timezonesets and /share/postgresql/tsearch_data, but would like some of them to be symlinks only. Right now omnigres seems to copy the symlink, and thus ends up with directories into the read-only nix-store. If omnigres' build system would create those directories itself and then copy the files it needs (instead of copying the directories, which are symlinks), then this would go away.
  • We somehow need to pass -DPostgreSQL_EXTENSION_DIR and -DPostgreSQL_PACKAGE_LIBRARY_DIR even though pg_config should return the correct paths. We have a similar failure for pgvector, so this might be a problem on our side. We don't know, yet.

To solve the first problem (bad copying), you proposed to get rid of copying entirely and suggested to instead temporarily install into the paths returned by pg_config. That won't work for us. I suggested to install into the TARGET directories you mentioned - but of course, installing temporarily, then testing, then removing, then installing properly... makes little sense. Thus my question, whether you could first install - and then run the tests.

Hope that clears it up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We somehow need to pass -DPostgreSQL_EXTENSION_DIR and -DPostgreSQL_PACKAGE_LIBRARY_DIR even though pg_config should return the correct paths. We have a similar failure for pgvector, so this might be a problem on our side. We don't know, yet.

Yeah, this was a problem with my change, that should be fixed in the latest push here. I can build both pgvector and omnigres now, without needing the two cmake flags above.

But the copying of symlinks problem still persists, ofc.

@wolfgangwalther wolfgangwalther force-pushed the postgresql-with-pg-config branch from 4aa8b35 to 7490876 Compare June 13, 2025 20:49
@github-actions github-actions bot added 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 2501-5000 This PR causes many rebuilds on Darwin and should target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. labels Jun 13, 2025
@wolfgangwalther
Copy link
Contributor Author

wolfgangwalther commented Jun 13, 2025

So my intermediate step of passing the dev output on made things worse. But I have the correct fix now: PGXS just must be stored during the build-process, which also makes a lot more sense than having this specific knowledge in the pg_config script.

Running nixpkgs-review now, but I think that should be all green without the cmake flags (which was the original goal!). We still need the pathsToLinks stuff as mentioned in the thread, until omnigres can solve that.

So right now, this PR improves correctness for everyone, removes one workaround for omnigres and adds another for it. So at least a net positive now.

Edit: OK, nixpkgs-review won't work with those rebuilds. But I can rebuild the same packages as before.

@wolfgangwalther
Copy link
Contributor Author

Builds look fine, so far, but we are back to omnigres failing on darwin as mentioned in #407920 (comment). I thought I had fixed it temporarily, but that wasn't the case because my "propagate dev output" change essentially just reverted everything I did previously.

So still need to investigate why omnigres can suddenly not find symbols on darwin.

@wolfgangwalther
Copy link
Contributor Author

The following are my steps taken while debugging this, but I found and pushed a fix. I'll still leave this here for the curious.


The PostgreSQL failure for MacOS is exactly the same as in omnigres/omnigres#618.

We get this:

-- Found postgres binary at /nix/store/81r3bq17r3zv2iz1mpsl2bgdysf0qi2j-postgresql-and-plugins-17.5/bin/postgres
-- PostgreSQL version PostgreSQL 17.5 found
-- PostgreSQL package library directory: /nix/store/81r3bq17r3zv2iz1mpsl2bgdysf0qi2j-postgresql-and-plugins-17.5/lib
-- PostgreSQL libraries: -lpgcommon -lpgport -lzstd -llz4 -lxml2 -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lm
-- PostgreSQL extension directory: /nix/store/81r3bq17r3zv2iz1mpsl2bgdysf0qi2j-postgresql-and-plugins-17.5/share/postgresql/extension
-- PostgreSQL linker options: -isysroot;/nix/store/w41ks2baj649algkjnbh9746cprrnr1k-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk;-L/nix/store/0mr2w5y44448szqy0al77p26y9cirn35-llvm-19.1.7-lib/lib;-L/nix/store/fy1l8akbxlmi6z7k92aiyqnxf81xwf9h-libxml2-2.13.8/lib;-L/nix/store/dhsgmjyvdi7bmirql4jdbq56ls12gymb-lz4-1.10.0-lib/lib;-L/nix/store/bh18spw9agz58x6sycrkpr4piam7jb1d-zstd-1.5.7/lib;-Wl,-dead_strip_dylibs,
-- PostgreSQL shared linker options: -isysroot /nix/store/w41ks2baj649algkjnbh9746cprrnr1k-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -L/nix/store/0mr2w5y44448szqy0al77p26y9cirn35-llvm-19.1.7-lib/lib -L/nix/store/fy1l8akbxlmi6z7k92aiyqnxf81xwf9h-libxml2-2.13.8/lib -L/nix/store/dhsgmjyvdi7bmirql4jdbq56ls12gymb-lz4-1.10.0-lib/lib -L/nix/store/bh18spw9agz58x6sycrkpr4piam7jb1d-zstd-1.5.7/lib -Wl,-dead_strip_dylibs

Before this PR, we get this:

-- Found postgres binary at /nix/store/w6cjhp0006p6dwmlcp1klz3sayylg4l2-postgresql-17.5/bin/postgres
-- PostgreSQL version PostgreSQL 17.5 found
-- PostgreSQL package library directory: /nix/store/vfbfv82pvncn16k3qfpqkkl634x2n79y-postgresql-and-plugins-17.5/lib/
-- PostgreSQL libraries: -lpgcommon -lpgport -lzstd -llz4 -lxml2 -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lm
-- PostgreSQL extension directory: /nix/store/vfbfv82pvncn16k3qfpqkkl634x2n79y-postgresql-and-plugins-17.5/share/postgresql/extension
-- PostgreSQL linker options: -isysroot;/nix/store/w41ks2baj649algkjnbh9746cprrnr1k-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk;-L/nix/store/0mr2w5y44448szqy0al77p26y9cirn35-llvm-19.1.7-lib/lib;-L/nix/store/fy1l8akbxlmi6z7k92aiyqnxf81xwf9h-libxml2-2.13.8/lib;-L/nix/store/dhsgmjyvdi7bmirql4jdbq56ls12gymb-lz4-1.10.0-lib/lib;-L/nix/store/bh18spw9agz58x6sycrkpr4piam7jb1d-zstd-1.5.7/lib;-Wl,-dead_strip_dylibs,
-- PostgreSQL shared linker options: -isysroot /nix/store/w41ks2baj649algkjnbh9746cprrnr1k-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -L/nix/store/0mr2w5y44448szqy0al77p26y9cirn35-llvm-19.1.7-lib/lib -L/nix/store/fy1l8akbxlmi6z7k92aiyqnxf81xwf9h-libxml2-2.13.8/lib -L/nix/store/dhsgmjyvdi7bmirql4jdbq56ls12gymb-lz4-1.10.0-lib/lib -L/nix/store/bh18spw9agz58x6sycrkpr4piam7jb1d-zstd-1.5.7/lib -Wl,-dead_strip_dylibs

The only difference is in the path to /bin/postgres. That's precisely the fix we're making here.

I think this is related to this line:
https://github.com/omnigres/omnigres/blob/d347be5ae1d79645ac277d19080eacba7b229cf8/cmake/PostgreSQLExtension.cmake#L246C50-L246C63

I remember having seen this a while ago elsewhere. The problem is, that .../bin/postgres is not the real postgres binary, but a wrapper. Ah, right we do this:

+ lib.optionalString stdenv'.hostPlatform.isDarwin ''
# The darwin specific Makefile for PGXS contains a reference to the postgres
# binary. Some extensions (here: postgis), which are able to set bindir correctly
# to their own output for installation, will then fail to find "postgres" during linking.
substituteInPlace "$dev/lib/pgxs/src/Makefile.port" \
--replace-fail '-bundle_loader $(bindir)/postgres' "-bundle_loader $out/bin/postgres"
''

IIUC, the PostgreSQLExtension.cmake file in omnigres' repo tries to do the same as the pgxs Makefile - but without using the latter. Since we need to patch the Makefile.. we probably need to deal with this as well.

Patching the bundle-loader line to point at the real binary instead of the wrapper fixes it.

@wolfgangwalther
Copy link
Contributor Author

The only inconsistency remaining is now the pathToLinks wrt omnigres symlink handling during copy.

@wolfgangwalther
Copy link
Contributor Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 407920 --package postgresql_16_jit --package postgresql15Packages.omnigres --package python312Packages.langgraph --package open-webui --package postgresql16Packages.omnigres --package postgresql_14_jit --package python312Packages.langgraph-checkpoint-postgres --package python313Packages.llama-index-vector-stores-postgres --package python313Packages.private-gpt --package postgresql_13_jit --package python312Packages.private-gpt --package postgresql_jit --package private-gpt --package postgresqlPackages.omnigres --package python312Packages.pgvector --package python313Packages.txtai --package python313Packages.langgraph-prebuilt --package python312Packages.txtai --package postgresql_15_jit --package python313Packages.pgvector --package python313Packages.langgraph-checkpoint-postgres --package postgresql14Packages.omnigres --package python312Packages.langgraph-prebuilt --package python312Packages.llama-index-vector-stores-postgres
Commit: 2b874ec5f71507f4b2b7b909253f07b7610ebfc6


x86_64-linux

✅ 39 packages built:
  • open-webui
  • open-webui.dist (open-webui.dist.dist)
  • postgresql14Packages.omnigres
  • postgresql15Packages.omnigres
  • postgresql16Packages.omnigres
  • postgresqlPackages.omnigres
  • postgresql_13_jit
  • postgresql_14_jit
  • postgresql_15_jit
  • postgresql_16_jit
  • postgresql_jit
  • private-gpt
  • private-gpt.dist (private-gpt.dist.dist)
  • python312Packages.langgraph
  • python312Packages.langgraph-checkpoint-postgres
  • python312Packages.langgraph-checkpoint-postgres.dist (python312Packages.langgraph-checkpoint-postgres.dist.dist)
  • python312Packages.langgraph-prebuilt
  • python312Packages.langgraph-prebuilt.dist (python312Packages.langgraph-prebuilt.dist.dist)
  • python312Packages.langgraph.dist (python312Packages.langgraph.dist.dist)
  • python312Packages.llama-index-vector-stores-postgres
  • python312Packages.llama-index-vector-stores-postgres.dist (python312Packages.llama-index-vector-stores-postgres.dist.dist)
  • python312Packages.pgvector
  • python312Packages.pgvector.dist (python312Packages.pgvector.dist.dist)
  • python312Packages.private-gpt
  • python312Packages.private-gpt.dist (python312Packages.private-gpt.dist.dist)
  • python312Packages.txtai
  • python312Packages.txtai.dist (python312Packages.txtai.dist.dist)
  • python313Packages.langgraph-checkpoint-postgres
  • python313Packages.langgraph-checkpoint-postgres.dist (python313Packages.langgraph-checkpoint-postgres.dist.dist)
  • python313Packages.langgraph-prebuilt
  • python313Packages.langgraph-prebuilt.dist (python313Packages.langgraph-prebuilt.dist.dist)
  • python313Packages.llama-index-vector-stores-postgres
  • python313Packages.llama-index-vector-stores-postgres.dist (python313Packages.llama-index-vector-stores-postgres.dist.dist)
  • python313Packages.pgvector
  • python313Packages.pgvector.dist (python313Packages.pgvector.dist.dist)
  • python313Packages.private-gpt
  • python313Packages.private-gpt.dist (python313Packages.private-gpt.dist.dist)
  • python313Packages.txtai
  • python313Packages.txtai.dist (python313Packages.txtai.dist.dist)

aarch64-linux

✅ 37 packages built:
  • postgresql14Packages.omnigres
  • postgresql15Packages.omnigres
  • postgresql16Packages.omnigres
  • postgresqlPackages.omnigres
  • postgresql_13_jit
  • postgresql_14_jit
  • postgresql_15_jit
  • postgresql_16_jit
  • postgresql_jit
  • private-gpt
  • private-gpt.dist (private-gpt.dist.dist)
  • python312Packages.langgraph
  • python312Packages.langgraph-checkpoint-postgres
  • python312Packages.langgraph-checkpoint-postgres.dist (python312Packages.langgraph-checkpoint-postgres.dist.dist)
  • python312Packages.langgraph-prebuilt
  • python312Packages.langgraph-prebuilt.dist (python312Packages.langgraph-prebuilt.dist.dist)
  • python312Packages.langgraph.dist (python312Packages.langgraph.dist.dist)
  • python312Packages.llama-index-vector-stores-postgres
  • python312Packages.llama-index-vector-stores-postgres.dist (python312Packages.llama-index-vector-stores-postgres.dist.dist)
  • python312Packages.pgvector
  • python312Packages.pgvector.dist (python312Packages.pgvector.dist.dist)
  • python312Packages.private-gpt
  • python312Packages.private-gpt.dist (python312Packages.private-gpt.dist.dist)
  • python312Packages.txtai
  • python312Packages.txtai.dist (python312Packages.txtai.dist.dist)
  • python313Packages.langgraph-checkpoint-postgres
  • python313Packages.langgraph-checkpoint-postgres.dist (python313Packages.langgraph-checkpoint-postgres.dist.dist)
  • python313Packages.langgraph-prebuilt
  • python313Packages.langgraph-prebuilt.dist (python313Packages.langgraph-prebuilt.dist.dist)
  • python313Packages.llama-index-vector-stores-postgres
  • python313Packages.llama-index-vector-stores-postgres.dist (python313Packages.llama-index-vector-stores-postgres.dist.dist)
  • python313Packages.pgvector
  • python313Packages.pgvector.dist (python313Packages.pgvector.dist.dist)
  • python313Packages.private-gpt
  • python313Packages.private-gpt.dist (python313Packages.private-gpt.dist.dist)
  • python313Packages.txtai
  • python313Packages.txtai.dist (python313Packages.txtai.dist.dist)

x86_64-darwin

✅ 19 packages built:
  • postgresql14Packages.omnigres
  • postgresql15Packages.omnigres
  • postgresql16Packages.omnigres
  • postgresqlPackages.omnigres
  • postgresql_13_jit
  • postgresql_14_jit
  • postgresql_15_jit
  • postgresql_16_jit
  • postgresql_jit
  • python312Packages.langgraph
  • python312Packages.langgraph-checkpoint-postgres
  • python312Packages.langgraph-checkpoint-postgres.dist (python312Packages.langgraph-checkpoint-postgres.dist.dist)
  • python312Packages.langgraph-prebuilt
  • python312Packages.langgraph-prebuilt.dist (python312Packages.langgraph-prebuilt.dist.dist)
  • python312Packages.langgraph.dist (python312Packages.langgraph.dist.dist)
  • python313Packages.langgraph-checkpoint-postgres
  • python313Packages.langgraph-checkpoint-postgres.dist (python313Packages.langgraph-checkpoint-postgres.dist.dist)
  • python313Packages.langgraph-prebuilt
  • python313Packages.langgraph-prebuilt.dist (python313Packages.langgraph-prebuilt.dist.dist)

aarch64-darwin

✅ 19 packages built:
  • postgresql14Packages.omnigres
  • postgresql15Packages.omnigres
  • postgresql16Packages.omnigres
  • postgresqlPackages.omnigres
  • postgresql_13_jit
  • postgresql_14_jit
  • postgresql_15_jit
  • postgresql_16_jit
  • postgresql_jit
  • python312Packages.langgraph
  • python312Packages.langgraph-checkpoint-postgres
  • python312Packages.langgraph-checkpoint-postgres.dist (python312Packages.langgraph-checkpoint-postgres.dist.dist)
  • python312Packages.langgraph-prebuilt
  • python312Packages.langgraph-prebuilt.dist (python312Packages.langgraph-prebuilt.dist.dist)
  • python312Packages.langgraph.dist (python312Packages.langgraph.dist.dist)
  • python313Packages.langgraph-checkpoint-postgres
  • python313Packages.langgraph-checkpoint-postgres.dist (python313Packages.langgraph-checkpoint-postgres.dist.dist)
  • python313Packages.langgraph-prebuilt
  • python313Packages.langgraph-prebuilt.dist (python313Packages.langgraph-prebuilt.dist.dist)

@wolfgangwalther wolfgangwalther changed the base branch from master to staging June 24, 2025 08:01
@nixpkgs-ci nixpkgs-ci bot closed this Jun 24, 2025
@wolfgangwalther
Copy link
Contributor Author

Hmm... odd. My force-push and nixpkgs-ci closing the PR temporarily happened at the same time - and now the PR can't be re-opened anymore.

Will open a new PR, targeting staging due to the rebuilds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 2501-5000 This PR causes many rebuilds on Darwin and should target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 12.approvals: 2 This PR was reviewed and approved by two persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants