Skip to content

Commit fb914f2

Browse files
committed
deps: support aeson 2.0
Closes: #991 Upstream quarrel: haskell/aeson#881
1 parent 5737ffc commit fb914f2

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

hnix.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ library
405405
-Wall
406406
-fprint-potential-instances
407407
build-depends:
408-
aeson >= 1.4.2 && < 1.6
408+
aeson >= 1.4.2 && < 1.6 || >= 2.0 && < 2.1
409409
, array >= 0.4 && < 0.6
410410
, base >= 4.12 && < 5
411411
, base16-bytestring >= 0.1.1 && < 1.1

src/Nix/Builtins.hs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ import qualified "hashing" Crypto.Hash.SHA1 as SHA1
3232
import qualified "hashing" Crypto.Hash.SHA256 as SHA256
3333
import qualified "hashing" Crypto.Hash.SHA512 as SHA512
3434
import qualified Data.Aeson as A
35+
#if MIN_VERSION_aeson(2,0,0)
36+
import qualified Data.Aeson.Key as AKM
37+
import qualified Data.Aeson.KeyMap as AKM
38+
#endif
3539
import Data.Align ( alignWith )
3640
import Data.Array
3741
import Data.Bits
@@ -1522,7 +1526,14 @@ fromJSONNix nvjson =
15221526
jsonToNValue :: (A.Value -> m (NValue t f m))
15231527
jsonToNValue =
15241528
\case
1525-
A.Object m -> traverseToNValue (nvSet mempty) (M.mapKeys coerce m)
1529+
A.Object m ->
1530+
traverseToNValue
1531+
(nvSet mempty)
1532+
#if MIN_VERSION_aeson(2,0,0)
1533+
(M.mapKeys (coerce . AKM.toText) $ AKM.toHashMap m)
1534+
#else
1535+
(M.mapKeys coerce m)
1536+
#endif
15261537
A.Array l -> traverseToNValue nvList (V.toList l)
15271538
A.String s -> pure $ nvStrWithoutContext s
15281539
A.Number n ->

src/Nix/Json.hs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
{-# language CPP #-}
12

23
module Nix.Json where
34

45
import qualified Data.Aeson as A
56
import qualified Data.Aeson.Encoding as A
7+
#if MIN_VERSION_aeson(2,0,0)
8+
import qualified Data.Aeson.Key as AKM
9+
import qualified Data.Aeson.KeyMap as AKM
10+
#endif
611
import qualified Data.Vector as V
712
import qualified Data.HashMap.Strict as HM
813
import Nix.Atoms
@@ -21,8 +26,13 @@ toEncodingSorted = \case
2126
A.pairs
2227
. mconcat
2328
. ((\(k, v) -> A.pair k $ toEncodingSorted v) <$>)
24-
. sortWith fst
25-
$ HM.toList m
29+
. sortWith fst $
30+
#if MIN_VERSION_aeson(2,0,0)
31+
AKM.toList
32+
#else
33+
HM.toList
34+
#endif
35+
m
2636
A.Array l -> A.list toEncodingSorted $ V.toList l
2737
v -> A.toEncoding v
2838

@@ -48,9 +58,17 @@ nvalueToJSON = \case
4858
NVList l -> A.Array . V.fromList <$> traverse intoJson l
4959
NVSet _ m ->
5060
maybe
51-
(A.Object <$> traverse intoJson (HM.mapKeys (coerce @VarName @Text) m))
61+
(A.Object <$> traverse intoJson kmap)
5262
intoJson
53-
(HM.lookup "outPath" m)
63+
(lkup "outPath" kmap)
64+
where
65+
#if MIN_VERSION_aeson(2,0,0)
66+
lkup = AKM.lookup
67+
kmap = AKM.fromHashMap (HM.mapKeys (AKM.fromText . coerce) m)
68+
#else
69+
lkup = HM.lookup
70+
kmap = HM.mapKeys (coerce @VarName @Text) m
71+
#endif
5472
NVPath p ->
5573
do
5674
fp <- lift $ coerce <$> addPath p

0 commit comments

Comments
 (0)