about summary refs log tree commit diff
path: root/third_party/gerrit_plugins/builder.nix
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/gerrit_plugins/builder.nix')
-rw-r--r--third_party/gerrit_plugins/builder.nix59
1 files changed, 35 insertions, 24 deletions
diff --git a/third_party/gerrit_plugins/builder.nix b/third_party/gerrit_plugins/builder.nix
index 7676f50208..50a4e78ae7 100644
--- a/third_party/gerrit_plugins/builder.nix
+++ b/third_party/gerrit_plugins/builder.nix
@@ -1,28 +1,39 @@
-{ depot, pkgs, ... }:
+{ depot, lib, pkgs, ... }:
 {
-  buildGerritBazelPlugin = {
-    name,
-    src,
-    depsOutputHash,
-    overlayPluginCmd ? ''
-      cp -R "${src}" "$out/plugins/${name}"
-    '',
-  }: ((depot.third_party.gerrit.override {
-    name = "${name}.jar";
+  buildGerritBazelPlugin =
+    { name
+    , src
+    , depsOutputHash
+    , overlayPluginCmd ? ''
+        cp -R "${src}" "$out/plugins/${name}"
+      ''
+    , postPatch ? ""
+    , patches ? [ ]
+    }: ((depot.third_party.gerrit.override {
+      name = "${name}.jar";
 
-    src = pkgs.runCommandLocal "${name}-src" {} ''
-      cp -R "${depot.third_party.gerrit.src}" "$out"
-      chmod +w "$out/plugins"
-      ${overlayPluginCmd}
-    '';
+      src = pkgs.runCommandLocal "${name}-src" { } ''
+        cp -R "${depot.third_party.gerrit.src}" "$out"
+        chmod +w "$out/plugins"
+        ${overlayPluginCmd}
+      '';
 
-    bazelTarget = "//plugins/${name}";
-  }).overrideAttrs (super: {
-    deps = super.deps.overrideAttrs (superDeps: {
-      outputHash = depsOutputHash;
-    });
-    installPhase = ''
-      cp "bazel-bin/plugins/${name}/${name}.jar" "$out"
-    '';
-  }));
+      bazelTargets = [ "//plugins/${name}" ];
+    }).overrideAttrs (super: {
+      deps = super.deps.overrideAttrs (superDeps: {
+        outputHash = depsOutputHash;
+      });
+      installPhase = ''
+        cp "bazel-bin/plugins/${name}/${name}.jar" "$out"
+      '';
+      postPatch = ''
+        ${super.postPatch or ""}
+        pushd "plugins/${name}"
+        ${lib.concatMapStringsSep "\n" (patch: ''
+          patch -p1 < ${patch}
+        '') patches}
+        popd
+        ${postPatch}
+      '';
+    }));
 }