Skip to content

Commit 9ac5e91

Browse files
committed
refactor(nix/cargo-pgrx): build cargo-pgrx by overriding upstream pkg
Replace the vendored and outdated cargo-pgrx expression with an override of the upstream nixpkgs package, dropping the manual dependency wiring, custom check flags, and meta block. Remove the cargo-pgrx overlay and call the package set directly via callPackages in the package list. Using the overlay shadows the upstream package, and in addition just adds another layer of unneeded indirection.
1 parent 8fd4313 commit 9ac5e91

5 files changed

Lines changed: 30 additions & 64 deletions

File tree

nix/cargo-pgrx/default.nix

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
22
lib,
3+
cargo-pgrx,
34
fetchCrate,
4-
openssl,
5-
pkg-config,
65
makeRustPlatform,
7-
stdenv,
86
rust-bin,
97
rustVersion ? "1.85.1",
108
}:
@@ -14,73 +12,56 @@ let
1412
rustc = rust-bin.stable.${rustVersion}.default;
1513
};
1614
mkCargoPgrx =
17-
{
18-
version,
19-
hash,
20-
cargoHash,
21-
}:
22-
let
23-
pname = if builtins.compareVersions "0.7.4" version >= 0 then "cargo-pgx" else "cargo-pgrx";
24-
in
25-
rustPlatform.buildRustPackage rec {
26-
# rust-overlay uses 'cargo-auditable' wrapper for 'cargo' command, but it
27-
# is using older version 0.18.1 of 'cargo_metadata' which doesn't support
28-
# rust edition 2024, so we disable the 'cargo-auditable' just for now.
29-
# ref: https://github.com/oxalica/rust-overlay/issues/153
30-
auditable = false;
31-
inherit pname;
32-
inherit version;
33-
src = fetchCrate { inherit version pname hash; };
34-
inherit cargoHash;
35-
nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ pkg-config ];
36-
buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ openssl ];
15+
args:
16+
(cargo-pgrx.override { inherit rustPlatform; }).overrideAttrs rec {
17+
pname = if lib.versionOlder version "0.7.4" then "cargo-pgx" else "cargo-pgrx";
18+
inherit (args) version;
3719

38-
OPENSSL_DIR = "${openssl.dev}";
39-
OPENSSL_INCLUDE_DIR = "${openssl.dev}/include";
40-
OPENSSL_LIB_DIR = "${openssl.out}/lib";
41-
PKG_CONFIG_PATH = "${openssl.dev}/lib/pkgconfig";
42-
preCheck = ''
43-
export PGRX_HOME=$(mktemp -d)
44-
'';
45-
checkFlags = [
46-
# requires pgrx to be properly initialized with cargo pgrx init
47-
"--skip=command::schema::tests::test_parse_managed_postmasters"
48-
];
49-
meta = with lib; {
50-
description = "Build Postgres Extensions with Rust";
51-
homepage = "https://github.com/pgcentralfoundation/pgrx";
52-
changelog = "https://github.com/pgcentralfoundation/pgrx/releases/tag/v${version}";
53-
license = licenses.mit;
54-
maintainers = with maintainers; [ happysalada ];
55-
mainProgram = "cargo-pgrx";
20+
src = fetchCrate {
21+
inherit pname;
22+
inherit (args)
23+
version
24+
hash
25+
;
26+
};
27+
28+
cargoDeps = rustPlatform.fetchCargoVendor {
29+
inherit
30+
pname
31+
src
32+
;
33+
inherit (args) version;
34+
hash = args.cargoHash;
5635
};
5736
};
5837
in
59-
{
60-
cargo-pgrx_0_10_2 = mkCargoPgrx {
38+
lib.mapAttrs (_: mkCargoPgrx) {
39+
cargo-pgrx_0_10_2 = {
6140
version = "0.10.2";
6241
hash = "sha256-FqjfbJmSy5UCpPPPk4bkEyvQCnaH9zYtkI7txgIn+ls=";
6342
cargoHash = "sha256-syZ3cQq8qDHBLvqmNDGoxeK6zXHJ47Jwkw3uhaXNCzI=";
6443
};
65-
cargo-pgrx_0_11_3 = mkCargoPgrx {
44+
cargo-pgrx_0_11_3 = {
6645
version = "0.11.3";
6746
hash = "sha256-UHIfwOdXoJvR4Svha6ud0FxahP1wPwUtviUwUnTmLXU=";
6847
cargoHash = "sha256-j4HnD8Zt9uhlV5N7ldIy9564o9qFEqs5KfXHmnQ1WEw=";
6948
};
70-
cargo-pgrx_0_12_6 = mkCargoPgrx {
49+
cargo-pgrx_0_12_6 = {
7150
version = "0.12.6";
7251
hash = "sha256-7aQkrApALZe6EoQGVShGBj0UIATnfOy2DytFj9IWdEA=";
7352
cargoHash = "sha256-pnMxWWfvr1/AEp8DvG4awig8zjdHizJHoZ5RJA8CL08=";
7453
};
75-
cargo-pgrx_0_12_9 = mkCargoPgrx {
54+
cargo-pgrx_0_12_9 = {
7655
version = "0.12.9";
7756
hash = "sha256-aR3DZAjeEEAjLQfZ0ZxkjLqTVMIEbU0UiZ62T4BkQq8=";
7857
cargoHash = "sha256-yZpD3FriL9UbzRtdFkfIfFfYIrRPYxr/lZ5rb0YBTPc=";
7958
};
80-
cargo-pgrx_0_14_3 = mkCargoPgrx {
59+
cargo-pgrx_0_14_3 = {
8160
version = "0.14.3";
8261
hash = "sha256-3TsNpEqNm3Uol5XPW1i0XEbP2fF2+RKB2d7lO6BDnvQ=";
8362
cargoHash = "sha256-LZUXhjMxkBs3O5feH4X5NQC7Qk4Ja6M5+sAYaSCikrY=";
8463
};
64+
}
65+
// {
8566
inherit mkCargoPgrx;
8667
}

nix/docs/flake-parts-architecture.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,6 @@ Overlays are flake-level (not per-system):
325325
postgresql_17
326326
supabase-groonga;
327327
328-
# Define new packages in terms of final/prev
329-
cargo-pgrx = final.callPackage ../cargo-pgrx/default.nix {
330-
inherit (final) lib darwin fetchCrate openssl;
331-
};
332-
333328
# Override existing packages
334329
buildPgrxExtension = final.callPackage ../cargo-pgrx/buildPgrxExtension.nix {
335330
inherit (final) cargo-pgrx lib;

nix/docs/updating-pgrx-extensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Use this when the extension requires a newer pgrx version.
148148
3. **Add cargo-pgrx entry** in `nix/cargo-pgrx/default.nix`:
149149

150150
```nix
151-
cargo-pgrx_0_16_1 = mkCargoPgrx {
151+
cargo-pgrx_0_16_1 = {
152152
version = "0.16.1";
153153
hash = "";
154154
cargoHash = "";

nix/overlays/default.nix

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,5 @@
1616
;
1717

1818
xmrig = throw "The xmrig package has been explicitly disabled in this flake.";
19-
20-
cargo-pgrx = final.callPackage ../cargo-pgrx/default.nix {
21-
inherit (final) lib;
22-
inherit (final) fetchCrate;
23-
inherit (final) openssl;
24-
inherit (final) pkg-config;
25-
inherit (final) makeRustPlatform;
26-
inherit (final) stdenv;
27-
inherit (final) rust-bin;
28-
};
2919
};
3020
}

nix/packages/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
inherit (pkgs.callPackage ./wal-g.nix { }) wal-g-2;
109109
inherit (supascan-pkgs) goss supascan supascan-specs;
110110
inherit (pg-startup-profiler-pkgs) pg-startup-profiler;
111-
inherit (pkgs.cargo-pgrx)
111+
inherit (pkgs.callPackages ../cargo-pgrx { })
112112
cargo-pgrx_0_11_3
113113
cargo-pgrx_0_12_6
114114
cargo-pgrx_0_12_9

0 commit comments

Comments
 (0)