Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgresql: replace pg_config with custom script #388807

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wolfgangwalther
Copy link
Contributor

By replacing upstream's pg_config binary with a shell script, we:

  • gain the ability to run pg_config easily when cross-compiling,
  • can remove the fake pg_config in the default output,
  • can remove the pg_config wrapper script dealing with special cases.

Some 20 years ago, pg_config was a shell script upstream, too. It was changed to a binary, when it was made "relocatable", so it would return paths depending on the location of the "postgres" binary. However, this is exactly the thing that just hurts us in nixpkgs - we don't want those paths to change, we want them to always point at the right outputs. By writing the script ourselves, this becomes a lot less painful.

This approach means more lines of codes, but all of them are dead simple and we have a lot less complexity overall.

Additionally, pg_config is now made a separate derivation, only exposed as "postgresql.pg_config". This has the nice side-effect, that all users of postgresql and libpq in nixpkgs must be very explicit about their dependency on pg_config. This gives a lot more visibility into the state of affairs regarding pkg-config support for libpq, which ultimately is the much better solution.


I only tested the postgresql extensions, so far - they all seem to work with this just fine. Everything outside the postgresql folder, I did not touch, yet.

TODO:

  • Fix all dependencies of postgresql and libpq, passing pg_config were needed.
  • Rebase on staging eventually.

Things done


Add a 👍 reaction to pull requests you find important.

@wolfgangwalther wolfgangwalther requested a review from rhelmot March 10, 2025 20:55
@@ -466,6 +461,8 @@ let
postgresql = this;
};

pg_config = buildPackages.callPackage ./pg_config.nix { inherit (finalAttrs) finalPackage; };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should make it work nicely for cross-compilation, @rhelmot. I tried a very simple extension in nix-build -A pkgsCross.x86_64-freebsd.postgresql.pkgs.pgtap, which built fine. It's a SQL-only extension, which essentially only depends on pg_config, so builds fine without your follow ups.

(had to cherry pick the --with-uuid=bsd change, ofc)

Currently, this extension fails to build on master, because pg_config can't be executed.

By replacing upstream's pg_config binary with a shell script, we:
- gain the ability to run pg_config easily when cross-compiling,
- can remove the fake pg_config in the default output,
- can remove the pg_config wrapper script dealing with special cases.

Some 20 years ago, pg_config *was* a shell script upstream, too. It was
changed to a binary, when it was made "relocatable", so it would return
paths depending on the location of the "postgres" binary. However, this
is exactly the thing that just hurts us in nixpkgs - we don't want those
paths to change, we want them to always point at the right outputs. By
writing the script ourselves, this becomes a lot less painful.

This approach means more lines of codes, but all of them are dead simple
and we have a lot less complexity overall.

Additionally, pg_config is now made a separate derivation, only exposed
as "postgresql.pg_config". This has the nice side-effect, that all users
of postgresql and libpq in nixpkgs must be very *explicit* about their
dependency on pg_config. This gives a lot more visibility into the state
of affairs regarding pkg-config support for libpq, which ultimately is
the much better solution.
@rhelmot
Copy link
Contributor

rhelmot commented Mar 10, 2025

This is fantastic, thank you so much for putting in the effort to build this! I will need to take some time to pick this onto my dev branch and test it out end-to-end.

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

Successfully merging this pull request may close these issues.

2 participants