From f8c740b781135a7564fa32658c5887e606138e08 Mon Sep 17 00:00:00 2001 From: Naïm Favier Date: Sun, 20 Mar 2022 09:55:59 +0100 Subject: haskellPackages.misfortune: apply patch to fix GHC 9 build --- .../haskell-modules/configuration-common.nix | 6 ++ .../haskell-modules/patches/misfortune-ghc9.patch | 70 ++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 pkgs/development/haskell-modules/patches/misfortune-ghc9.patch (limited to 'pkgs/development') diff --git a/pkgs/development/haskell-modules/configuration-common.nix b/pkgs/development/haskell-modules/configuration-common.nix index f533bbd62d5c..1dd02e762f14 100644 --- a/pkgs/development/haskell-modules/configuration-common.nix +++ b/pkgs/development/haskell-modules/configuration-common.nix @@ -2372,6 +2372,12 @@ self: super: { # https://github.com/kuribas/mfsolve/issues/8 mfsolve = dontCheck super.mfsolve; + # compatibility with random-fu 0.3 https://github.com/mokus0/misfortune/pull/5 + misfortune = appendPatch ./patches/misfortune-ghc9.patch (overrideCabal (drv: { + revision = null; + editedCabalFile = null; + }) super.misfortune); + # Ships a custom cabal-doctest Setup.hs in the release tarball, but the actual # test suite is commented out, so the required dependency is missing naturally. # We need to use a default Setup.hs instead. Current master doesn't exhibit diff --git a/pkgs/development/haskell-modules/patches/misfortune-ghc9.patch b/pkgs/development/haskell-modules/patches/misfortune-ghc9.patch new file mode 100644 index 000000000000..39f983b15d78 --- /dev/null +++ b/pkgs/development/haskell-modules/patches/misfortune-ghc9.patch @@ -0,0 +1,70 @@ +diff --git a/misfortune.cabal b/misfortune.cabal +index f5d0dd3..faa5794 100644 +--- a/misfortune.cabal ++++ b/misfortune.cabal +@@ -113,7 +113,8 @@ Library + directory, + filepath, + knob, +- random-fu >= 0.2.2, ++ random, ++ random-fu >= 0.3, + semigroups, + text, + utf8-string, +diff --git a/src/Data/Fortune.hs b/src/Data/Fortune.hs +index 16d221e..ffbc970 100644 +--- a/src/Data/Fortune.hs ++++ b/src/Data/Fortune.hs +@@ -64,6 +64,7 @@ import Paths_misfortune + import System.Directory + import System.Environment + import System.FilePath ++import System.Random.Stateful (newIOGenM, newStdGen) + + -- |The number of fortune strings in the index + numFortunes :: S.FortuneStats -> Int +@@ -233,9 +234,10 @@ randomFortune paths = withFortuneFiles '%' False paths $ \fs -> do + -- random fortune from that file (unformly). + randomFortuneFromRandomFile :: RVar FortuneFile -> IO String + randomFortuneFromRandomFile file = do +- f <- sample file ++ gen <- newStdGen >>= newIOGenM ++ f <- sampleFrom gen file + n <- getNumFortunes f +- i <- sample (uniform 0 (n-1)) ++ i <- sampleFrom gen (uniform 0 (n-1)) + T.unpack <$> getFortune f i + + -- |Given a list of 'FortuneFile's, compute a distrubution over them weighted by the number +diff --git a/src/Fortune.hs b/src/Fortune.hs +index 5a27578..d6ffb74 100644 +--- a/src/Fortune.hs ++++ b/src/Fortune.hs +@@ -21,6 +21,7 @@ import System.Environment + import System.Exit + import System.FilePath + import System.IO ++import System.Random.Stateful (newIOGenM, newStdGen) + import Text.Printf + import Text.Regex.Base + import Text.Regex.PCRE +@@ -200,6 +201,7 @@ main = do + fortunes <- filterM (filterFile args) (fortuneFiles args) + + dist <- getDist args fortunes ++ gen <- newStdGen >>= newIOGenM + + when (numEvents dist == 0) $ do + hPutStrLn stderr "No fortunes matched the filter criteria" +@@ -225,8 +227,8 @@ main = do + , let pctStr = printf "(%.2f%%)" (100 * weight / totalWeight dist) :: String + ] + else do +- (file, fortuneDist) <- sample dist +- fortune <- sample fortuneDist ++ (file, fortuneDist) <- sampleFrom gen dist ++ fortune <- sampleFrom gen fortuneDist + putStrLn . T.unpack =<< getFortune file fortune + + getDist :: Args -> [FortuneFile] -> IO (Categorical Float (FortuneFile, Categorical Float Int)) -- cgit 1.4.1