git.iko.soy/typeable/cabal2nix
on master help sign in
Add support for aeson 1.x.
commit4decb9c3b9abdf3d27b3733401e15e44ccc146ae authorPeter Simons <simons@cryp.to> dateThu 15 Sep 2016, 18:50 (10 years ago) parent9458be4
3 files changed+21−13
cabal2nix.cabal+3−3 package.yaml+1−1 src/Distribution/Nixpkgs/Haskell/FromCabal/Configuration.hs+17−9
cabal2nix.cabal+3−3
@@ -70,7 +70,7 @@ library
7070 src
7171 ghc-options: -Wall
7272 build-depends:
73− aeson < 1
73+ aeson
7474 , ansi-wl-pprint
7575 , base < 5
7676 , bytestring
@@ -117,7 +117,7 @@ executable cabal2nix
117117 cabal2nix
118118 ghc-options: -Wall
119119 build-depends:
120− aeson < 1
120+ aeson
121121 , ansi-wl-pprint
122122 , base < 5
123123 , bytestring
@@ -149,7 +149,7 @@ executable hackage2nix
149149 hackage2nix
150150 ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
151151 build-depends:
152− aeson < 1
152+ aeson
153153 , ansi-wl-pprint
154154 , base < 5
155155 , bytestring
package.yaml+1−1
@@ -62,7 +62,7 @@ description: >
6262ghc-options: -Wall
6363
6464dependencies:
65− - aeson < 1
65+ - aeson
6666 - ansi-wl-pprint
6767 - base < 5
6868 - bytestring
src/Distribution/Nixpkgs/Haskell/FromCabal/Configuration.hs+17−9
@@ -1,5 +1,5 @@
11{-# LANGUAGE RecordWildCards #-}
2−{-# LANGUAGE CPP #-}
2+{-# LANGUAGE CPP #-}
33{-# LANGUAGE FlexibleInstances #-}
44{-# LANGUAGE OverloadedStrings #-}
55{-# LANGUAGE DeriveGeneric #-}
@@ -10,6 +10,7 @@ module Distribution.Nixpkgs.Haskell.FromCabal.Configuration ( Configuration(..),
1010import Control.DeepSeq
1111import Control.Lens
1212import Control.Monad
13+import Data.Aeson
1314import Data.Map as Map
1415import Data.Set as Set
1516import Data.Text as T
@@ -65,25 +66,32 @@ instance FromJSON Identifier where
6566 parseJSON (String s) = pure (review ident (T.unpack s))
6667 parseJSON s = fail ("parseJSON: " ++ show s ++ " is not a valid Nix identifier")
6768
68−-- aeson-0.11 introduces a general instance, so we just need a couple
69−-- of specific ones
70−#if MIN_VERSION_aeson(0,11,0)
69+#if MIN_VERSION_aeson(1,0,0)
70+
71+instance FromJSONKey Identifier where
72+ fromJSONKey = FromJSONKeyText parseKey
73+
74+instance FromJSONKey PackageName where
75+ fromJSONKey = FromJSONKeyText parseKey
76+
77+#elif MIN_VERSION_aeson(0,11,0)
78+
7179instance (FromJSON v) => FromJSON (Map Identifier v) where
7280 parseJSON = fmap (Map.mapKeys parseKey) . parseJSON
7381
7482instance (FromJSON v) => FromJSON (Map PackageName v) where
7583 parseJSON = fmap (Map.mapKeys parseKey) . parseJSON
7684
77−parseKey :: (FromJSON k) => Text -> k
78−parseKey s = either error id (parseEither parseJSON (String s))
7985#else
86+
8087instance (Ord k, FromJSON k, FromJSON v) => FromJSON (Map k v) where
8188 parseJSON = fmap (Map.mapKeys parseKey) . parseJSON
82− where
83− parseKey :: FromJSON k => Text -> k
84− parseKey s = either error id (parseEither parseJSON (String s))
89+
8590#endif
8691
92+parseKey :: FromJSON k => Text -> k
93+parseKey s = either error id (parseEither parseJSON (String s))
94+
8795readConfiguration :: FilePath -> IO Configuration
8896readConfiguration path =
8997 decodeFile path >>= maybe (fail ("invalid config file at " ++ show path)) assertConsistency