Skip to content

NixOS: PostgreSQL fails to start due to hardcoded /usr/share/zoneinfo in bundled binary #11

@hachi-gallop

Description

@hachi-gallop

Problem

pg0 fails on NixOS (and any system without /usr/share/zoneinfo) because the bundled PostgreSQL binary from theseus-rs/postgresql-binaries is compiled on Debian with /usr/share/zoneinfo hardcoded.

NixOS stores timezone data at /etc/zoneinfo (symlinked from the Nix store). There is no /usr/share/zoneinfo on a standard NixOS system.

When PostgreSQL starts, it tries to resolve the timezone (e.g., UTC) by looking in /usr/share/zoneinfo and gets a FATAL error:

FATAL:  could not find a suitable time zone abbreviations file

or when a client connects and the server processes its startup parameters:

ERROR:  invalid value for parameter "TimeZone": "UTC"
DETAIL:  /usr/share/zoneinfo: No such file or directory

This causes pg0 start to fail entirely on NixOS systems.

Root Cause

The root cause is in the upstream theseus-rs/postgresql-binaries project — the pre-built binaries are compiled with --with-system-tzdata=/usr/share/zoneinfo. I've also filed an issue there: https://github.com/theseus-rs/postgresql-binaries/issues

Workaround (for NixOS users)

Binary-patch the postgres executable to replace the hardcoded path with the NixOS equivalent:

PG0_POSTGRES=$(find ~/.pg0/installation -name postgres -type f | head -1)
perl -pi -e 's|/usr/share/zoneinfo|/etc/zoneinfo\x00\x00\x00\x00\x00\x00|g' "$PG0_POSTGRES"

The padding with null bytes is required to preserve the binary's size (the path string is the same length).

Suggested Fix in pg0

Until the upstream binaries are fixed, pg0 can mitigate this by explicitly setting timezone = 'UTC' in the configuration HashMap before calling postgresql.start():

// Around line 628 in src/main.rs, where other defaults are set:
configuration.insert("timezone".to_string(), "UTC".to_string());
configuration.insert("log_timezone".to_string(), "UTC".to_string());

These keys are written to postgresql.conf by postgresql_embedded, so PostgreSQL reads them at startup and never falls back to the timezone file lookup path. This is a minimal, low-risk fix that resolves the NixOS failure without requiring binary patches.

Environment

  • NixOS (unstable, 2025-04)
  • pg0 v0.4.x
  • PostgreSQL 18.1 (theseus-rs bundled binary)
  • Architecture: x86_64-linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions