Skip to content

Commit c9db11c

Browse files
committed
remote: add Types.StoreText, use in AddTextToStore
1 parent 7b579a2 commit c9db11c

File tree

7 files changed

+37
-4
lines changed

7 files changed

+37
-4
lines changed

hnix-store-remote/hnix-store-remote.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ library
9090
, System.Nix.Store.Remote.Types.Logger
9191
, System.Nix.Store.Remote.Types.ProtoVersion
9292
, System.Nix.Store.Remote.Types.StoreConfig
93+
, System.Nix.Store.Remote.Types.StoreText
9394
, System.Nix.Store.Remote.Types.SubstituteMode
9495
, System.Nix.Store.Remote.Types.Verbosity
9596
, System.Nix.Store.Remote.Types.WorkerMagic

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ deriving via GenericArbitrary SubstituteMode
2121
deriving via GenericArbitrary ProtoVersion
2222
instance Arbitrary ProtoVersion
2323

24+
deriving via GenericArbitrary StoreText
25+
instance Arbitrary StoreText
26+
2427
-- * Logger
2528

2629
deriving via GenericArbitrary Activity
@@ -56,7 +59,7 @@ deriving via GenericArbitrary Verbosity
5659
instance Arbitrary (Some StoreRequest) where
5760
arbitrary = oneof
5861
[ Some <$> (AddToStore <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary)
59-
, Some <$> (AddTextToStore <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary)
62+
, Some <$> (AddTextToStore <$> arbitrary <*> arbitrary <*> arbitrary)
6063
, Some <$> (AddSignatures <$> arbitrary <*> arbitrary)
6164
, Some . AddIndirectRoot <$> arbitrary
6265
, Some . AddTempRoot <$> arbitrary

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import System.Nix.Store.Types (RepairMode)
2424
import System.Nix.StorePath (StorePath, StorePathName, StorePathHashPart)
2525
import System.Nix.StorePath.Metadata (Metadata)
2626
import System.Nix.Store.Remote.Types.CheckMode (CheckMode)
27+
import System.Nix.Store.Remote.Types.StoreText (StoreText)
2728
import System.Nix.Store.Remote.Types.SubstituteMode (SubstituteMode)
2829

2930
data StoreRequest :: Type -> Type where
@@ -49,8 +50,7 @@ data StoreRequest :: Type -> Type where
4950
-- Reference accepts repair but only uses it
5051
-- to throw error in case of remote talking to nix-daemon.
5152
AddTextToStore
52-
:: Text -- ^ Name of the text
53-
-> Text -- ^ Actual text to add
53+
:: StoreText
5454
-> HashSet StorePath -- ^ Set of @StorePath@s that the added text references
5555
-> RepairMode -- ^ Repair mode, must be @RepairMode_DontRepair@ in case of remote backend
5656
-> StoreRequest StorePath
@@ -167,7 +167,7 @@ deriveGShow ''StoreRequest
167167

168168
instance {-# OVERLAPPING #-} Eq (Some StoreRequest) where
169169
Some (AddToStore a b c d) == Some (AddToStore a' b' c' d') = (a, b, c, d) == (a', b', c', d')
170-
Some (AddTextToStore a b c d) == Some (AddTextToStore a' b' c' d') = (a, b, c, d) == (a', b', c', d')
170+
Some (AddTextToStore a b c) == Some (AddTextToStore a' b' c') = (a, b, c) == (a', b', c')
171171
Some (AddSignatures a b) == Some (AddSignatures a' b') = (a, b) == (a', b')
172172
Some (AddIndirectRoot a) == Some (AddIndirectRoot a') = a == a'
173173
Some (AddTempRoot a) == Some (AddTempRoot a') = a == a'

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ module System.Nix.Store.Remote.Serializer
6767
, HandshakeSError(..)
6868
, workerMagic
6969
-- * Worker protocol
70+
, storeText
7071
, workerOp
7172
) where
7273

@@ -927,6 +928,17 @@ workerMagic = Serializer
927928

928929
-- * Worker protocol
929930

931+
storeText :: NixSerializer r SError StoreText
932+
storeText = Serializer
933+
{ getS = do
934+
storeTextName <- getS storePathName
935+
storeTextText <- getS text
936+
pure StoreText{..}
937+
, putS = \StoreText{..} -> do
938+
putS storePathName storeTextName
939+
putS text storeTextText
940+
}
941+
930942
workerOp :: NixSerializer r SError WorkerOp
931943
workerOp = enum
932944

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module System.Nix.Store.Remote.Types
55
, module System.Nix.Store.Remote.Types.Logger
66
, module System.Nix.Store.Remote.Types.ProtoVersion
77
, module System.Nix.Store.Remote.Types.StoreConfig
8+
, module System.Nix.Store.Remote.Types.StoreText
89
, module System.Nix.Store.Remote.Types.SubstituteMode
910
, module System.Nix.Store.Remote.Types.Verbosity
1011
, module System.Nix.Store.Remote.Types.WorkerMagic
@@ -17,6 +18,7 @@ import System.Nix.Store.Remote.Types.CheckMode
1718
import System.Nix.Store.Remote.Types.Logger
1819
import System.Nix.Store.Remote.Types.ProtoVersion
1920
import System.Nix.Store.Remote.Types.StoreConfig
21+
import System.Nix.Store.Remote.Types.StoreText
2022
import System.Nix.Store.Remote.Types.SubstituteMode
2123
import System.Nix.Store.Remote.Types.Verbosity
2224
import System.Nix.Store.Remote.Types.WorkerMagic
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module System.Nix.Store.Remote.Types.StoreText
2+
( StoreText(..)
3+
) where
4+
5+
import Data.Text (Text)
6+
import GHC.Generics (Generic)
7+
import System.Nix.StorePath (StorePathName)
8+
9+
data StoreText = StoreText
10+
{ storeTextName :: StorePathName
11+
, storeTextText :: Text
12+
} deriving (Eq, Generic, Ord, Show)

hnix-store-remote/tests/NixSerializerSpec.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ spec = parallel $ do
167167
it' "IsValidPath" WorkerOp_IsValidPath 1
168168
it' "BuildPathsWithResults" WorkerOp_BuildPathsWithResults 46
169169

170+
describe "Worker protocol" $ do
171+
prop "StoreText" $ roundtripS storeText
172+
170173
errorInfoIf :: Bool -> Logger -> Bool
171174
errorInfoIf True (Logger_Error (Right x)) = noJust0s x
172175
where

0 commit comments

Comments
 (0)