From bbe38d31a838a6cf2cf5f4637650208f06bfe621 Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Tue, 25 Apr 2023 15:55:53 -0400
Subject: [PATCH] Fix the `zlib` C library dependency in the Nix build

---
 flake.nix                |  1 +
 nix/haskell-packages.nix | 17 ++++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/flake.nix b/flake.nix
index fd06ef7..c0573fb 100644
--- a/flake.nix
+++ b/flake.nix
@@ -28,6 +28,7 @@
         compilerVersion = ghcVersion;
         packageName = "gbs-downloader";
         hsPkgsOverrides = import ./nix/haskell-packages.nix {
+          inherit pkgs;
           haskellLib = pkgs.haskell.lib;
         };
       };
diff --git a/nix/haskell-packages.nix b/nix/haskell-packages.nix
index 0411c50..834ddd8 100644
--- a/nix/haskell-packages.nix
+++ b/nix/haskell-packages.nix
@@ -1,8 +1,23 @@
-{haskellLib}: hfinal: hprev: {
+{
+  pkgs,
+  haskellLib,
+}: hfinal: hprev: {
   tahoe-chk = hfinal.callPackage ./tahoe-chk.nix {};
   tahoe-great-black-swamp = hfinal.callPackage ./tahoe-great-black-swamp.nix {};
 
   # A broken dependency of a tahoe-great-black-swamp executable that we don't
   # use.  Flip the broken bit so we can get a build.
   language-ecmascript = haskellLib.unmarkBroken hprev.language-ecmascript;
+
+  # hs-flake-utils does a callCabal2nix for us but we can't use it because we
+  # need to overide an argument.  This overlay runs before the hs-flake-utils
+  # overlay (a mistake?) so we can't even use hprev.gbs-downloader.override -
+  # we just have to re-do it all ourselves.
+  gbs-downloader = hfinal.callCabal2nix "gbs-downloader" ../. {
+    # cabal2nix gives the generated nix expression a `zlib` parameter which is
+    # then satisfied *from the Haskell package set* because there is a zlib
+    # package there and it gets precedence over the zlib in the top-level
+    # package set.  Then the build fails because that's not the zlib we want.
+    inherit (pkgs) zlib;
+  };
 }
-- 
GitLab