fix nix packaging#440
Conversation
On NixOS, running dynamically linked programs intended for generic Linux environments is not possible. This patch allows for configuring a binary path at build time so that the Postgres version from the nixpkgs can be used instead.
| "log_min_messages": "PANIC", // Only log PANIC level messages | ||
| "log_statement": "none", // Don't log SQL statements | ||
| "log_min_duration_statement": "-1", // Don't log slow queries | ||
| "unix_socket_directories": runtimePath, // Use a directory that is guaranteed to exist |
There was a problem hiding this comment.
This was added because the default directory Postgres uses to create the lockfiles may not exist. Using runtimePath ensures the directory exists before Postgres starts.
Greptile SummaryThis PR updates Nix packaging so embedded Postgres can use Nix-provided binaries. The main changes are:
Confidence Score: 3/5This should be fixed before merging.
nix/pgschema.nix Important Files Changed
Reviews (1): Last reviewed commit: "configure postgres binary path when buil..." | Re-trigger Greptile |
| "-X" | ||
| "github.com/pgplex/pgschema/cmd.BuildDate=${buildDate}" | ||
| "-X" | ||
| "github.com/pgplex/pgschema/internal/postgres.binariesPath=${postgres}" |
There was a problem hiding this comment.
Wrong binary directory The injected value points at the PostgreSQL package root, but
embedded-postgres checks and runs pg_ctl under <binariesPath>/bin/pg_ctl. A Nix PostgreSQL package exposes pg_ctl from its bin output, so split-output packages can put the executable under ${postgresql.bin}/bin/pg_ctl rather than ${postgresql}/bin/pg_ctl. In that case the Nix-built pgschema still cannot start embedded Postgres and fails before planning.
Context Used: CLAUDE.md (source)
| "-X" | ||
| "github.com/pgplex/pgschema/cmd.BuildDate=${buildDate}" | ||
| "-X" | ||
| "github.com/pgplex/pgschema/internal/postgres.binariesPath=${postgres}" |
There was a problem hiding this comment.
Pinned server mismatch This always injects the default Nix PostgreSQL package, while
StartEmbeddedPostgres still selects an embedded-postgres version from the target database. If the target database is a different major version from the Nix package, the code asks embedded-postgres for one version but actually runs another version's initdb and postgres binaries. Planning against a PostgreSQL 14 or 15 target on a package set whose default is 17 can validate desired state with the wrong server version.
Context Used: CLAUDE.md (source)
Running
pgschemathat is built by nix on NixOS is not possible since NixOS cannot run dynamically linked executables for general Linux environments. This works around that by providing the path to the Postgres binaries built using nix via ldflags.This has an added benefit that users can override the postgresql package being used by
embeddedpostgres.