about summary refs log tree commit diff
path: root/pkgs/development/haskell-modules/lib
diff options
context:
space:
mode:
authorsternenseemann <sternenseemann@systemli.org>2023-02-04 01:44:36 +0100
committersternenseemann <sternenseemann@systemli.org>2023-02-04 12:34:07 +0100
commit63862f4a66c19edc38280c51386513f5cee30afc (patch)
treeb5ff7ac16553391b1e61750df39a6ca618652686 /pkgs/development/haskell-modules/lib
parent27179a22939f4d32af244009242a1c3dace9bb23 (diff)
haskell.packages.ghc94.X11-xft: automate workaround for cabal#8455
The current workaround for the regression is propagating the
runtime dependency closure (technically only Requires.private in the
pkg-config files). This can easily be done automatically by mimicking
how e.g. pkgsStatic converts buildInputs to propagatedBuildInputs.
This is extracted into a helper function,
__CabalEagerPkgConfigWorkaround, which can be applied to any package
easily.
Diffstat (limited to 'pkgs/development/haskell-modules/lib')
-rw-r--r--pkgs/development/haskell-modules/lib/compose.nix40
1 files changed, 40 insertions, 0 deletions
diff --git a/pkgs/development/haskell-modules/lib/compose.nix b/pkgs/development/haskell-modules/lib/compose.nix
index ebaba1a22fa6d..647e95211f1c3 100644
--- a/pkgs/development/haskell-modules/lib/compose.nix
+++ b/pkgs/development/haskell-modules/lib/compose.nix
@@ -464,4 +464,44 @@ rec {
   allowInconsistentDependencies = overrideCabal (drv: {
     allowInconsistentDependencies = true;
   });
+
+  # Work around a Cabal bug requiring pkg-config --static --libs to work even
+  # when linking dynamically, affecting Cabal 3.8 and 3.9.
+  # https://github.com/haskell/cabal/issues/8455
+  #
+  # For this, we treat the runtime system/pkg-config dependencies of a Haskell
+  # derivation as if they were propagated from their dependencies which allows
+  # pkg-config --static to work in most cases.
+  #
+  # Warning: This function may change or be removed at any time, e.g. if we find
+  # a different workaround, upstream fixes the bug or we patch Cabal.
+  __CabalEagerPkgConfigWorkaround =
+    let
+      # Take list of derivations and return list of the transitive dependency
+      # closure, only taking into account buildInputs. Loosely based on
+      # closePropagationFast.
+      propagatedPlainBuildInputs = drvs:
+        builtins.map (i: i.val) (
+          builtins.genericClosure {
+            startSet = builtins.map (drv:
+              { key = drv.outPath; val = drv; }
+            ) drvs;
+            operator = { val, ... }:
+              if !lib.isDerivation val
+              then [ ]
+              else
+                builtins.concatMap (drv:
+                  if !lib.isDerivation drv
+                  then [ ]
+                  else [ { key = drv.outPath; val = drv; } ]
+                ) val.buildInputs or [ ];
+          }
+        );
+    in
+    overrideCabal (old: {
+      benchmarkPkgconfigDepends = propagatedPlainBuildInputs old.benchmarkPkgconfigDepends or [ ];
+      executablePkgconfigDepends = propagatedPlainBuildInputs old.executablePkgconfigDepends or [ ];
+      libraryPkgconfigDepends = propagatedPlainBuildInputs old.libraryPkgconfigDepends or [ ];
+      testPkgconfigDepends = propagatedPlainBuildInputs old.testPkgconfigDepends or [ ];
+    });
 }