Skip to content

Commit a5dac6d

Browse files
committed
remote: shuffle reply serializers, extend ReplySError
1 parent 7bdbab9 commit a5dac6d

File tree

2 files changed

+107
-88
lines changed

2 files changed

+107
-88
lines changed

hnix-store-remote/src/System/Nix/Store/Remote/Serializer.hs

Lines changed: 105 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ module System.Nix.Store.Remote.Serializer
4444
, pathMetadata
4545
-- * OutputName
4646
, outputName
47-
-- * Realisation
48-
, derivationOutputTyped
49-
, realisation
50-
, realisationWithId
5147
-- * Signatures
5248
, signature
5349
, narSignature
@@ -63,7 +59,6 @@ module System.Nix.Store.Remote.Serializer
6359
, derivedPath
6460
-- * Build
6561
, buildMode
66-
, buildResult
6762
-- * Logger
6863
, LoggerSError(..)
6964
, activityID
@@ -89,6 +84,12 @@ module System.Nix.Store.Remote.Serializer
8984
, storeRequest
9085
-- ** Reply
9186
, ReplySError(..)
87+
-- *** Realisation
88+
, derivationOutputTyped
89+
, realisation
90+
, realisationWithId
91+
-- *** BuildResult
92+
, buildResult
9293
) where
9394

9495
import Control.Monad.Except (MonadError, throwError, )
@@ -620,28 +621,6 @@ outputName =
620621
System.Nix.OutputName.unOutputName
621622
text
622623

623-
-- * Realisation
624-
625-
derivationOutputTyped :: NixSerializer r SError (System.Nix.Realisation.DerivationOutput OutputName)
626-
derivationOutputTyped =
627-
mapPrismSerializer
628-
( Data.Bifunctor.first SError_DerivationOutput
629-
. System.Nix.Realisation.derivationOutputParser
630-
System.Nix.OutputName.mkOutputName
631-
)
632-
( Data.Text.Lazy.toStrict
633-
. Data.Text.Lazy.Builder.toLazyText
634-
. System.Nix.Realisation.derivationOutputBuilder
635-
System.Nix.OutputName.unOutputName
636-
)
637-
text
638-
639-
realisation :: NixSerializer r SError Realisation
640-
realisation = json
641-
642-
realisationWithId :: NixSerializer r SError (System.Nix.Realisation.DerivationOutput OutputName, Realisation)
643-
realisationWithId = json
644-
645624
-- * Signatures
646625

647626
signature
@@ -804,64 +783,6 @@ derivedPath = Serializer
804783
buildMode :: NixSerializer r SError BuildMode
805784
buildMode = enum
806785

807-
buildResult
808-
:: ( HasProtoVersion r
809-
, HasStoreDir r
810-
)
811-
=> NixSerializer r SError BuildResult
812-
buildResult = Serializer
813-
{ getS = do
814-
pv <- Control.Monad.Reader.asks hasProtoVersion
815-
816-
buildResultStatus <- getS enum
817-
buildResultErrorMessage <- getS maybeText
818-
819-
( buildResultTimesBuilt
820-
, buildResultIsNonDeterministic
821-
, buildResultStartTime
822-
, buildResultStopTime
823-
) <-
824-
if protoVersion_minor pv >= 29
825-
then do
826-
tb <- (\case 0 -> Nothing; x -> Just x) <$> getS int
827-
nondet <- getS bool
828-
start <- (\case x | x == t0 -> Nothing; x -> Just x) <$> getS time
829-
end <- (\case x | x == t0 -> Nothing; x -> Just x) <$> getS time
830-
pure $ (tb, pure nondet, start, end)
831-
else pure $ (Nothing, Nothing, Nothing, Nothing)
832-
833-
buildResultBuiltOutputs <-
834-
if protoVersion_minor pv >= 28
835-
then
836-
pure
837-
. Data.Map.Strict.fromList
838-
. map (\(_, (a, b)) -> (a, b))
839-
. Data.Map.Strict.toList
840-
<$> getS (mapS derivationOutputTyped realisationWithId)
841-
else pure Nothing
842-
pure BuildResult{..}
843-
844-
, putS = \BuildResult{..} -> do
845-
pv <- Control.Monad.Reader.asks hasProtoVersion
846-
847-
putS enum buildResultStatus
848-
putS maybeText buildResultErrorMessage
849-
Control.Monad.when (protoVersion_minor pv >= 29) $ do
850-
putS int $ Data.Maybe.fromMaybe 0 buildResultTimesBuilt
851-
putS bool $ Data.Maybe.fromMaybe False buildResultIsNonDeterministic
852-
putS time $ Data.Maybe.fromMaybe t0 buildResultStartTime
853-
putS time $ Data.Maybe.fromMaybe t0 buildResultStopTime
854-
Control.Monad.when (protoVersion_minor pv >= 28)
855-
$ putS (mapS derivationOutputTyped realisationWithId)
856-
$ Data.Map.Strict.fromList
857-
$ map (\(a, b) -> (a, (a, b)))
858-
$ Data.Map.Strict.toList
859-
$ Data.Maybe.fromMaybe mempty buildResultBuiltOutputs
860-
}
861-
where
862-
t0 :: UTCTime
863-
t0 = Data.Time.Clock.POSIX.posixSecondsToUTCTime 0
864-
865786
-- * Logger
866787

867788
data LoggerSError
@@ -1414,5 +1335,103 @@ storeRequest = Serializer
14141335
-- * Reply
14151336

14161337
data ReplySError
1417-
= ReplySError_Prim SError
1338+
= ReplySError_PrimGet SError
1339+
| ReplySError_PrimPut SError
1340+
| ReplySError_DerivationOutput SError
1341+
| ReplySError_Realisation SError
1342+
| ReplySError_RealisationWithId SError
14181343
deriving (Eq, Ord, Generic, Show)
1344+
1345+
mapGetER
1346+
:: Functor m
1347+
=> SerialT r SError m a
1348+
-> SerialT r ReplySError m a
1349+
mapGetER = mapErrorST ReplySError_PrimGet
1350+
1351+
mapPutER
1352+
:: Functor m
1353+
=> SerialT r SError m a
1354+
-> SerialT r ReplySError m a
1355+
mapPutER = mapErrorST ReplySError_PrimPut
1356+
1357+
-- *** Realisation
1358+
1359+
derivationOutputTyped :: NixSerializer r ReplySError (System.Nix.Realisation.DerivationOutput OutputName)
1360+
derivationOutputTyped = mapErrorS ReplySError_DerivationOutput $
1361+
mapPrismSerializer
1362+
( Data.Bifunctor.first SError_DerivationOutput
1363+
. System.Nix.Realisation.derivationOutputParser
1364+
System.Nix.OutputName.mkOutputName
1365+
)
1366+
( Data.Text.Lazy.toStrict
1367+
. Data.Text.Lazy.Builder.toLazyText
1368+
. System.Nix.Realisation.derivationOutputBuilder
1369+
System.Nix.OutputName.unOutputName
1370+
)
1371+
text
1372+
1373+
realisation :: NixSerializer r ReplySError Realisation
1374+
realisation = mapErrorS ReplySError_Realisation json
1375+
1376+
realisationWithId :: NixSerializer r ReplySError (System.Nix.Realisation.DerivationOutput OutputName, Realisation)
1377+
realisationWithId = mapErrorS ReplySError_RealisationWithId json
1378+
1379+
-- *** BuildResult
1380+
1381+
buildResult
1382+
:: ( HasProtoVersion r
1383+
, HasStoreDir r
1384+
)
1385+
=> NixSerializer r ReplySError BuildResult
1386+
buildResult = Serializer
1387+
{ getS = do
1388+
pv <- Control.Monad.Reader.asks hasProtoVersion
1389+
1390+
buildResultStatus <- mapGetER $ getS enum
1391+
buildResultErrorMessage <- mapGetER $ getS maybeText
1392+
1393+
( buildResultTimesBuilt
1394+
, buildResultIsNonDeterministic
1395+
, buildResultStartTime
1396+
, buildResultStopTime
1397+
) <-
1398+
if protoVersion_minor pv >= 29
1399+
then mapGetER $ do
1400+
tb <- (\case 0 -> Nothing; x -> Just x) <$> getS int
1401+
nondet <- getS bool
1402+
start <- (\case x | x == t0 -> Nothing; x -> Just x) <$> getS time
1403+
end <- (\case x | x == t0 -> Nothing; x -> Just x) <$> getS time
1404+
pure $ (tb, pure nondet, start, end)
1405+
else pure $ (Nothing, Nothing, Nothing, Nothing)
1406+
1407+
buildResultBuiltOutputs <-
1408+
if protoVersion_minor pv >= 28
1409+
then
1410+
pure
1411+
. Data.Map.Strict.fromList
1412+
. map (\(_, (a, b)) -> (a, b))
1413+
. Data.Map.Strict.toList
1414+
<$> getS (mapS derivationOutputTyped realisationWithId)
1415+
else pure Nothing
1416+
pure BuildResult{..}
1417+
1418+
, putS = \BuildResult{..} -> do
1419+
pv <- Control.Monad.Reader.asks hasProtoVersion
1420+
1421+
mapPutER $ putS enum buildResultStatus
1422+
mapPutER $ putS maybeText buildResultErrorMessage
1423+
Control.Monad.when (protoVersion_minor pv >= 29) $ mapPutER $ do
1424+
putS int $ Data.Maybe.fromMaybe 0 buildResultTimesBuilt
1425+
putS bool $ Data.Maybe.fromMaybe False buildResultIsNonDeterministic
1426+
putS time $ Data.Maybe.fromMaybe t0 buildResultStartTime
1427+
putS time $ Data.Maybe.fromMaybe t0 buildResultStopTime
1428+
Control.Monad.when (protoVersion_minor pv >= 28)
1429+
$ putS (mapS derivationOutputTyped realisationWithId)
1430+
$ Data.Map.Strict.fromList
1431+
$ map (\(a, b) -> (a, (a, b)))
1432+
$ Data.Map.Strict.toList
1433+
$ Data.Maybe.fromMaybe mempty buildResultBuiltOutputs
1434+
}
1435+
where
1436+
t0 :: UTCTime
1437+
t0 = Data.Time.Clock.POSIX.posixSecondsToUTCTime 0

hnix-store-remote/src/System/Nix/Store/Remote/Types/StoreReply.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ instance StoreReply Bool where
2323
getReplyS = mapPrimE bool
2424

2525
instance StoreReply BuildResult where
26-
getReplyS = mapPrimE buildResult
26+
getReplyS = buildResult
2727

2828
instance StoreReply StorePath where
2929
getReplyS = mapPrimE storePath
3030

3131
mapPrimE
3232
:: NixSerializer r SError a
3333
-> NixSerializer r ReplySError a
34-
mapPrimE = mapErrorS ReplySError_Prim
34+
mapPrimE = mapErrorS ReplySError_PrimGet

0 commit comments

Comments
 (0)