From a007338b341dd6cc883700537fbd6b44e7f598a0 Mon Sep 17 00:00:00 2001
From: Benjamin Lee <benjamin@computer.surgery>
Date: Thu, 23 May 2024 20:40:29 -0700
Subject: [PATCH] mark dynamic jemalloc builds as broken on linux

---
 flake.nix                 | 2 ++
 nix/pkgs/main/default.nix | 7 +++++++
 2 files changed, 9 insertions(+)

diff --git a/flake.nix b/flake.nix
index 98783c44..667f8dc8 100644
--- a/flake.nix
+++ b/flake.nix
@@ -90,6 +90,8 @@
         ])
         ++ scope.main.propagatedBuildInputs
         ++ scope.main.nativeBuildInputs;
+
+        meta.broken = scope.main.meta.broken;
       };
     in
     {
diff --git a/nix/pkgs/main/default.nix b/nix/pkgs/main/default.nix
index 758ed60f..a65f3850 100644
--- a/nix/pkgs/main/default.nix
+++ b/nix/pkgs/main/default.nix
@@ -155,4 +155,11 @@ craneLib.buildPackage ( commonAttrs // {
   };
 
   meta.mainProgram = commonAttrs.pname;
+  # Dynamically-linked jemalloc is broken on linux due to link-order problems,
+  # where the symbols are being resolved to libc malloc/free before jemalloc is
+  # loaded. This problem does not occur on darwin for unknown reasons.
+  meta.broken =
+    stdenv.isLinux &&
+    !stdenv.hostPlatform.isStatic &&
+    (featureEnabled "jemalloc");
 })