From bde376725ed5dae962b1a61117db2bf3d0a76a5b Mon Sep 17 00:00:00 2001
From: Ellie Hermaszewska <git@monoid.al>
Date: Wed, 17 Nov 2021 14:48:36 +0800
Subject: [PATCH] generate-nix-overrides.hs: Use haskell.lib.compose

This is passed in as haskellLib, as in convention in nixpkgs, to allow easy of
calling the generated override file from
pkgs/development/haskell-modules/default.nix in nixpkgs.

haskell.lib.compose is a set of "more composable" haskell library functions,
they take the "pkg" argument last.

See https://github.com/NixOS/nixpkgs/pull/142940 for more info.
---
 scripts/README.md                 |  2 +-
 scripts/generate-nix-overrides.hs | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/scripts/README.md b/scripts/README.md
index aee3b287..949dbab1 100644
--- a/scripts/README.md
+++ b/scripts/README.md
@@ -26,7 +26,7 @@ self: super:
   ghcHEAD = super.haskell.packages.ghcHEAD.override
   { overrides = sel: sup:
                   # The patches from the directory
-                  ((super.callPackage self.patches {} sel sup)
+                  ((super.callPackage self.patches { haskellLib = haskell.lib.compose; } sel sup)
                   # Any more local overrides you want.
                   // { mkDerivation = drv: sup.mkDerivation
                         ( drv // { jailbreak = true; doHaddock = false; });
diff --git a/scripts/generate-nix-overrides.hs b/scripts/generate-nix-overrides.hs
index 4c826055..ce36b5ae 100755
--- a/scripts/generate-nix-overrides.hs
+++ b/scripts/generate-nix-overrides.hs
@@ -45,7 +45,7 @@ mkOverride (display -> pName, patches) =
 
 override :: FilePath -> FilePath -> FilePath -> String -> PatchType -> String
 override prefix patchDir extlessPath nixexpr ptype =
-  unwords ["(", patchFunction ptype, nixexpr, prefix </> patchDir </> addExtension extlessPath (patchTypeExt ptype), ")"]
+  unwords ["(", patchFunction ptype, prefix </> patchDir </> addExtension extlessPath (patchTypeExt ptype), nixexpr, ")"]
 
 generateOverride :: FilePath -> FilePath -> (FilePath, [PatchType]) -> IO (PackageName, ([Int], String))
 generateOverride prefix patchDir (patchExtless, patchTypes) = do
@@ -54,13 +54,13 @@ generateOverride prefix patchDir (patchExtless, patchTypes) = do
   let pname = display (packageName pid)
       version = versionNumbers (packageVersion pid)
   return . (packageName pid,) . (version,) $ 
-    "haskell.lib.doJailbreak (dontRevise "
+    "haskellLib.doJailbreak (dontRevise "
     ++ foldl' (override prefix patchDir patchExtless) ("super."++pname) patchTypes ++ ")"
 
 patchFunction :: PatchType -> String
 patchFunction = \case
   CabalPatch  -> "setCabalFile"
-  NormalPatch -> "haskell.lib.appendPatch"
+  NormalPatch -> "haskellLib.appendPatch"
 
 patchTypeExt :: PatchType -> String
 patchTypeExt = \case
@@ -85,9 +85,9 @@ main = do
                 [prefix, dir] -> return (prefix, dir)
                 _     -> fail "Usage: generate-nix-overrides [<prefix>, patchdir]"
   overrides <- generateOverrides prefix patchDir
-  putStrLn "{haskell}:"
-  putStrLn "let dontRevise = pkg: haskell.lib.overrideCabal pkg (old: { editedCabalFile = null; }); in"
-  putStrLn "let setCabalFile = pkg: file: haskell.lib.overrideCabal pkg (old: { postPatch = ''cp ${file} ${old.pname}.cabal''; }); in"
+  putStrLn "{haskellLib}:"
+  putStrLn "let dontRevise = haskellLib.overrideCabal (old: { editedCabalFile = null; }); in"
+  putStrLn "let setCabalFile = file: haskellLib.overrideCabal (old: { postPatch = ''cp ${file} ${old.pname}.cabal''; }); in"
   putStrLn "self: super: {\n"
   putStrLn overrides
   putStrLn "}"
-- 
GitLab