Unverified Commit be15e0c3 authored by Wolfgang Walther's avatar Wolfgang Walther Committed by GitHub
Browse files

buildPgrxExtension: restructure with lib.extendMkDerivation (#394089)

parents 59e2a0be b50641ed
Loading
Loading
Loading
Loading
+138 −136
Original line number Diff line number Diff line
@@ -47,7 +47,18 @@
#                      If the generated rust bindings aren't needed to use the extension, its a
#                      unnecessary and heavy dependency. If you set this to true, you also
#                      have to add `rustfmt` to `nativeBuildInputs`.
#   - `usePgTestCheckFeature` Whether to enable the `pg_test` feature during the check phase.
lib.extendMkDerivation {
  constructDrv = rustPlatform.buildRustPackage;

  excludeDrvArgNames = [
    "postgresql"
    "useFakeRustfmt"
    "usePgTestCheckFeature"
  ];

  extendDrvArgs =
    finalAttrs:
    {
      buildAndTestSubdir ? null,
      buildType ? "release",
@@ -70,10 +81,10 @@ in

    assert lib.asserts.assertMsg (
      (args.installPhase or "") == ""
) "buildPgrxExtensions overwrites the installPhase, so providing one does nothing";
    ) "buildPgrxExtension overwrites the installPhase, so providing one does nothing";
    assert lib.asserts.assertMsg (
      (args.buildPhase or "") == ""
) "buildPgrxExtensions overwrites the buildPhase, so providing one does nothing";
    ) "buildPgrxExtension overwrites the buildPhase, so providing one does nothing";
    assert lib.asserts.assertMsg (useFakeRustfmt -> !rustfmtInNativeBuildInputs)
      "The parameter useFakeRustfmt is set to true, but rustfmt is included in nativeBuildInputs. Either set useFakeRustfmt to false or remove rustfmt from nativeBuildInputs.";
    assert lib.asserts.assertMsg (!useFakeRustfmt -> rustfmtInNativeBuildInputs)
@@ -110,17 +121,9 @@ let
        pg_ctl stop
      '';

  argsForBuildRustPackage = builtins.removeAttrs args [
    "postgresql"
    "useFakeRustfmt"
    "usePgTestCheckFeature"
  ];

      cargoPgrxFlags' = lib.escapeShellArgs cargoPgrxFlags;

  # so we don't accidentally `(rustPlatform.buildRustPackage argsForBuildRustPackage) // { ... }` because
  # we forgot parentheses
  finalArgs = argsForBuildRustPackage // {
    in
    {
      buildInputs = (args.buildInputs or [ ]) ++ lib.optionals stdenv.hostPlatform.isDarwin [ Security ];

      nativeBuildInputs =
@@ -188,5 +191,4 @@ let
        broken = (args.meta.broken or false) || stdenv.hostPlatform.isDarwin;
      };
    };
in
rustPlatform.buildRustPackage finalArgs
}
+5 −5
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ in
  cargo-pgrx = cargo-pgrx_0_12_0_alpha_1;
  rustPlatform = rustPlatform';
})
  rec {
  (finalAttrs: {
    inherit postgresql;

    pname = "pgvecto-rs";
@@ -49,7 +49,7 @@ in
    src = fetchFromGitHub {
      owner = "tensorchord";
      repo = "pgvecto.rs";
      tag = "v${version}";
      tag = "v${finalAttrs.version}";
      hash = "sha256-X7BY2Exv0xQNhsS/GA7GNvj9OeVDqVCd/k3lUkXtfgE=";
    };

@@ -58,7 +58,7 @@ in

    # Set appropriate version on vectors.control, otherwise it won't show up on PostgreSQL
    postPatch = ''
      substituteInPlace ./vectors.control --subst-var-by CARGO_VERSION ${version}
      substituteInPlace ./vectors.control --subst-var-by CARGO_VERSION ${finalAttrs.version}
    '';

    # Include upgrade scripts in the final package
@@ -90,7 +90,7 @@ in
        ||
          # PostgreSQL 17 support issue upstream: https://github.com/tensorchord/pgvecto.rs/issues/607
          # Check after next package update.
          lib.versionAtLeast postgresql.version "17" && version == "0.3.0";
          lib.versionAtLeast postgresql.version "17" && finalAttrs.version == "0.3.0";
      description = "Scalable, Low-latency and Hybrid-enabled Vector Search in Postgres";
      homepage = "https://github.com/tensorchord/pgvecto.rs";
      license = lib.licenses.asl20;
@@ -99,4 +99,4 @@ in
        esclear
      ];
    };
  }
  })
+67 −70
Original line number Diff line number Diff line
@@ -6,15 +6,14 @@
  postgresqlTestExtension,
}:

let
  finalPackage = buildPgrxExtension rec {
buildPgrxExtension (finalAttrs: {
  pname = "pgvectorscale";
  version = "0.7.0";

  src = fetchFromGitHub {
    owner = "timescale";
    repo = "pgvectorscale";
      tag = version;
    tag = finalAttrs.version;
    hash = "sha256-dy481k2SvyYXwwcsyLZSl3XlhSk9C5+4LfEfciB1DK4=";
  };

@@ -34,7 +33,7 @@ let
  inherit postgresql;

  passthru.tests.extension = postgresqlTestExtension {
      inherit finalPackage;
    inherit (finalAttrs) finalPackage;
    withPackages = [ "pgvector" ];
    sql =
      let
@@ -82,8 +81,6 @@ let
    description = "Complement to pgvector for high performance, cost efficient vector search on large workloads";
    license = lib.licenses.postgresql;
    platforms = postgresql.meta.platforms;
      changelog = "https://github.com/timescale/pgvectorscale/releases/tag/${version}";
    };
    changelog = "https://github.com/timescale/pgvectorscale/releases/tag/${finalAttrs.version}";
  };
in
finalPackage
})
+4 −4
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
  postgresql,
  util-linux,
}:
buildPgrxExtension rec {
buildPgrxExtension (finalAttrs: {
  inherit postgresql;

  pname = "pgx_ulid";
@@ -15,7 +15,7 @@ buildPgrxExtension rec {
  src = fetchFromGitHub {
    owner = "pksunkara";
    repo = "pgx_ulid";
    tag = "v${version}";
    tag = "v${finalAttrs.version}";
    hash = "sha256-VdLWwkUA0sVs5Z/Lyf5oTRhcHVzPmhgnYQhIM8MWJ0c=";
  };

@@ -42,8 +42,8 @@ buildPgrxExtension rec {
    broken = lib.versionOlder postgresql.version "14";
    description = "ULID Postgres extension written in Rust";
    homepage = "https://github.com/pksunkara/pgx_ulid";
    changelog = "https://github.com/pksunkara/pgx_ulid/blob/v${version}/CHANGELOG.md";
    changelog = "https://github.com/pksunkara/pgx_ulid/blob/v${finalAttrs.version}/CHANGELOG.md";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ myypo ];
  };
}
})
+3 −3
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
  postgresql,
}:

(buildPgrxExtension.override { cargo-pgrx = cargo-pgrx_0_12_6; }) rec {
(buildPgrxExtension.override { cargo-pgrx = cargo-pgrx_0_12_6; }) (finalAttrs: {
  inherit postgresql;

  pname = "timescaledb_toolkit";
@@ -17,7 +17,7 @@
  src = fetchFromGitHub {
    owner = "timescale";
    repo = "timescaledb-toolkit";
    tag = version;
    tag = finalAttrs.version;
    hash = "sha256-7yUbtWbYL4AnuUX8OXG4OVqYCY2Lf0pISSTlcFdPqog=";
  };

@@ -40,4 +40,4 @@
    platforms = postgresql.meta.platforms;
    license = lib.licenses.tsl;
  };
}
})