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
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
Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ import qualified "hashing" Crypto.Hash.SHA1 as SHA1
3232import qualified "hashing" Crypto.Hash.SHA256 as SHA256
3333import qualified "hashing" Crypto.Hash.SHA512 as SHA512
3434import 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
3539import Data.Align ( alignWith )
3640import Data.Array
3741import Data.Bits
@@ -1524,7 +1528,14 @@ fromJSONNix nvjson =
15241528 jsonToNValue :: (A. Value -> m (NValue t f m ))
15251529 jsonToNValue =
15261530 \ case
1527- A. Object m -> traverseToNValue (nvSet mempty ) (M. mapKeys coerce m)
1531+ A. Object m ->
1532+ traverseToNValue
1533+ (nvSet mempty )
1534+ #if MIN_VERSION_aeson(2,0,0)
1535+ (M. mapKeys (coerce . AKM. toText) $ AKM. toHashMap m)
1536+ #else
1537+ (M. mapKeys coerce m)
1538+ #endif
15281539 A. Array l -> traverseToNValue nvList (V. toList l)
15291540 A. String s -> pure $ nvStrWithoutContext s
15301541 A. Number n ->
Original file line number Diff line number Diff line change 1+ {-# language CPP #-}
12
23module Nix.Json where
34
45import qualified Data.Aeson as A
56import qualified Data.Aeson.Encoding as A
67import qualified Data.Vector as V
78import qualified Data.HashMap.Strict as HM
9+ #if MIN_VERSION_aeson(2,0,0)
10+ import qualified Data.Aeson.Key as AKM
11+ import qualified Data.Aeson.KeyMap as AKM
12+ #endif
813import Nix.Atoms
914import Nix.Effects
1015import Nix.Exec
@@ -21,8 +26,13 @@ toEncodingSorted = \case
2126 A. pairs
2227 . fold
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
You can’t perform that action at this time.
0 commit comments