Skip to content

fix nix packaging#440

Open
vkcku wants to merge 2 commits into
pgplex:mainfrom
vkcku:fix-nix-packaging
Open

fix nix packaging#440
vkcku wants to merge 2 commits into
pgplex:mainfrom
vkcku:fix-nix-packaging

Conversation

@vkcku
Copy link
Copy Markdown

@vkcku vkcku commented May 20, 2026

Running pgschema that 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.

vkcku added 2 commits May 20, 2026 19:56
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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 20, 2026

Greptile Summary

This PR updates Nix packaging so embedded Postgres can use Nix-provided binaries. The main changes are:

  • Adds an ldflags-injected binariesPath for embedded PostgreSQL.
  • Passes that path into embedded-postgres during startup.
  • Adds a Nix postgresql override argument and injects it into the Go binary.
  • Sets unix_socket_directories to the embedded runtime directory.

Confidence Score: 3/5

This should be fixed before merging.

  • The Nix build can still point embedded Postgres at a path that does not contain the expected pg_ctl executable.
  • The injected package can make planning run with a different PostgreSQL major version than the target database.
  • The affected path is the core embedded Postgres startup flow used by planning.

nix/pgschema.nix

Important Files Changed

Filename Overview
internal/postgres/embedded.go Adds the injected binary path and a runtime socket directory to embedded Postgres startup.
nix/pgschema.nix Injects the selected PostgreSQL derivation into the Go binary through ldflags.

Reviews (1): Last reviewed commit: "configure postgres binary path when buil..." | Re-trigger Greptile

Comment thread nix/pgschema.nix
"-X"
"github.com/pgplex/pgschema/cmd.BuildDate=${buildDate}"
"-X"
"github.com/pgplex/pgschema/internal/postgres.binariesPath=${postgres}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 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)

Comment thread nix/pgschema.nix
"-X"
"github.com/pgplex/pgschema/cmd.BuildDate=${buildDate}"
"-X"
"github.com/pgplex/pgschema/internal/postgres.binariesPath=${postgres}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 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)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant