File tree Expand file tree Collapse file tree 3 files changed +35
-6
lines changed Expand file tree Collapse file tree 3 files changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -405,7 +405,7 @@ library
405
405
-Wall
406
406
-fprint-potential-instances
407
407
build-depends :
408
- aeson >= 1.4.2 && < 1.6
408
+ aeson >= 1.4.2 && < 1.6 || >= 2.0 && < 2.1
409
409
, array >= 0.4 && < 0.6
410
410
, base >= 4.12 && < 5
411
411
, base16-bytestring >= 0.1.1 && < 1.1
Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ import qualified "hashing" Crypto.Hash.SHA1 as SHA1
32
32
import qualified "hashing" Crypto.Hash.SHA256 as SHA256
33
33
import qualified "hashing" Crypto.Hash.SHA512 as SHA512
34
34
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
35
39
import Data.Align ( alignWith )
36
40
import Data.Array
37
41
import Data.Bits
@@ -1522,7 +1526,14 @@ fromJSONNix nvjson =
1522
1526
jsonToNValue :: (A. Value -> m (NValue t f m ))
1523
1527
jsonToNValue =
1524
1528
\ 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
1526
1537
A. Array l -> traverseToNValue nvList (V. toList l)
1527
1538
A. String s -> pure $ nvStrWithoutContext s
1528
1539
A. Number n ->
Original file line number Diff line number Diff line change
1
+ {-# language CPP #-}
1
2
2
3
module Nix.Json where
3
4
4
5
import qualified Data.Aeson as A
5
6
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
6
11
import qualified Data.Vector as V
7
12
import qualified Data.HashMap.Strict as HM
8
13
import Nix.Atoms
@@ -21,8 +26,13 @@ toEncodingSorted = \case
21
26
A. pairs
22
27
. mconcat
23
28
. ((\ (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
26
36
A. Array l -> A. list toEncodingSorted $ V. toList l
27
37
v -> A. toEncoding v
28
38
@@ -48,9 +58,17 @@ nvalueToJSON = \case
48
58
NVList l -> A. Array . V. fromList <$> traverse intoJson l
49
59
NVSet _ m ->
50
60
maybe
51
- (A. Object <$> traverse intoJson ( HM. mapKeys (coerce @ VarName @ Text ) m) )
61
+ (A. Object <$> traverse intoJson kmap )
52
62
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
54
72
NVPath p ->
55
73
do
56
74
fp <- lift $ coerce <$> addPath p
You can’t perform that action at this time.
0 commit comments