Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin support for postgres extensions #2088

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions docs/app/docs/devbox_examples/databases/postgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand All @@ -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

Expand Down
8 changes: 6 additions & 2 deletions examples/databases/postgres/devbox.json
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 4 additions & 3 deletions plugins/postgresql.json
Original file line number Diff line number Diff line change
@@ -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": "",
Expand Down
Loading