@@ -31,6 +31,8 @@ module System.Nix.Store.Remote.Serializer
3131 , set
3232 , hashSet
3333 , mapS
34+ , vector
35+ , json
3436 -- * ProtoVersion
3537 , protoVersion
3638 -- * StorePath
@@ -45,6 +47,7 @@ module System.Nix.Store.Remote.Serializer
4547 -- * Realisation
4648 , derivationOutputTyped
4749 , realisation
50+ , realisationWithId
4851 -- * Signatures
4952 , signature
5053 , narSignature
@@ -93,6 +96,7 @@ import Control.Monad.Trans (MonadTrans, lift)
9396import Control.Monad.Trans.Reader (ReaderT , runReaderT , withReaderT )
9497import Control.Monad.Trans.Except (ExceptT , mapExceptT , runExceptT , withExceptT )
9598import Crypto.Hash (Digest , HashAlgorithm , SHA256 )
99+ import Data.Aeson (FromJSON , ToJSON )
96100import Data.ByteString (ByteString )
97101import Data.Dependent.Sum (DSum ((:=>) ))
98102import Data.Fixed (Uni )
@@ -242,6 +246,7 @@ data SError
242246 | SError_HashAlgo String
243247 | SError_IllegalBool Word64
244248 | SError_InvalidNixBase32
249+ | SError_JSONDecoding String
245250 | SError_NarHashMustBeSHA256
246251 | SError_NotYetImplemented String (ForPV ProtoVersion )
247252 | SError_Name InvalidNameError
@@ -447,6 +452,22 @@ vector =
447452 Data.Vector. toList
448453 . list
449454
455+ json
456+ :: ( FromJSON a
457+ , ToJSON a
458+ )
459+ => NixSerializer r SError a
460+ json =
461+ mapPrismSerializer
462+ ( Data.Bifunctor. first SError_JSONDecoding
463+ . Data.Aeson. eitherDecode
464+ )
465+ Data.Aeson. encode
466+ $ mapIsoSerializer
467+ Data.ByteString.Lazy. fromStrict
468+ Data.ByteString.Lazy. toStrict
469+ byteString
470+
450471-- * ProtoVersion
451472
452473-- protoVersion_major & 0xFF00
@@ -614,17 +635,11 @@ derivationOutputTyped =
614635 )
615636 text
616637
617- realisation
618- :: HasStoreDir r
619- => NixSerializer r SError Realisation
620- realisation = Serializer
621- { getS = do
622- rb <- getS byteString
623- case Data.Aeson. eitherDecode (Data.ByteString.Lazy. fromStrict rb) of
624- Left e -> error e
625- Right r -> pure r
626- , putS = putS byteString . Data.ByteString.Lazy. toStrict . Data.Aeson. encode
627- }
638+ realisation :: NixSerializer r SError Realisation
639+ realisation = json
640+
641+ realisationWithId :: NixSerializer r SError (System.Nix.Realisation. DerivationOutput OutputName , Realisation )
642+ realisationWithId = json
628643
629644-- * Signatures
630645
@@ -818,9 +833,10 @@ buildResult = Serializer
818833 if protoVersion_minor pv >= 28
819834 then
820835 pure
821- . Data.Map.Strict. mapKeys
822- System.Nix.Realisation. derivationOutputName
823- <$> getS (mapS derivationOutputTyped realisation)
836+ . Data.Map.Strict. fromList
837+ . map (\ (_, (a, b)) -> (a, b))
838+ . Data.Map.Strict. toList
839+ <$> getS (mapS derivationOutputTyped realisationWithId)
824840 else pure Nothing
825841 pure BuildResult {.. }
826842
@@ -835,8 +851,10 @@ buildResult = Serializer
835851 putS time $ Data.Maybe. fromMaybe t0 buildResultStartTime
836852 putS time $ Data.Maybe. fromMaybe t0 buildResultStopTime
837853 Control.Monad. when (protoVersion_minor pv >= 28 )
838- -- TODO realisation.id
839- $ putS (mapS outputName realisation)
854+ $ putS (mapS derivationOutputTyped realisationWithId)
855+ $ Data.Map.Strict. fromList
856+ $ map (\ (a, b) -> (a, (a, b)))
857+ $ Data.Map.Strict. toList
840858 $ Data.Maybe. fromMaybe mempty buildResultBuiltOutputs
841859 }
842860 where
0 commit comments