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: improve fake pg_config in default output #341421

Merged
merged 2 commits into from
Sep 21, 2024

Conversation

wolfgangwalther
Copy link
Contributor

Description of changes

This fixes some build systems which look up the location of pg_config via the location of the postgres binary itself, e.g. timescaledb, instead of calling pg_config which is on PATH.

Since the -dev output is correctly placed before the default output of postgresql in PATH, we can rely on that and call "pg_config" from the default output's fake script. Only do that, when the one on PATH is actually a different file, though, to prevent infinite loops.

@Ma27 could you have a look?

Resolves #341408, CC @zoechi

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

pkgs/servers/sql/postgresql/generic.nix Outdated Show resolved Hide resolved
pkgs/servers/sql/postgresql/generic.nix Outdated Show resolved Hide resolved
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.

Looking good now, except for one remark.
Currently testing the change.

If no further issues arise during testing, we can merge as soon as this is fixed.

Thank you for your work!

pkgs/servers/sql/postgresql/pg_config.sh Outdated Show resolved Hide resolved
pkgs/servers/sql/postgresql/pg_config.sh Outdated Show resolved Hide resolved
@wolfgangwalther
Copy link
Contributor Author

I'm not happy with the current implementation, yet. Two reasons:

  • cycle detection to prevent infinite loops of calling pg_config.sh itself is potentially brittle when someone creates a wrapper script around it. This can be improved by setting an environment variable before calling the pg_config in PATH and checking that instead.
  • when I execute this script on my local system, I get entirely different values returned - because I do have a pg_config on path. This means the script will return potentially entirely wrong stuff. We can improve that, by calling pg_config --bindir first - and confirming that the pg_config we are about to call will actually "belong" to the same derivation that we're currently in.

@wolfgangwalther
Copy link
Contributor Author

Ok, the latest version is one that I am quite happy with, it should check all the boxes.

@wolfgangwalther wolfgangwalther marked this pull request as ready for review September 19, 2024 16:46
@wolfgangwalther wolfgangwalther force-pushed the postgresql-pg-config branch 2 times, most recently from d67e3f2 to 09d6dc3 Compare September 19, 2024 16:48
@wolfgangwalther
Copy link
Contributor Author

Ok, the latest version is one that I am quite happy with, it should check all the boxes.

Except that the prevention of infinite recursion doesn't work as expected, yet.

This fixes some build systems which look up the location of pg_config
via the location of the postgres binary itself, e.g. timescaledb,
instead of calling pg_config which is on PATH.

Since the -dev output is correctly placed before the default output of
postgresql in PATH, we can rely on that and call "pg_config" from the
default output's fake script. Only do that, when the one on PATH is
actually a different file, though, to prevent infinite loops.

Resolves NixOS#341408
@wolfgangwalther
Copy link
Contributor Author

Ok, the latest version is one that I am quite happy with, it should check all the boxes.

Except that the prevention of infinite recursion doesn't work as expected, yet.

But now it does, after the latest push.

@Ma27 Ma27 merged commit 9163a9f into NixOS:staging Sep 21, 2024
24 of 26 checks passed
@wolfgangwalther wolfgangwalther deleted the postgresql-pg-config branch September 21, 2024 12:09
@@ -0,0 +1,35 @@
# The real pg_config needs to be in the same path as the "postgres" binary
Copy link
Contributor

Choose a reason for hiding this comment

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

How come there's no shebang here? (Just browsing by as this is blocking my VERY (not) important desktop upgrades where I'm not even using TimeScale yet 😄 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #341421 (comment), the shebang should be added by writeShellApplication automatically.

Copy link
Member

Choose a reason for hiding this comment

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

fwiw I built this locally and tested all cases we came up with and covered before merging.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Ma27 No doubt it'd work. If there's no shebang it'll run in the executing shell. I was just curious why it's omitted.

I usually use writeScriptBin, stick a shebang in the file as
#! /usr/bin/env bash
then prepend a shebang in Nix with a specified version (second shebang is effectively ignored then). The reason being editor tooling reading the shebang to know what highlights and checks to apply.

Sorry I've been up all night and was just curious, call it bikeshedding2.0 in hindsight 😸

Thanks for the replies!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason being editor tooling reading the shebang to know what highlights and checks to apply.

I thought about that, too, and briefly wondered whether to add a # shellcheck shell=bash directive to be able to run shellcheck directly on the file. But since writeShellApplication includes shellchecking, I didn't see the need for that. My editor highlights correctly without the shebang, too.

But yeah, I can see this as a valid reason to do it.

Lillecarl pushed a commit to Lillecarl/nixos that referenced this pull request Sep 24, 2024
pg_config is broken and it's bothersome to override because postgres
packages(plugins) are their own package scope so we can't simply
override some bullshit fix for timescale without overriding the entirety
of our selected postgres version. Which doesn't really matter because
we're enabling Python support in postgres and building it anyways, but
it's not right!
anpin added a commit to anpin/nixpkgs that referenced this pull request Oct 7, 2024
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.

3 participants