Nix package for pg_pure, libpure and the vetted Pure modules
The Pure runtime pg_pure embeds (libpure) is not in nixpkgs, and it must be
built from the gburd/pure-lang fork against a recent LLVM. This flake does
that build once, and builds pg_pure itself for PostgreSQL 17, 18 and 19, so a
host that wants to run pg_pure does not have to maintain a bespoke LLVM build
by hand. (This is the pg.ddx.io evaluation’s top operational blocker; see
pg_pure’s ROADMAP phase 2.A.)
What it provides
packages.pg_pure-pg17,packages.pg_pure-pg18,packages.pg_pure-pg19– pg_pure built with PGXS against nixpkgs' PostgreSQL 17, 18 and 19, linked topure-with-modules. Each is laid out forpostgresql.withPackages.checks.installcheck-pg17,-pg18,-pg19– both regression suites (pg_pureu,pg_pure) against that server withjit = onand the server’s llvmjit installed, so a JIT-compiled query and a Pure call meet in one backend. A check fails on anyterminated by signalin the server log, and on a server whose JIT did not actually run.packages.libpure– the Pure runtime and interpreter, LLVM 21, with its LLVM symbols hidden so it coexists with a PostgreSQL whose own JIT links a different LLVM (DESIGN.md section 5).packages.pure-gsl– the GSL bindings, includinggsl::linalg::cholesky_solve(the compiled SPD solve pg_pure exposes).packages.pure-mpfr,packages.pure-stldict,packages.pure-rational– the other vetted modules: arbitrary-precision floats (mpfr), STL-backed maps (dict), and exact-rational utilities (rational).packages.pure-with-modules(the default) – libpure and the modules merged into one prefix, which is what you pointPURE_PREFIX/PURELIBat.devShells.default– a shell withpureonPATHandPURELIBset.
Use it
A PostgreSQL 19 server with pg_pure installed (swap in 17 or 18):
nix build github:gburd/pg_pure?dir=nix#pg_pure-pg19
# in your own flake or configuration:
postgresql_19.withPackages (_: [ pg_pure.packages.${system}.pg_pure-pg19 ])
The server needs PURELIB in its environment for the add-on modules: point it
at the module directory of the same pure-with-modules the package links (for
example PURELIB=$(nix build --no-link --print-out-paths github:gburd/pg_pure?dir=nix#pure-with-modules)/lib/pure).
Without it the Pure prelude still loads, so plain Pure functions work, but
using gsl::linalg and the other modules fail with “No such file or
directory”.
Run the regression suites for one major:
nix build github:gburd/pg_pure?dir=nix#checks.x86_64-linux.installcheck-pg19
Build the merged Pure prefix on its own:
nix build github:gburd/pg_pure?dir=nix#pure-with-modules
# ./result is a prefix with bin/pure, lib/libpure.so, lib/pure/gsl/...
Try the compiled solve interactively:
nix develop github:gburd/pg_pure?dir=nix
$ echo 'using gsl::linalg; gsl::linalg::cholesky_solve (dmatrix {4.0,1.0;1.0,3.0}) (dmatrix {1.0;2.0});' | pure -i -q
{0.0909090909090909,0.636363636363636}
Build pg_pure against it (from the repo root, with a PostgreSQL’s pg_config):
make PG_CONFIG=/path/to/pg_config PURE_PREFIX="$(nix build --no-link --print-out-paths .#pure-with-modules)"
Notes
- Pin the fork: the
pure-langinput tracks thelibpure-embeddablebranch. Runnix flake update pure-langto move to a newer fork commit, then re-qualify pg_pure against it. - Known cosmetic warning: loading a gsl module prints
gsl/common.pure, line 12: libgsl: cannot open shared object file. This is the fork module’s redundant explicitusing "lib:libgsl"; the module still loads (its gsl.so carries the correct RPATH) and results are correct. The fix belongs in the fork’s common.pure, not here. - The TAP suite (
t/*.pl) does not run under Nix: nixpkgs' PostgreSQL ships without thePostgreSQL::Testharness.ci/gate.shruns it against the PGDG packages. - Because the libraries are built against the Nix glibc, the cleanest result is when pg_pure is also built under Nix (or at least run against the Nix loader). Mixing a Nix-built libpure with a host-built server can surface a glibc version mismatch; build the whole stack under one toolchain.