99{-# LANGUAGE RecordWildCards #-}
1010module System.Nix.Store.Remote
1111 (
12- MonadStoreT
13- , MonadStore
12+ RemoteStoreT
13+ , System.Nix.Nar. PathType ( .. )
1414 , addToStore
1515 , addTextToStore
1616 , addSignatures
@@ -75,14 +75,14 @@ type CheckSigsFlag = Bool
7575type SubstituteFlag = Bool
7676
7777-- | Pack `FilePath` as `Nar` and add it to the store.
78- addToStore :: forall a m . (ValidAlgo a , NamedAlgo a , MonadIO m )
78+ addToStore :: forall a m . (NamedAlgo a , MonadRemoteStore m , MonadIO m )
7979 => StorePathName -- ^ Name part of the newly created `StorePath`
8080 -> FilePath -- ^ Local `FilePath` to add
8181 -> Bool -- ^ Add target directory recursively
82- -> (FilePath -> Bool ) -- ^ Path filter function
82+ -> (FilePath -> System.Nix.Nar. PathType -> m Bool ) -- ^ Path filter function
8383 -> RepairFlag -- ^ Only used by local store backend
84- -> MonadStoreT m StorePath
85- addToStore name pth recursive _pathFilter _repair = do
84+ -> m StorePath
85+ addToStore name pth recursive pathFilter _repair = do
8686
8787 runOpArgsIO AddToStore $ \ yield -> do
8888 yield $ Data.ByteString.Lazy. toStrict $ Data.Binary.Put. runPut $ do
@@ -96,20 +96,20 @@ addToStore name pth recursive _pathFilter _repair = do
9696
9797 putText $ System.Nix.Hash. algoName @ a
9898
99- System.Nix.Nar. streamNarIO yield System.Nix.Nar. narEffectsIO pth
99+ System.Nix.Nar. streamNarIO yield pathFilter System.Nix.Nar. narEffectsIO pth
100100
101101 sockGetPath
102102
103103-- | Add text to store.
104104--
105105-- Reference accepts repair but only uses it
106106-- to throw error in case of remote talking to nix-daemon.
107- addTextToStore :: (MonadIO m )
107+ addTextToStore :: (MonadIO m , MonadRemoteStore m )
108108 => Text -- ^ Name of the text
109109 -> Text -- ^ Actual text to add
110110 -> StorePathSet -- ^ Set of `StorePath`s that the added text references
111111 -> RepairFlag -- ^ Repair flag, must be `False` in case of remote backend
112- -> MonadStoreT m StorePath
112+ -> m StorePath
113113addTextToStore name text references' repair = do
114114 when repair $ error " repairing is not supported when building through the Nix daemon"
115115 runOpArgs AddTextToStore $ do
@@ -118,40 +118,43 @@ addTextToStore name text references' repair = do
118118 putPaths references'
119119 sockGetPath
120120
121- addSignatures :: StorePath
121+ addSignatures :: (MonadIO m )
122+ => StorePath
122123 -> [ByteString ]
123- -> MonadStore ()
124+ -> RemoteStoreT m ()
124125addSignatures p signatures = do
125126 void $ simpleOpArgs AddSignatures $ do
126127 putPath p
127128 putByteStrings signatures
128129
129- addIndirectRoot :: StorePath -> MonadStore ()
130+ addIndirectRoot :: ( MonadIO m ) => StorePath -> RemoteStoreT m ()
130131addIndirectRoot pn = do
131132 void $ simpleOpArgs AddIndirectRoot $ putPath pn
132133
133134-- | Add temporary garbage collector root.
134135--
135136-- This root is removed as soon as the client exits.
136- addTempRoot :: StorePath -> MonadStore ()
137+ addTempRoot :: ( MonadIO m ) => StorePath -> RemoteStoreT m ()
137138addTempRoot pn = do
138139 void $ simpleOpArgs AddTempRoot $ putPath pn
139140
140141-- | Build paths if they are an actual derivations.
141142--
142143-- If derivation output paths are already valid, do nothing.
143- buildPaths :: StorePathSet
144+ buildPaths :: (MonadIO m )
145+ => StorePathSet
144146 -> BuildMode
145- -> MonadStore ()
147+ -> RemoteStoreT m ()
146148buildPaths ps bm = do
147149 void $ simpleOpArgs BuildPaths $ do
148150 putPaths ps
149151 putInt $ fromEnum bm
150152
151- buildDerivation :: StorePath
153+ buildDerivation :: (MonadIO m )
154+ => StorePath
152155 -> Derivation StorePath Text
153156 -> BuildMode
154- -> MonadStore BuildResult
157+ -> RemoteStoreT m BuildResult
155158buildDerivation p drv buildMode = do
156159 runOpArgs BuildDerivation $ do
157160 putPath p
@@ -165,12 +168,12 @@ buildDerivation p drv buildMode = do
165168 res <- getSocketIncremental $ getBuildResult
166169 return res
167170
168- ensurePath :: StorePath -> MonadStore ()
171+ ensurePath :: ( MonadIO m ) => StorePath -> RemoteStoreT m ()
169172ensurePath pn = do
170173 void $ simpleOpArgs EnsurePath $ putPath pn
171174
172175-- | Find garbage collector roots.
173- findRoots :: MonadStore (Map ByteString StorePath )
176+ findRoots :: ( MonadIO m ) => RemoteStoreT m (Map ByteString StorePath )
174177findRoots = do
175178 runOp FindRoots
176179 sd <- getStoreDir
@@ -182,40 +185,42 @@ findRoots = do
182185 r <- catRights res
183186 return $ Data.Map.Strict. fromList r
184187 where
185- catRights :: [(a , Either String b )] -> MonadStore [(a , b )]
188+ catRights :: ( MonadIO m ) => [(a , Either String b )] -> RemoteStoreT m [(a , b )]
186189 catRights = mapM ex
187190
188- ex :: (a , Either [Char ] b ) -> MonadStore (a , b )
191+ ex :: (MonadIO m ) => ( a , Either [Char ] b ) -> RemoteStoreT m (a , b )
189192 ex (x, Right y) = return (x, y)
190193 ex (_x , Left e) = error $ " Unable to decode root: " ++ e
191194
192- isValidPathUncached :: StorePath -> MonadStore Bool
195+ isValidPathUncached :: ( MonadIO m ) => StorePath -> RemoteStoreT m Bool
193196isValidPathUncached p = do
194197 simpleOpArgs IsValidPath $ putPath p
195198
196199-- | Query valid paths from set, optionally try to use substitutes.
197- queryValidPaths :: StorePathSet -- ^ Set of `StorePath`s to query
200+ queryValidPaths :: (MonadIO m )
201+ => StorePathSet -- ^ Set of `StorePath`s to query
198202 -> SubstituteFlag -- ^ Try substituting missing paths when `True`
199- -> MonadStore StorePathSet
203+ -> RemoteStoreT m StorePathSet
200204queryValidPaths ps substitute = do
201205 runOpArgs QueryValidPaths $ do
202206 putPaths ps
203207 putBool substitute
204208 sockGetPaths
205209
206- queryAllValidPaths :: MonadStore StorePathSet
210+ queryAllValidPaths :: ( MonadIO m ) => RemoteStoreT m StorePathSet
207211queryAllValidPaths = do
208212 runOp QueryAllValidPaths
209213 sockGetPaths
210214
211- querySubstitutablePaths :: StorePathSet -> MonadStore StorePathSet
215+ querySubstitutablePaths :: ( MonadIO m ) => StorePathSet -> RemoteStoreT m StorePathSet
212216querySubstitutablePaths ps = do
213217 runOpArgs QuerySubstitutablePaths $ do
214218 putPaths ps
215219 sockGetPaths
216220
217- queryPathInfoUncached :: StorePath
218- -> MonadStore StorePathMetadata
221+ queryPathInfoUncached :: (MonadIO m )
222+ => StorePath
223+ -> RemoteStoreT m StorePathMetadata
219224queryPathInfoUncached path = do
220225 runOpArgs QueryPathInfo $ do
221226 putPath path
@@ -252,31 +257,31 @@ queryPathInfoUncached path = do
252257
253258 return $ StorePathMetadata {.. }
254259
255- queryReferrers :: StorePath -> MonadStore StorePathSet
260+ queryReferrers :: ( MonadIO m ) => StorePath -> RemoteStoreT m StorePathSet
256261queryReferrers p = do
257262 runOpArgs QueryReferrers $ do
258263 putPath p
259264 sockGetPaths
260265
261- queryValidDerivers :: StorePath -> MonadStore StorePathSet
266+ queryValidDerivers :: ( MonadIO m ) => StorePath -> RemoteStoreT m StorePathSet
262267queryValidDerivers p = do
263268 runOpArgs QueryValidDerivers $ do
264269 putPath p
265270 sockGetPaths
266271
267- queryDerivationOutputs :: StorePath -> MonadStore StorePathSet
272+ queryDerivationOutputs :: ( MonadIO m ) => StorePath -> RemoteStoreT m StorePathSet
268273queryDerivationOutputs p = do
269274 runOpArgs QueryDerivationOutputs $
270275 putPath p
271276 sockGetPaths
272277
273- queryDerivationOutputNames :: StorePath -> MonadStore StorePathSet
278+ queryDerivationOutputNames :: ( MonadIO m ) => StorePath -> RemoteStoreT m StorePathSet
274279queryDerivationOutputNames p = do
275280 runOpArgs QueryDerivationOutputNames $
276281 putPath p
277282 sockGetPaths
278283
279- queryPathFromHashPart :: Digest StorePathHashAlgo -> MonadStore StorePath
284+ queryPathFromHashPart :: ( MonadIO m ) => Digest StorePathHashAlgo -> RemoteStoreT m StorePath
280285queryPathFromHashPart storePathHash = do
281286 runOpArgs QueryPathFromHashPart $
282287 putByteStringLen
@@ -285,12 +290,13 @@ queryPathFromHashPart storePathHash = do
285290 $ System.Nix.Hash. encodeBase32 storePathHash
286291 sockGetPath
287292
288- queryMissing :: StorePathSet
289- -> MonadStore ( StorePathSet -- Paths that will be built
290- , StorePathSet -- Paths that have substitutes
291- , StorePathSet -- Unknown paths
292- , Integer -- Download size
293- , Integer ) -- Nar size?
293+ queryMissing :: (MonadIO m )
294+ => StorePathSet
295+ -> RemoteStoreT m ( StorePathSet -- Paths that will be built
296+ , StorePathSet -- Paths that have substitutes
297+ , StorePathSet -- Unknown paths
298+ , Integer -- Download size
299+ , Integer ) -- Nar size?
294300queryMissing ps = do
295301 runOpArgs QueryMissing $ do
296302 putPaths ps
@@ -302,14 +308,14 @@ queryMissing ps = do
302308 narSize' <- sockGetInt
303309 return (willBuild, willSubstitute, unknown, downloadSize', narSize')
304310
305- optimiseStore :: MonadStore ()
311+ optimiseStore :: ( MonadIO m ) => RemoteStoreT m ()
306312optimiseStore = void $ simpleOp OptimiseStore
307313
308- syncWithGC :: MonadStore ()
314+ syncWithGC :: ( MonadIO m ) => RemoteStoreT m ()
309315syncWithGC = void $ simpleOp SyncWithGC
310316
311317-- returns True on errors
312- verifyStore :: CheckFlag -> RepairFlag -> MonadStore Bool
318+ verifyStore :: ( MonadIO m ) => CheckFlag -> RepairFlag -> RemoteStoreT m Bool
313319verifyStore check repair = simpleOpArgs VerifyStore $ do
314320 putBool check
315321 putBool repair
0 commit comments