Skip to content

Commit 77fe9f9

Browse files
committed
remote: add gcResult serializer
1 parent 5aa62fd commit 77fe9f9

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ module System.Nix.Store.Remote.Serializer
9090
, realisationWithId
9191
-- *** BuildResult
9292
, buildResult
93+
-- *** GCResult
94+
, gcResult
9395
) where
9496

9597
import Control.Monad.Except (MonadError, throwError, )
@@ -1338,6 +1340,7 @@ data ReplySError
13381340
= ReplySError_PrimGet SError
13391341
| ReplySError_PrimPut SError
13401342
| ReplySError_DerivationOutput SError
1343+
| ReplySError_GCResult SError
13411344
| ReplySError_Realisation SError
13421345
| ReplySError_RealisationWithId SError
13431346
deriving (Eq, Ord, Generic, Show)
@@ -1435,3 +1438,18 @@ buildResult = Serializer
14351438
where
14361439
t0 :: UTCTime
14371440
t0 = Data.Time.Clock.POSIX.posixSecondsToUTCTime 0
1441+
1442+
gcResult
1443+
:: HasStoreDir r
1444+
=> NixSerializer r ReplySError GCResult
1445+
gcResult = mapErrorS ReplySError_GCResult $ Serializer
1446+
{ getS = do
1447+
gcResult_deletedPaths <- getS (hashSet storePath)
1448+
gcResult_bytesFreed <- getS int
1449+
Control.Monad.void $ getS (int @Word64) -- obsolete
1450+
pure GCResult{..}
1451+
, putS = \GCResult{..} -> do
1452+
putS (hashSet storePath) gcResult_deletedPaths
1453+
putS int gcResult_bytesFreed
1454+
putS (int @Word64) 0 -- obsolete
1455+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module System.Nix.Store.Remote.Types.StoreReply
55
import System.Nix.Build (BuildResult)
66
import System.Nix.StorePath (HasStoreDir(..), StorePath)
77
import System.Nix.Store.Remote.Serializer
8+
import System.Nix.Store.Remote.Types.GC (GCResult)
89
import System.Nix.Store.Remote.Types.ProtoVersion (HasProtoVersion)
910

1011
-- | Get @NixSerializer@ for some type @a@
@@ -25,6 +26,9 @@ instance StoreReply Bool where
2526
instance StoreReply BuildResult where
2627
getReplyS = buildResult
2728

29+
instance StoreReply GCResult where
30+
getReplyS = gcResult
31+
2832
instance StoreReply StorePath where
2933
getReplyS = mapPrimE storePath
3034

hnix-store-remote/tests/NixSerializerSpec.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ spec = parallel $ do
149149
forAll (arbitrary `suchThat` (restrictProtoVersion (hasProtoVersion testStoreConfig)))
150150
$ roundtripSReader @TestStoreConfig storeRequest testStoreConfig
151151

152+
describe "StoreReply" $ do
153+
prop "GCResult" $ roundtripSReader @StoreDir gcResult
154+
152155
restrictProtoVersion :: ProtoVersion -> Some StoreRequest -> Bool
153156
restrictProtoVersion v (Some (BuildPaths _ _)) | v < ProtoVersion 1 30 = False
154157
restrictProtoVersion _ (Some (BuildDerivation _ drv _)) = inputDrvs drv == mempty

0 commit comments

Comments
 (0)