Skip to content

Commit 650ecda

Browse files
authored
fix nix packaging (#440)
* 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. * configure postgres binary path when building via nix
1 parent 0abf597 commit 650ecda

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

internal/postgres/embedded.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import (
1717
"github.com/pgplex/pgschema/cmd/util"
1818
)
1919

20+
// binariesPath is the path that contains the Postgres binaries.
21+
// This is meant to be injected via ldflags (for example, to use the nix
22+
// postgres versions when building with nix).
23+
var binariesPath string
24+
2025
// PostgresVersion is an alias for the embedded-postgres version type.
2126
type PostgresVersion = embeddedpostgres.PostgresVersion
2227

@@ -91,14 +96,16 @@ func StartEmbeddedPostgres(config *EmbeddedPostgresConfig) (*EmbeddedPostgres, e
9196
Password(config.Password).
9297
Port(uint32(port)).
9398
RuntimePath(runtimePath).
99+
BinariesPath(binariesPath).
94100
DataPath(filepath.Join(runtimePath, "data")).
95101
Logger(io.Discard). // Suppress embedded-postgres startup logs
96102
StartParameters(map[string]string{
97-
"logging_collector": "off", // Disable log collector
98-
"log_destination": "stderr", // Send logs to stderr (which we discard)
99-
"log_min_messages": "PANIC", // Only log PANIC level messages
100-
"log_statement": "none", // Don't log SQL statements
101-
"log_min_duration_statement": "-1", // Don't log slow queries
103+
"logging_collector": "off", // Disable log collector
104+
"log_destination": "stderr", // Send logs to stderr (which we discard)
105+
"log_min_messages": "PANIC", // Only log PANIC level messages
106+
"log_statement": "none", // Don't log SQL statements
107+
"log_min_duration_statement": "-1", // Don't log slow queries
108+
"unix_socket_directories": runtimePath, // Use a directory that is guaranteed to exist
102109
})
103110

104111
// Create and start PostgreSQL instance

nix/pgschema.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
{ pkgs ? import <nixpkgs> {}, rev ? "unknown", buildDate ? "unknown" }:
1+
{ pkgs ? import <nixpkgs> {}, rev ? "unknown", buildDate ? "unknown", postgresql ? null }:
22

33
let
44
lib = pkgs.lib;
55
version = lib.strings.removeSuffix "\n" (builtins.readFile ../internal/version/VERSION);
6+
postgres = if postgresql == null then pkgs.postgresql else postgresql;
67
in
78
pkgs.buildGoModule {
89
pname = "pgschema";
@@ -31,6 +32,8 @@ pkgs.buildGoModule {
3132
"github.com/pgplex/pgschema/cmd.GitCommit=${rev}"
3233
"-X"
3334
"github.com/pgplex/pgschema/cmd.BuildDate=${buildDate}"
35+
"-X"
36+
"github.com/pgplex/pgschema/internal/postgres.binariesPath=${postgres}"
3437
];
3538

3639
meta = with lib; {

0 commit comments

Comments
 (0)