git.iko.soy/typeable/cabal2nix
on master help sign in
Add NFData instances for our data types so that we can use them in combination with monad-par.
commit28d0d5084046b47e760c583e6aaa070270a15468 authorPeter Simons <simons@cryp.to> dateSun 7 Dec 2014, 16:16 (12 years ago) parentf4fb199
5 files changed+34−9
cabal2nix.cabal+2−2 src/Distribution/NixOS/Derivation/Cabal.hs+17−5 src/Distribution/NixOS/Derivation/License.hs+6−1 src/Distribution/NixOS/Derivation/Meta.hs+5−1 src/Distribution/NixOS/Fetch.hs+4
cabal2nix.cabal+2−2
@@ -59,7 +59,7 @@ Executable cabal2nix
5959 main-is: cabal2nix.hs
6060 hs-source-dirs: src
6161 Build-Depends: base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.18,
62− filepath, directory, process, hackage-db >= 1.11, transformers
62+ filepath, directory, process, hackage-db >= 1.11, transformers, deepseq
6363 Extensions: PatternGuards, RecordWildCards, CPP
6464 Ghc-Options: -Wall
6565 other-modules: Cabal2Nix.CorePackages
@@ -83,7 +83,7 @@ Executable hackage4nix
8383 hs-source-dirs: src
8484 Build-Depends: base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.18,
8585 mtl, containers, directory, filepath, hackage-db >= 1.11,
86− transformers, process
86+ transformers, process, deepseq
8787 Extensions: PatternGuards, RecordWildCards, CPP
8888 Ghc-Options: -Wall
8989 other-modules: Cabal2Nix.CorePackages
src/Distribution/NixOS/Derivation/Cabal.hs+17−5
@@ -20,20 +20,21 @@ module Distribution.NixOS.Derivation.Cabal
2020 )
2121 where
2222
23+import Control.DeepSeq
24+import Data.Char
25+import Data.Function
26+import Data.List
27+import Data.Version
2328import Distribution.NixOS.Derivation.Meta
2429import Distribution.NixOS.Fetch
2530import Distribution.NixOS.PrettyPrinting
2631import Distribution.NixOS.Regex hiding ( empty )
2732import Distribution.Package
28−import Distribution.Text
2933#ifdef __HADDOCK__
3034import Distribution.PackageDescription ( PackageDescription )
3135#endif
3236import Distribution.PackageDescription ( FlagAssignment, FlagName(..) )
33−import Data.Version
34−import Data.List
35−import Data.Char
36−import Data.Function
37+import Distribution.Text
3738
3839-- | A represtation of Nix expressions for building Haskell packages.
3940-- The data type correspond closely to the definition of
@@ -73,6 +74,17 @@ instance Text Derivation where
7374instance Package Derivation where
7475 packageId deriv = PackageIdentifier (PackageName (pname deriv)) (version deriv)
7576
77+instance NFData Derivation where
78+ rnf (MkDerivation a b c d e f g h i j k l m n o p q r t u v) =
79+ a `deepseq` b `deepseq` c `deepseq` d `deepseq` e `deepseq` f `deepseq` g `deepseq`
80+ h `deepseq` i `deepseq` j `deepseq` k `deepseq` l `deepseq` m `deepseqFlagAssignment` n `deepseq`
81+ o `deepseq` p `deepseq` q `deepseq` r `deepseq` t `deepseq` u `deepseq` v `deepseq` ()
82+
83+-- FlagName has no NFData instance in old version of Cabal.
84+deepseqFlagAssignment :: FlagAssignment -> a -> a
85+deepseqFlagAssignment [] b = b
86+deepseqFlagAssignment ((FlagName n, v):as) b = n `deepseq` v `deepseq` as `deepseqFlagAssignment` b
87+
7688renderDerivation :: Derivation -> Doc
7789renderDerivation deriv =
7890 text "# This file was auto-generated by cabal2nix. Please do NOT edit manually!" $$
src/Distribution/NixOS/Derivation/License.hs+6−1
@@ -13,9 +13,10 @@
1313
1414module Distribution.NixOS.Derivation.License ( License(..) ) where
1515
16+import Control.DeepSeq
17+import Data.Maybe
1618import Distribution.NixOS.PrettyPrinting
1719import Distribution.Text
18−import Data.Maybe
1920
2021-- | The representation for licenses used in Nix derivations. Known
2122-- licenses are Nix expressions -- such as @stdenv.lib.licenses.bsd3@
@@ -49,3 +50,7 @@ instance Text License where
4950 disp (Known x) = text x
5051 disp (Unknown x) = string (fromMaybe "unknown" x)
5152 parse = error "parsing Distribution.NixOS.Derivation.License is not supported yet"
53+
54+instance NFData License where
55+ rnf (Known s) = rnf s
56+ rnf (Unknown s) = rnf s
src/Distribution/NixOS/Derivation/Meta.hs+5−1
@@ -17,8 +17,9 @@ module Distribution.NixOS.Derivation.Meta
1717 )
1818 where
1919
20−import Distribution.NixOS.PrettyPrinting
20+import Control.DeepSeq
2121import Distribution.NixOS.Derivation.License
22+import Distribution.NixOS.PrettyPrinting
2223import Distribution.Text
2324
2425-- | A representation of the @meta@ section used in Nix expressions.
@@ -55,6 +56,9 @@ instance Text Meta where
5556 disp = renderMeta
5657 parse = error "parsing Distribution.NixOS.Derivation.Cabal.Meta is not supported yet"
5758
59+instance NFData Meta where
60+ rnf (Meta a b c d e f) = a `deepseq` b `deepseq` c `deepseq` d `deepseq` e `deepseq` f `deepseq` ()
61+
5862renderMeta :: Meta -> Doc
5963renderMeta meta = vcat
6064 [ text "meta" <+> equals <+> lbrace
src/Distribution/NixOS/Fetch.hs+4
@@ -9,6 +9,7 @@ module Distribution.NixOS.Fetch
99 ) where
1010
1111import Control.Applicative
12+import Control.DeepSeq
1213import Control.Monad
1314import Control.Monad.IO.Class
1415import Control.Monad.Trans.Maybe
@@ -36,6 +37,9 @@ data DerivationSource = DerivationSource
3637 , derivHash :: String -- ^ The hash of the source.
3738 } deriving (Show, Eq, Ord)
3839
40+instance NFData DerivationSource where
41+ rnf (DerivationSource a b c d) = a `deepseq` b `deepseq` c `deepseq` d `deepseq` ()
42+
3943fromDerivationSource :: DerivationSource -> Source
4044fromDerivationSource DerivationSource{..} = Source derivUrl derivRevision $ Just derivHash
4145