From 6ea5bb0f201e4601483ccdb9e75b5d1123c3db6c Mon Sep 17 00:00:00 2001 From: vkcku Date: Wed, 20 May 2026 19:55:13 +0530 Subject: [PATCH 1/2] allow configuring embedded postgres binaries path 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. --- internal/postgres/embedded.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/internal/postgres/embedded.go b/internal/postgres/embedded.go index 7fea4c48..8220dc29 100644 --- a/internal/postgres/embedded.go +++ b/internal/postgres/embedded.go @@ -17,6 +17,11 @@ import ( "github.com/pgplex/pgschema/cmd/util" ) +// binariesPath is the path that contains the Postgres binaries. +// This is meant to be injected via ldflags (for example, to use the nix +// postgres versions when building with nix). +var binariesPath string + // PostgresVersion is an alias for the embedded-postgres version type. type PostgresVersion = embeddedpostgres.PostgresVersion @@ -91,14 +96,16 @@ func StartEmbeddedPostgres(config *EmbeddedPostgresConfig) (*EmbeddedPostgres, e Password(config.Password). Port(uint32(port)). RuntimePath(runtimePath). + BinariesPath(binariesPath). DataPath(filepath.Join(runtimePath, "data")). Logger(io.Discard). // Suppress embedded-postgres startup logs StartParameters(map[string]string{ - "logging_collector": "off", // Disable log collector - "log_destination": "stderr", // Send logs to stderr (which we discard) - "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 + "logging_collector": "off", // Disable log collector + "log_destination": "stderr", // Send logs to stderr (which we discard) + "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 }) // Create and start PostgreSQL instance From f7a96c99664867055d34283d75f87c649dc537e7 Mon Sep 17 00:00:00 2001 From: vkcku Date: Wed, 20 May 2026 20:04:48 +0530 Subject: [PATCH 2/2] configure postgres binary path when building via nix --- nix/pgschema.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nix/pgschema.nix b/nix/pgschema.nix index b9596c23..766070ff 100644 --- a/nix/pgschema.nix +++ b/nix/pgschema.nix @@ -1,8 +1,9 @@ -{ pkgs ? import {}, rev ? "unknown", buildDate ? "unknown" }: +{ pkgs ? import {}, rev ? "unknown", buildDate ? "unknown", postgresql ? null }: let lib = pkgs.lib; version = lib.strings.removeSuffix "\n" (builtins.readFile ../internal/version/VERSION); + postgres = if postgresql == null then pkgs.postgresql else postgresql; in pkgs.buildGoModule { pname = "pgschema"; @@ -31,6 +32,8 @@ pkgs.buildGoModule { "github.com/pgplex/pgschema/cmd.GitCommit=${rev}" "-X" "github.com/pgplex/pgschema/cmd.BuildDate=${buildDate}" + "-X" + "github.com/pgplex/pgschema/internal/postgres.binariesPath=${postgres}" ]; meta = with lib; {