@@ -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