Skip to content
Merged
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
35 changes: 2 additions & 33 deletions nix/cargo-pgrx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ let
cargo = rust-bin.stable.${rustVersion}.default;
rustc = rust-bin.stable.${rustVersion}.default;
});
in
{
mkCargoPgrx =
{
version,
Expand Down Expand Up @@ -65,37 +67,4 @@ let
mainProgram = "cargo-pgrx";
};
};
in
{
cargo-pgrx_0_10_2 = mkCargoPgrx {
version = "0.10.2";
hash = "sha256-FqjfbJmSy5UCpPPPk4bkEyvQCnaH9zYtkI7txgIn+ls=";
cargoHash = "sha256-syZ3cQq8qDHBLvqmNDGoxeK6zXHJ47Jwkw3uhaXNCzI=";
};
cargo-pgrx_0_11_3 = mkCargoPgrx {
version = "0.11.3";
hash = "sha256-UHIfwOdXoJvR4Svha6ud0FxahP1wPwUtviUwUnTmLXU=";
cargoHash = "sha256-j4HnD8Zt9uhlV5N7ldIy9564o9qFEqs5KfXHmnQ1WEw=";
};
cargo-pgrx_0_12_6 = mkCargoPgrx {
version = "0.12.6";
hash = "sha256-7aQkrApALZe6EoQGVShGBj0UIATnfOy2DytFj9IWdEA=";
cargoHash = "sha256-pnMxWWfvr1/AEp8DvG4awig8zjdHizJHoZ5RJA8CL08=";
};
cargo-pgrx_0_12_9 = mkCargoPgrx {
version = "0.12.9";
hash = "sha256-aR3DZAjeEEAjLQfZ0ZxkjLqTVMIEbU0UiZ62T4BkQq8=";
cargoHash = "sha256-yZpD3FriL9UbzRtdFkfIfFfYIrRPYxr/lZ5rb0YBTPc=";
};
cargo-pgrx_0_14_3 = mkCargoPgrx {
version = "0.14.3";
hash = "sha256-3TsNpEqNm3Uol5XPW1i0XEbP2fF2+RKB2d7lO6BDnvQ=";
cargoHash = "sha256-LZUXhjMxkBs3O5feH4X5NQC7Qk4Ja6M5+sAYaSCikrY=";
};
cargo-pgrx_0_19_2 = mkCargoPgrx {
version = "0.19.2";
hash = "sha256-PANc819AhIE9yJ6NFHGJxHJHWZyR2Srmj2cEz3vQmJk=";
cargoHash = "sha256-cTD7x36FvFUIwVLuAqrOJ75vLDppITiDrY8Fs3RjPqU=";
};
inherit mkCargoPgrx;
}
19 changes: 0 additions & 19 deletions nix/devShells.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@
paramiko
]
);
mkCargoPgrxDevShell =
{ pgrxVersion, rustVersion }:
pkgs.mkShell {
packages = with pkgs; [
self'.packages."cargo-pgrx_${pgrxVersion}"
(rust-bin.stable.${rustVersion}.default.override { extensions = [ "rust-src" ]; })
];
shellHook = ''
export HISTFILE=.history
'';
};
docvenv = pkgs.python3.buildEnv.override {
extraLibs = self'.packages.docs.nativeBuildInputs;
};
Expand Down Expand Up @@ -147,14 +136,6 @@
}
];
};
cargo-pgrx_0_11_3 = mkCargoPgrxDevShell {
pgrxVersion = "0_11_3";
rustVersion = "1.80.0";
};
cargo-pgrx_0_12_6 = mkCargoPgrxDevShell {
pgrxVersion = "0_12_6";
rustVersion = "1.80.0";
};
};
};
}
87 changes: 22 additions & 65 deletions nix/docs/creating-pgrx-extension.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Creating a New pgrx Extension
# Creating a new pgrx extension

This guide covers how to set up a new cargo pgrx PostgreSQL extension in this project.

## Template: New pgrx Extension
## Template: New pgrx extension

### 1. Directory Structure

Expand Down Expand Up @@ -122,19 +122,21 @@ Edit `nix/ext/versions.json` and add your extension:
"my_extension": {
"0.1.0": {
"postgresql": ["15", "17"],
"hash": "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"hash": "",
"pgrx": "0.12.6",
"rust": "1.80.0"
}
}
}
```

**To calculate the hash:** Use a dummy hash first, then run:
Run the following to calculate content hash:

```bash
nix build .#psql_15.exts.my_extension -L
```
The error message will show the correct hash.

The error message will show the correct hash, update the `hash` attribute in versions.json.

### 4. Register in postgres.nix

Expand All @@ -149,59 +151,14 @@ ourExtensions = [

## Files to Modify (Summary)

| File | Change |
|------|--------|
| `nix/ext/my_extension/default.nix` | Create new file |
| `nix/ext/versions.json` | Add version entry |
| `nix/packages/postgres.nix` | Add to `ourExtensions` list |
| `nix/tests/sql/my_extension.sql` | (optional) Add test SQL |
| File | Change |
| ------------------------------------- | ------------------------------- |
| `nix/ext/my_extension/default.nix` | Create new file |
| `nix/ext/versions.json` | Add version entry |
| `nix/packages/postgres.nix` | Add to `ourExtensions` list |
| `nix/tests/sql/my_extension.sql` | (optional) Add test SQL |
| `nix/tests/expected/my_extension.out` | (optional) Expected test output |

## Using nix develop for Extension Development

### Available Dev Shells

```bash
# List all available dev shells
nix flake show | grep devShells

# Enter pgrx 0.12.6 development environment (Rust 1.80.0)
nix develop .#cargo-pgrx_0_12_6

# Enter pgrx 0.14.3 development environment (Rust 1.87.0)
nix develop .#cargo-pgrx_0_14_3

# Default shell (general tooling, not pgrx-specific)
nix develop
```

### Inside the Dev Shell

Once inside `nix develop .#cargo-pgrx_0_12_6`:

```bash
# Initialize pgrx (first time only)
cargo pgrx init --pg15 $(which pg_config)

# Create a new extension from scratch
cargo pgrx new my_extension
cd my_extension

# Build and test your extension
cargo pgrx run pg15

# Package for release
cargo pgrx package
```

### Dev Shell Contents

The pgrx dev shells provide:
- Correct Rust toolchain version
- `cargo-pgrx` CLI matching the pgrx version
- PostgreSQL headers and pg_config
- Required build tools (pkg-config, openssl, etc.)

## Build Commands

```bash
Expand All @@ -222,17 +179,17 @@ nix flake check -L

From `nix/cargo-pgrx/versions.json`:

| pgrx Version | Rust Version |
|--------------|--------------|
| 0.12.6 | 1.80.0, 1.81.0 |
| 0.14.3 | 1.87.0 |
| pgrx Version | Rust Version |
| ------------ | -------------- |
| 0.12.6 | 1.80.0, 1.81.0 |
| 0.14.3 | 1.87.0 |

Match your extension's pgrx dependency to a supported combination.

## Existing Examples to Reference

| Extension | Path | Notes |
|-----------|------|-------|
| pg_graphql | `nix/ext/pg_graphql/default.nix` | Clean pgrx example |
| pg_jsonschema | `nix/ext/pg_jsonschema/default.nix` | Simple single-crate |
| wrappers | `nix/ext/wrappers/default.nix` | Complex with git deps |
| Extension | Path | Notes |
| ------------- | ----------------------------------- | --------------------- |
| pg_graphql | `nix/ext/pg_graphql/default.nix` | Clean pgrx example |
| pg_jsonschema | `nix/ext/pg_jsonschema/default.nix` | Simple single-crate |
| wrappers | `nix/ext/wrappers/default.nix` | Complex with git deps |
27 changes: 4 additions & 23 deletions nix/docs/updating-pgrx-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ Use this when the extension requires a newer pgrx version.
| `nix/ext/versions.json` | Add new version with new pgrx version |
| `nix/ext/<extension>/default.nix` | Add old version to `allPreviouslyPackagedVersions` |
| `nix/cargo-pgrx/versions.json` | Add new pgrx version (if not already present) |
| `nix/cargo-pgrx/default.nix` | Add new `cargo-pgrx_x_y_z` entry (if not already present) |
| `nix/overlays/default.nix` | Add new `buildPgrxExtension_x_y_z` (if not already present) |

### Steps

Expand All @@ -143,27 +141,10 @@ Use this when the extension requires a newer pgrx version.
}
```

The `rust` object maps Rust versions to their corresponding `cargoHash`. You'll need to calculate both the `hash` (for the pgrx crate) and `cargoHash` (for cargo dependencies).
The `rust` object maps Rust versions to their corresponding `cargoHash`.
You'll need to calculate both the `hash` (for the pgrx crate) and `cargoHash` (for cargo dependencies).

3. **Add cargo-pgrx entry** in `nix/cargo-pgrx/default.nix`:

```nix
cargo-pgrx_0_16_1 = mkCargoPgrx {
version = "0.16.1";
hash = "";
cargoHash = "";
};
```

4. **Add overlay entry** in `nix/overlays/default.nix`:

```nix
buildPgrxExtension_0_16_1 = prev.buildPgrxExtension.override {
cargo-pgrx = final.cargo-pgrx.cargo-pgrx_0_16_1;
};
```

5. **Update `nix/ext/versions.json`** with the new extension version:
3. **Update `nix/ext/versions.json`** with the new extension version:

```json
"0.5.7": {
Expand All @@ -174,7 +155,7 @@ Use this when the extension requires a newer pgrx version.
}
```

6. **Stage and build** to calculate hashes:
4. **Stage and build** to calculate hashes:

```bash
git add .
Expand Down
6 changes: 0 additions & 6 deletions nix/packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@
inherit (pkgs.callPackage ./wal-g.nix { }) wal-g-2 wal-g-3;
inherit (supascan-pkgs) goss supascan supascan-specs;
inherit (pg-startup-profiler-pkgs) pg-startup-profiler;
inherit (pkgs.cargo-pgrx)
cargo-pgrx_0_11_3
cargo-pgrx_0_12_6
cargo-pgrx_0_12_9
cargo-pgrx_0_14_3
;
}
// lib.optionalAttrs pkgs.stdenv.isDarwin {
setup-darwin-linux-builder = pkgs.callPackage ./setup-darwin-linux-builder.nix {
Expand Down
Loading