From fcf27fe30d3f304175f14458918f2f97c35b9bcf Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Thu, 12 Sep 2024 19:15:29 +0200 Subject: [PATCH] postgresql: improve fake pg_config in default output 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 #341408 --- pkgs/servers/sql/postgresql/generic.nix | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkgs/servers/sql/postgresql/generic.nix b/pkgs/servers/sql/postgresql/generic.nix index dcb286dd3077ba..2518b088bd4f2e 100644 --- a/pkgs/servers/sql/postgresql/generic.nix +++ b/pkgs/servers/sql/postgresql/generic.nix @@ -188,10 +188,17 @@ let moveToOutput "bin/pg_config" "$dev" # To prevent a "pg_config: could not find own program executable" error, we fake # pg_config in the default output. - cat << EOF > "$out/bin/pg_config" && chmod +x "$out/bin/pg_config" + cat << 'EOF' > "$out/bin/pg_config" && chmod +x "$out/bin/pg_config" #!${stdenv'.shell} - echo The real pg_config can be found in the -dev output. - exit 1 + my_path="$(readlink -f -- "$0")" + on_path="$(readlink -f -- "$(which pg_config)")" + if [[ "$my_path" == "$on_path" ]]; then + echo The real pg_config can be found in the -dev output. + exit 1 + else + # There is a different pg_config in PATH, let's call this instead. + pg_config "$@" + fi EOF wrapProgram "$dev/bin/pg_config" --argv0 "$out/bin/pg_config"