@@ -1,10 +1,8 @@
11{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
32
43module Distribution.Nixpkgs.Haskell.FromCabal.PostProcess ( postProcess, pkg ) where
54
65import Control.Lens
7−import Control.Monad.Trans.State
86import Data.List.Split
97import Data.Map ( Map )
108import qualified Data.Map as Map
@@ -13,7 +11,6 @@ import Data.Set ( Set )
1311import qualified Data.Set as Set
1412import Distribution.Nixpkgs.Haskell
1513import Distribution.Nixpkgs.Meta
16−import Distribution.Nixpkgs.License
1714import Distribution.Package
1815import Distribution.System
1916import Distribution.Text
@@ -21,11 +18,7 @@ import Distribution.Version
2118import Language.Nix
2219
2320postProcess :: Derivation -> Derivation
24−postProcess deriv =
25− foldr (.) id [ f | (Dependency n vr _, f) <- hooks, packageName deriv == n, packageVersion deriv `withinRange` vr ]
26− . fixGtkBuilds
27− . fixBuildDependsForTools
28− $ deriv
21+postProcess deriv = foldr ($) (fixGtkBuilds deriv) [ f | (Dependency n vr, f) <- hooks, packageName deriv == n, packageVersion deriv `withinRange` vr ]
2922
3023fixGtkBuilds :: Derivation -> Derivation
3124fixGtkBuilds drv = drv & dependencies . pkgconfig %~ Set.filter (not . collidesWithHaskellName)
@@ -43,69 +36,34 @@ fixGtkBuilds drv = drv & dependencies . pkgconfig %~ Set.filter (not . collidesW
4336 buildDeps :: Map Identifier Path
4437 buildDeps = Map.delete myName (toMapOf (dependencies . haskell . to Set.toList . traverse . binding . ifolded) drv)
4538
46−-- Per https://github.com/haskell/cabal/issues/5412 hvr considers
47−-- `build-depends` providing executables an accident, and fragile one at that,
48−-- unworthy of any compatibility hacks. But while he and the other Hackage
49−-- maintainers is dedicated to fixing executables and libraries on Hackage, test
50−-- suites and benchmarks are not a priority, as it is trivial to skip building
51−-- test-suites with cabal-install. Nix however wishes to build test suites much
52−-- more widely, so skipping those components is not an option.
53−--
54−-- Between that, and Stack not changing behavior as of
55−-- https://github.com/commercialhaskell/stack/pull/4132, it seems likely that
56−-- for a while packages scraped from Hackage will continue to improperly use
57−-- `build-depends: package-for-tool` instead of `build-tool-depends` (which does
58−-- also work for Stack). Until that changes, we provide do this to work around
59−-- those package's brokenness.
60−fixBuildDependsForTools :: Derivation -> Derivation
61−fixBuildDependsForTools = foldr (.) id
62− [ fmap snd $ runState $ do
63− needs <- use $ cloneLens c . haskell . contains p
64− cloneLens c . tool . contains p ||= needs
65− | (c :: ALens' Derivation BuildInfo) <- [ testDepends, benchmarkDepends ]
66− , p <- self <$> [ "hspec-discover"
67− , "tasty-discover"
68− , "hsx2hs"
69− , "markdown-unlit"
70− ]
71− ]
72−
7339hooks :: [(Dependency, Derivation -> Derivation)]
7440hooks =
7541 [ ("Agda < 2.5", set (executableDepends . tool . contains (pkg "emacs")) True . set phaseOverrides agdaPostInstall)
7642 , ("Agda >= 2.5", set (executableDepends . tool . contains (pkg "emacs")) True . set phaseOverrides agda25PostInstall)
7743 , ("alex < 3.1.5", set (testDepends . tool . contains (pkg "perl")) True)
7844 , ("alex", set (executableDepends . tool . contains (self "happy")) True)
79− , ("alsa-core", over (metaSection . platforms) (Set.filter (\(Platform _ os) -> os == Linux)))
45+ , ("alsa-core", over (metaSection . platforms) (Set.filter (\(Platform _ os) -> os == Linux))) , ("bustle", set (libraryDepends . pkgconfig . contains "system-glib = pkgs.glib") True)
8046 , ("bindings-GLFW", over (libraryDepends . system) (Set.union (Set.fromList [bind "pkgs.xorg.libXext", bind "pkgs.xorg.libXfixes"])))
81− , ("bindings-lxc", over (metaSection . platforms) (Set.filter (\(Platform _ os) -> os == Linux)))
82− , ("bustle", bustleOverrides)
47+ , ("bindings-lxc", over (metaSection . platforms) (Set.filter (\(Platform _ os) -> os == Linux))) , ("bustle", set (libraryDepends . pkgconfig . contains "system-glib = pkgs.glib") True)
48+ , ("bustle", set (libraryDepends . pkgconfig . contains "system-glib = pkgs.glib") True)
8349 , ("Cabal", set doCheck False) -- test suite doesn't work in Nix
8450 , ("Cabal >2.2", over (setupDepends . haskell) (Set.union (Set.fromList [self "mtl", self "parsec"]))) -- https://github.com/haskell/cabal/issues/5391
8551 , ("cabal-helper", set doCheck False) -- https://github.com/DanielG/cabal-helper/issues/17
8652 , ("cabal-install", set doCheck False . set phaseOverrides cabalInstallPostInstall)
87− , ("cabal2nix > 2", cabal2nixOverrides)
8853 , ("darcs", set phaseOverrides darcsInstallPostInstall . set doCheck False)
8954 , ("dbus", set doCheck False) -- don't execute tests that try to access the network
9055 , ("dns", set testTarget "spec") -- don't execute tests that try to access the network
9156 , ("eventstore", over (metaSection . platforms) (Set.filter (\(Platform arch _) -> arch == X86_64)))
9257 , ("freenect < 1.2.1", over configureFlags (Set.union (Set.fromList ["--extra-include-dirs=${pkgs.freenect}/include/libfreenect", "--extra-lib-dirs=${pkgs.freenect}/lib"])))
93− , ("fltkhs", set (libraryDepends . system . contains (pkg "fltk14")) True . over (libraryDepends . pkgconfig) (Set.union (pkgs ["libGLU", "libGL"]))) -- TODO: fltk14 belongs into the *setup* dependencies.
9458 , ("gf", set phaseOverrides gfPhaseOverrides . set doCheck False)
9559 , ("gi-cairo", giCairoPhaseOverrides) -- https://github.com/haskell-gi/haskell-gi/issues/36
96− , ("gi-gdk", set runHaddock True )
97− , ("gi-gio", set runHaddock True )
98− , ("gi-glib", set runHaddock True )
9960 , ("gi-gst", giGstLibOverrides "gstreamer") -- https://github.com/haskell-gi/haskell-gi/issues/36
10061 , ("gi-gstaudio", giGstLibOverrides "gst-plugins-base") -- https://github.com/haskell-gi/haskell-gi/issues/36
10162 , ("gi-gstbase", giGstLibOverrides "gst-plugins-base") -- https://github.com/haskell-gi/haskell-gi/issues/36
10263 , ("gi-gstvideo", giGstLibOverrides "gst-plugins-base") -- https://github.com/haskell-gi/haskell-gi/issues/36
103− , ("gi-gtk", set runHaddock True )
10464 , ("gi-javascriptcore < 4.0.0.0", webkitgtk24xHook) -- https://github.com/haskell-gi/haskell-gi/issues/36
10565 , ("gi-pango", giCairoPhaseOverrides) -- https://github.com/haskell-gi/haskell-gi/issues/36
106− , ("gi-pango", set runHaddock True )
10766 , ("gi-pangocairo", giCairoPhaseOverrides) -- https://github.com/haskell-gi/haskell-gi/issues/36
108− , ("gi-vte", set runHaddock True )
10967 , ("gi-webkit", webkitgtk24xHook) -- https://github.com/haskell-gi/haskell-gi/issues/36
11068 , ("gio", set (libraryDepends . pkgconfig . contains "system-glib = pkgs.glib") True)
11169 , ("git", set doCheck False) -- https://github.com/vincenthz/hit/issues/33
@@ -116,7 +74,6 @@ hooks =
11674 , ("GlomeVec", set (libraryDepends . pkgconfig . contains (bind "self.llvmPackages.llvm")) True)
11775 , ("graphviz", set (testDepends . system . contains (pkg "graphviz")) True)
11876 , ("gtk3", gtk3Hook)
119− , ("gtkglext", gtkglextHook)
12077 , ("haddock", haddockHook) -- https://github.com/haskell/haddock/issues/511
12178 , ("hakyll", set (testDepends . tool . contains (pkg "utillinux")) True) -- test suite depends on "rev"
12279 , ("haskell-src-exts", set doCheck False)
@@ -127,8 +84,8 @@ hooks =
12784 , ("holy-project", set doCheck False) -- attempts to access the network
12885 , ("hoogle", set testTarget "--test-option=--no-net")
12986 , ("hsignal < 0.2.7.4", set phaseOverrides "prePatch = \"rm -v Setup.lhs\";") -- https://github.com/amcphail/hsignal/issues/1
130− , ("hslua < 0.9.3", over (libraryDepends . system) (replace (pkg "lua") (pkg "lua5_1")))
131− , ("hslua >= 0.9.3", over (libraryDepends . system) (replace (pkg "lua") (pkg "lua5_3")))
87+ , ("hslua < 0.9.3", over (libraryDepends . each) (replace (pkg "lua") (pkg "lua5_1")))
88+ , ("hslua >= 0.9.3", over (libraryDepends . each) (replace (pkg "lua") (pkg "lua5_3")))
13289 , ("hspec-core >= 2.4.4", hspecCoreOverrides)
13390 , ("http-client", set doCheck False) -- attempts to access the network
13491 , ("http-client-openssl >= 0.2.0.1", set doCheck False) -- attempts to access the network
@@ -148,13 +105,10 @@ hooks =
148105 , ("network-attoparsec", set doCheck False) -- test suite requires network access
149106 , ("numeric-qq", set doCheck False) -- test suite doesn't finish even after 1+ days
150107 , ("opencv", opencvOverrides)
151− , ("pandoc >= 1.16.0.2 && < 2.5", set doCheck False) -- https://github.com/jgm/pandoc/issues/2709 and https://github.com/fpco/stackage/issues/1332
152− , ("pandoc < 2.6", pandocPre26Overrides)
153− , ("pandoc >= 2.6", pandocOverrides)
154− , ("pandoc-citeproc", set doCheck False) -- https://github.com/jgm/pandoc-citeproc/issues/369
108+ , ("pandoc >= 1.16.0.2", set doCheck False) -- https://github.com/jgm/pandoc/issues/2709 and https://github.com/fpco/stackage/issues/1332
109+ , ("pandoc", set jailbreak False) -- jailbreak-cabal break the build
110+ , ("pandoc-citeproc", set doCheck False) -- https://github.com/jgm/pandoc-citeproc/issues/172
155111 , ("purescript", set doCheck False) -- test suite doesn't cope with Nix build env
156− , ("proto-lens-protobuf-types", set (libraryDepends . tool . contains (pkg "protobuf")) True)
157− , ("proto-lens-protoc", set (libraryDepends . tool . contains (pkg "protobuf")) True)
158112 , ("qtah-cpp-qt5", set (libraryDepends . system . contains (bind "pkgs.qt5.qtbase")) True)
159113 , ("qtah-qt5", set (libraryDepends . tool . contains (bind "pkgs.qt5.qtbase")) True)
160114 , ("readline", over (libraryDepends . system) (Set.union (pkgs ["readline", "ncurses"])))
@@ -168,11 +122,10 @@ hooks =
168122 , ("target", set (testDepends . system . contains (pkg "z3")) True)
169123 , ("terminfo", set (libraryDepends . system . contains (pkg "ncurses")) True)
170124 , ("text", set doCheck False) -- break infinite recursion
171− , ("tensorflow-proto", set (libraryDepends . tool . contains (pkg "protobuf")) True)
172125 , ("thyme", set (libraryDepends . tool . contains (self "cpphs")) True) -- required on Darwin
173126 , ("twilio", set doCheck False) -- attempts to access the network
174127 , ("tz", set phaseOverrides "preConfigure = \"export TZDIR=${pkgs.tzdata}/share/zoneinfo\";")
175− , ("udev", over (metaSection . platforms) (Set.filter (\(Platform _ os) -> os == Linux)))
128+ , ("udev", over (metaSection . platforms) (Set.filter (\(Platform _ os) -> os == Linux))) , ("bustle", set (libraryDepends . pkgconfig . contains "system-glib = pkgs.glib") True)
176129 , ("webkitgtk3", webkitgtk24xHook) -- https://github.com/haskell-gi/haskell-gi/issues/36
177130 , ("webkitgtk3-javascriptcore", webkitgtk24xHook) -- https://github.com/haskell-gi/haskell-gi/issues/36
178131 , ("websockets", set doCheck False) -- https://github.com/jaspervdj/websockets/issues/104
@@ -181,10 +134,9 @@ hooks =
181134 , ("wxc", wxcHook)
182135 , ("wxcore", set (libraryDepends . pkgconfig . contains (pkg "wxGTK")) True)
183136 , ("X11", over (libraryDepends . system) (Set.union (Set.fromList $ map bind ["pkgs.xorg.libXinerama","pkgs.xorg.libXext","pkgs.xorg.libXrender","pkgs.xorg.libXScrnSaver"])))
184− , ("xmonad >= 0.14.2", set phaseOverrides xmonadPostInstall)
137+ , ("xmonad", set phaseOverrides xmonadPostInstall)
185138 , ("zip-archive < 0.3.1", over (testDepends . tool) (replace (self "zip") (pkg "zip")))
186139 , ("zip-archive >= 0.3.1 && < 0.3.2.3", over (testDepends . tool) (Set.union (Set.fromList [pkg "zip", pkg "unzip"]))) -- https://github.com/jgm/zip-archive/issues/35
187− , ("zip-archive >= 0.4", set (testDepends . tool . contains (pkg "which")) True)
188140 ]
189141
190142pkg :: Identifier -> Binding
@@ -202,18 +154,10 @@ bind s = binding # (i, path # is)
202154 is = map (review ident) (splitOn "." s)
203155 i = last is
204156
205−-- | @replace old new bset@ replaces the Nix binding @old@ with @new@ in the
206−-- set of bindings @bset@. If @old@ is not found in @bset@, then the function
207−-- fails with an 'error'.
208157replace :: Binding -> Binding -> Set Binding -> Set Binding
209−replace old new bs
210− | old `Set.member` bs = Set.insert new (Set.delete old bs)
211− | otherwise = error (unwords [ "post-process: cannot replace name binding"
212− , show old, "by", show new
213− , "because it's not found in set"
214− , show bs
215− ])
158+replace old new bs = if old `Set.member` bs then Set.insert new (Set.delete old bs) else bs
216159
160+-- TODO: I need to figure out how to conveniently replace a binding in a set.
217161gtk3Hook :: Derivation -> Derivation -- https://github.com/NixOS/cabal2nix/issues/145
218162gtk3Hook = set (libraryDepends . pkgconfig . contains (pkg "gtk3")) True
219163 . over (libraryDepends . pkgconfig) (Set.filter (\b -> view localName b /= "gtk3"))
@@ -230,12 +174,13 @@ gitAnnexHook = set phaseOverrides gitAnnexOverrides
230174 where
231175 gitAnnexOverrides = unlines
232176 [ "preConfigure = \"export HOME=$TEMPDIR; patchShebangs .\";"
233− , "postBuild = ''"
177+ , "installPhase = \"make PREFIX=$out BUILDER=: install\";"
178+ , "checkPhase = ''"
234179 , " ln -sf dist/build/git-annex/git-annex git-annex"
235180 , " ln -sf git-annex git-annex-shell"
181+ , " export PATH+=\":$PWD\""
182+ , " git-annex test"
236183 , "'';"
237− , "installPhase = \"make PREFIX=$out BUILDER=: install install-completions\";"
238− , "checkPhase = ''PATH+=\":$PWD\" git-annex test'';"
239184 , "enableSharedExecutables = false;"
240185 ]
241186 buildInputs = pkgs ["git","rsync","gnupg","curl","wget","lsof","openssh","which","bup","perl"]
@@ -256,7 +201,7 @@ gfPhaseOverrides = unlines
256201 , " sed -i \"s|numJobs (bf bi)++||\" ./Setup.hs"
257202 -- Parallel compilation fails. Disable it.
258203 , "'';"
259− , "preBuild = ''export LD_LIBRARY_PATH=`pwd`/dist/build''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH'';"
204+ , "preBuild = ''export LD_LIBRARY_PATH=`pwd`/dist/build:$LD_LIBRARY_PATH'';"
260205 -- The build step itself, after having built the library, needs to be able
261206 -- to find the library it just built in order to compile grammar files.
262207 ]
@@ -292,8 +237,10 @@ darcsInstallPostInstall = unlines
292237xmonadPostInstall :: String
293238xmonadPostInstall = unlines
294239 [ "postInstall = ''"
295− , " install -D man/xmonad.1 ''${!outputDoc}/share/man/man1/xmonad.1"
296− , " install -D man/xmonad.hs ''${!outputDoc}/share/doc/$name/sample-xmonad.hs"
240+ , " shopt -s globstar"
241+ , " mkdir -p $doc/share/man/man1"
242+ , " mv \"$data/\"**\"/man/\"*[0-9] $doc/share/man/man1/"
243+ , " rm \"$data/\"**\"/man/\"*"
297244 , "'';"
298245 ]
299246
@@ -360,50 +307,8 @@ webkitgtk24xHook = set (libraryDepends . pkgconfig . contains (pkg "webkitgtk24x
360307opencvOverrides :: Derivation -> Derivation
361308opencvOverrides = set phaseOverrides "hardeningDisable = [ \"bindnow\" ];"
362309 . over (libraryDepends . pkgconfig) (replace (pkg "opencv") (pkg "opencv3"))
310+ . set (configureFlags . contains "--with-gcc=${stdenv.cc}/bin/c++") True
311+ . set (configureFlags . contains "--with-ld=${stdenv.cc}/bin/c++") True
363312
364313hspecCoreOverrides :: Derivation -> Derivation -- https://github.com/hspec/hspec/issues/330
365314hspecCoreOverrides = set phaseOverrides "testTarget = \"--test-option=--skip --test-option='Test.Hspec.Core.Runner.hspecResult runs specs in parallel'\";"
366−
367−cabal2nixOverrides :: Derivation -> Derivation
368−cabal2nixOverrides = set phaseOverrides $ unlines
369− [ "preCheck = ''"
370− , " export PATH=\"$PWD/dist/build/cabal2nix:$PATH\""
371− , " export HOME=\"$TMPDIR/home\""
372− , "'';"
373− ]
374−
375−gtkglextHook :: Derivation -> Derivation
376−gtkglextHook = over (libraryDepends . system) (Set.union (Set.fromList deps))
377− where
378− deps :: [Binding]
379− deps = bind <$> [ "pkgs.gtk2"
380− , "pkgs.libGLU"
381− , "pkgs.xorg.libSM"
382− , "pkgs.xorg.libICE"
383− , "pkgs.xorg.libXt"
384− , "pkgs.xorg.libXmu"
385− ]
386−
387−pandocPre26Overrides :: Derivation -> Derivation
388−pandocPre26Overrides = set phaseOverrides postInstall
389− where
390− postInstall = unlines [ "postInstall = ''"
391− , " mkdir -p $out/share"
392− , " mv $data/*/*/man $out/share/"
393− , "'';"
394− ]
395−
396−pandocOverrides :: Derivation -> Derivation
397−pandocOverrides = set phaseOverrides postInstall
398− where
399− postInstall = unlines [ "postInstall = ''"
400− , " mkdir -p $out/share/man/man1"
401− , " mv \"man/\"*.1 $out/share/man/man1/"
402− , "'';"
403− ]
404−
405−bustleOverrides :: Derivation -> Derivation
406−bustleOverrides = set (libraryDepends . pkgconfig . contains "system-glib = pkgs.glib") True
407− . set (executableDepends . pkgconfig . contains "gio-unix = null") False
408− . set (metaSection . license) (Known "stdenv.lib.licenses.lgpl21Plus")
409− . set (metaSection . hydraPlatforms) allKnownPlatforms