# Building pg_turbovec from source on NixOS / nix-using systems This is what worked on the dev machine; adapt to your environment as necessary. ## 1. Prerequisites - A Rust toolchain >= 1.85. - Nix-installed PostgreSQL 16 (we'll copy it to a writable location). - libclang (for `pgrx-pg-sys` bindgen). - libopenblas + openblas-dev headers (for `turbovec`). - pkg-config + libssl + libssl-dev (for `cargo install cargo-pgrx`). ## 2. Build cargo-pgrx ```bash SSLDIR=$(find /nix/store -maxdepth 3 -name 'openssl-3*-dev' -type d | head -1) SSLDIR=${SSLDIR%-dev} SSLDEV=${SSLDIR}-dev OPENSSL_LIB_DIR=$SSLDIR/lib OPENSSL_INCLUDE_DIR=$SSLDEV/include OPENSSL_NO_VENDOR=1 \ cargo install cargo-pgrx --version 0.17.0 ``` ## 3. Set up a writable PG16 install The system pg_config lives in a Nix store path that's read-only; `cargo pgrx install` would fail trying to copy the .control file into it. We copy the install tree to a writable location and wrap `pg_config` to rewrite its hard-coded paths: ```bash PG_RO=$(find /nix/store -maxdepth 3 -name 'postgresql-16.9' -type d | head -1) PG_RO_DEV=$(find /nix/store -maxdepth 3 -name 'postgresql-16.9-dev' -type d | head -1) PG_RW=$HOME/.pgrx/install-pg16 mkdir -p $PG_RW cp -rfL $PG_RO/. $PG_RW/. && chmod -R u+w $PG_RW cp -rfL $PG_RO_DEV/bin/. $PG_RW/bin/. && chmod -R u+w $PG_RW/bin mkdir -p $PG_RW/include cp -rfL $PG_RO_DEV/include/. $PG_RW/include/. && chmod -R u+w $PG_RW/include cp -rfL $PG_RO_DEV/lib/. $PG_RW/lib/. && chmod -R u+w $PG_RW/lib # Wrap pg_config so its --pkglibdir / --sharedir / --bindir all # point at the writable copy. mv $PG_RW/bin/pg_config $PG_RW/bin/pg_config.real cat > $PG_RW/bin/pg_config < $HOME/.pgrx/config.toml <