Skip to content

Commit d18a014

Browse files
committed
remote: add Query.Missing serializer
1 parent c841f93 commit d18a014

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ deriving via GenericArbitrary GCAction
7878
deriving via GenericArbitrary GCOptions
7979
instance Arbitrary GCOptions
8080

81-
deriving via GenericArbitrary GCResult
82-
instance Arbitrary GCResult
83-
8481
-- * Handshake
8582

8683
deriving via GenericArbitrary WorkerMagic
@@ -94,6 +91,8 @@ deriving via GenericArbitrary TrustedFlag
9491
deriving via GenericArbitrary WorkerOp
9592
instance Arbitrary WorkerOp
9693

94+
-- ** Request
95+
9796
instance Arbitrary (Some StoreRequest) where
9897
arbitrary = oneof
9998
[ Some <$> (AddToStore <$> arbitrary <*> arbitrary <*> arbitrary <*> pure RepairMode_DontRepair)
@@ -121,3 +120,11 @@ instance Arbitrary (Some StoreRequest) where
121120
, pure $ Some SyncWithGC
122121
, Some <$> (VerifyStore <$> arbitrary <*> arbitrary)
123122
]
123+
124+
-- ** Reply
125+
126+
deriving via GenericArbitrary GCResult
127+
instance Arbitrary GCResult
128+
129+
deriving via GenericArbitrary Missing
130+
instance Arbitrary Missing

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ module System.Nix.Store.Remote.Serializer
9292
, buildResult
9393
-- *** GCResult
9494
, gcResult
95+
-- *** Missing
96+
, missing
9597
) where
9698

9799
import Control.Monad.Except (MonadError, throwError, )
@@ -1341,6 +1343,7 @@ data ReplySError
13411343
| ReplySError_PrimPut SError
13421344
| ReplySError_DerivationOutput SError
13431345
| ReplySError_GCResult SError
1346+
| ReplySError_Missing SError
13441347
| ReplySError_Realisation SError
13451348
| ReplySError_RealisationWithId SError
13461349
deriving (Eq, Ord, Generic, Show)
@@ -1453,3 +1456,23 @@ gcResult = mapErrorS ReplySError_GCResult $ Serializer
14531456
putS int gcResultBytesFreed
14541457
putS (int @Word64) 0 -- obsolete
14551458
}
1459+
1460+
missing
1461+
:: HasStoreDir r
1462+
=> NixSerializer r ReplySError Missing
1463+
missing = mapErrorS ReplySError_Missing $ Serializer
1464+
{ getS = do
1465+
missingWillBuild <- getS (hashSet storePath)
1466+
missingWillSubstitute <- getS (hashSet storePath)
1467+
missingUnknownPaths <- getS (hashSet storePath)
1468+
missingDownloadSize <- getS int
1469+
missingNarSize <- getS int
1470+
1471+
pure Missing{..}
1472+
, putS = \Missing{..} -> do
1473+
putS (hashSet storePath) missingWillBuild
1474+
putS (hashSet storePath) missingWillSubstitute
1475+
putS (hashSet storePath) missingUnknownPaths
1476+
putS int missingDownloadSize
1477+
putS int missingNarSize
1478+
}

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
@@ -6,6 +6,7 @@ import System.Nix.Build (BuildResult)
66
import System.Nix.StorePath (HasStoreDir(..), StorePath)
77
import System.Nix.Store.Remote.Serializer
88
import System.Nix.Store.Remote.Types.GC (GCResult)
9+
import System.Nix.Store.Remote.Types.Query.Missing (Missing)
910
import System.Nix.Store.Remote.Types.ProtoVersion (HasProtoVersion)
1011

1112
-- | Get @NixSerializer@ for some type @a@
@@ -29,6 +30,9 @@ instance StoreReply BuildResult where
2930
instance StoreReply GCResult where
3031
getReplyS = gcResult
3132

33+
instance StoreReply Missing where
34+
getReplyS = missing
35+
3236
instance StoreReply StorePath where
3337
getReplyS = mapPrimE storePath
3438

hnix-store-remote/tests/NixSerializerSpec.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ spec = parallel $ do
151151

152152
describe "StoreReply" $ do
153153
prop "GCResult" $ roundtripSReader @StoreDir gcResult
154+
prop "Missing" $ roundtripSReader @StoreDir missing
154155

155156
restrictProtoVersion :: ProtoVersion -> Some StoreRequest -> Bool
156157
restrictProtoVersion v (Some (BuildPaths _ _)) | v < ProtoVersion 1 30 = False

0 commit comments

Comments
 (0)