From a6e5be322927cdc5f429cca7ae02e32cb61cd7e5 Mon Sep 17 00:00:00 2001 From: John Lago <750845+Lagoja@users.noreply.github.com> Date: Fri, 24 May 2024 18:59:09 -0700 Subject: [PATCH] Add support for postgres extensions --- .../devbox_examples/databases/postgres.md | 22 +++++++++++++++++-- examples/databases/postgres/devbox.json | 8 +++++-- plugins/postgresql.json | 7 +++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/docs/app/docs/devbox_examples/databases/postgres.md b/docs/app/docs/devbox_examples/databases/postgres.md index e1108023301..eef8958982a 100644 --- a/docs/app/docs/devbox_examples/databases/postgres.md +++ b/docs/app/docs/devbox_examples/databases/postgres.md @@ -25,6 +25,25 @@ Alternatively, you can add the following to your devbox.json: This will install the latest version of Postgres. You can find other installable versions of Postgres by running `devbox search postgresql`. You can also view the available versions on [Nixhub](https://www.nixhub.io/packages/postgresql) +## Installing Extensions with PostgreSQL + +To install and use extensions in PostgreSQL, you should first install the `lib` output for Postgres by running `devbox add postgresql --outputs=out,lib`: + +```json + "packages": { + "postgresql": { + "version": "latest", + "outputs": ["out", "lib"] + }, + } +``` + +You can then install the extension using `devbox add postgresqlXXpackages.extension`, where `XX` is the major version of Postgres that you are using. For example, to install Postgis for PostgreSQL 15, you can run: + +```bash +devbox add postgresql15Packages.postgis +``` + ## PostgreSQL Plugin Support Devbox will automatically create the following configuration when you run `devbox add postgresql`: @@ -38,8 +57,7 @@ You can use `devbox services start|stop postgresql` to start or stop the Postgre `PGHOST=./.devbox/virtenv/postgresql` `PGDATA=./.devbox/virtenv/postgresql/data` - -This variable tells PostgreSQL which directory to use for creating and storing databases. +`NIX_PGLIBDIR=./.devbox/nix/profile/default/lib` ### Notes diff --git a/examples/databases/postgres/devbox.json b/examples/databases/postgres/devbox.json index e528a436349..25f5f688ee7 100644 --- a/examples/databases/postgres/devbox.json +++ b/examples/databases/postgres/devbox.json @@ -1,10 +1,14 @@ { "packages": { - "postgresql": "latest", + "postgresql": { + "version": "latest", + "outputs": ["out", "lib"] + }, "glibcLocales": { "version": "latest", "platforms": ["x86_64-linux", "aarch64-linux"] - } + }, + "postgresql15Packages.postgis": "latest" }, "shell": { "init_hook": null diff --git a/plugins/postgresql.json b/plugins/postgresql.json index b26e221fc41..6d5c7128f77 100644 --- a/plugins/postgresql.json +++ b/plugins/postgresql.json @@ -1,10 +1,11 @@ { "name": "postgresql", - "version": "0.0.2", - "description": "To initialize the database run `initdb`.", + "version": "0.0.3", + "description": "To initialize the database run `initdb`.\nIf you want to install extensions with Postgres, make sure to add the lib output with `devbox add postgresql --outputs=out,lib`", "env": { "PGDATA": "{{ .Virtenv }}/data", - "PGHOST": "{{ .Virtenv }}" + "PGHOST": "{{ .Virtenv }}", + "NIX_PGLIBDIR": "{{ .DevboxProfileDefault }}/lib" }, "create_files": { "{{ .Virtenv }}/data": "",