9
9
{-# LANGUAGE RecordWildCards #-}
10
10
module System.Nix.Store.Remote
11
11
(
12
- MonadStoreT
13
- , MonadStore
12
+ RemoteStoreT
13
+ , System.Nix.Nar. PathType ( .. )
14
14
, addToStore
15
15
, addTextToStore
16
16
, addSignatures
@@ -75,14 +75,14 @@ type CheckSigsFlag = Bool
75
75
type SubstituteFlag = Bool
76
76
77
77
-- | 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 )
79
79
=> StorePathName -- ^ Name part of the newly created `StorePath`
80
80
-> FilePath -- ^ Local `FilePath` to add
81
81
-> Bool -- ^ Add target directory recursively
82
- -> (FilePath -> Bool ) -- ^ Path filter function
82
+ -> (FilePath -> System.Nix.Nar. PathType -> m Bool ) -- ^ Path filter function
83
83
-> 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
86
86
87
87
runOpArgsIO AddToStore $ \ yield -> do
88
88
yield $ Data.ByteString.Lazy. toStrict $ Data.Binary.Put. runPut $ do
@@ -96,20 +96,20 @@ addToStore name pth recursive _pathFilter _repair = do
96
96
97
97
putText $ System.Nix.Hash. algoName @ a
98
98
99
- System.Nix.Nar. streamNarIO yield System.Nix.Nar. narEffectsIO pth
99
+ System.Nix.Nar. streamNarIO yield pathFilter System.Nix.Nar. narEffectsIO pth
100
100
101
101
sockGetPath
102
102
103
103
-- | Add text to store.
104
104
--
105
105
-- Reference accepts repair but only uses it
106
106
-- to throw error in case of remote talking to nix-daemon.
107
- addTextToStore :: (MonadIO m )
107
+ addTextToStore :: (MonadIO m , MonadRemoteStore m )
108
108
=> Text -- ^ Name of the text
109
109
-> Text -- ^ Actual text to add
110
110
-> StorePathSet -- ^ Set of `StorePath`s that the added text references
111
111
-> RepairFlag -- ^ Repair flag, must be `False` in case of remote backend
112
- -> MonadStoreT m StorePath
112
+ -> m StorePath
113
113
addTextToStore name text references' repair = do
114
114
when repair $ error " repairing is not supported when building through the Nix daemon"
115
115
runOpArgs AddTextToStore $ do
@@ -118,40 +118,43 @@ addTextToStore name text references' repair = do
118
118
putPaths references'
119
119
sockGetPath
120
120
121
- addSignatures :: StorePath
121
+ addSignatures :: (MonadIO m )
122
+ => StorePath
122
123
-> [ByteString ]
123
- -> MonadStore ()
124
+ -> RemoteStoreT m ()
124
125
addSignatures p signatures = do
125
126
void $ simpleOpArgs AddSignatures $ do
126
127
putPath p
127
128
putByteStrings signatures
128
129
129
- addIndirectRoot :: StorePath -> MonadStore ()
130
+ addIndirectRoot :: ( MonadIO m ) => StorePath -> RemoteStoreT m ()
130
131
addIndirectRoot pn = do
131
132
void $ simpleOpArgs AddIndirectRoot $ putPath pn
132
133
133
134
-- | Add temporary garbage collector root.
134
135
--
135
136
-- This root is removed as soon as the client exits.
136
- addTempRoot :: StorePath -> MonadStore ()
137
+ addTempRoot :: ( MonadIO m ) => StorePath -> RemoteStoreT m ()
137
138
addTempRoot pn = do
138
139
void $ simpleOpArgs AddTempRoot $ putPath pn
139
140
140
141
-- | Build paths if they are an actual derivations.
141
142
--
142
143
-- If derivation output paths are already valid, do nothing.
143
- buildPaths :: StorePathSet
144
+ buildPaths :: (MonadIO m )
145
+ => StorePathSet
144
146
-> BuildMode
145
- -> MonadStore ()
147
+ -> RemoteStoreT m ()
146
148
buildPaths ps bm = do
147
149
void $ simpleOpArgs BuildPaths $ do
148
150
putPaths ps
149
151
putInt $ fromEnum bm
150
152
151
- buildDerivation :: StorePath
153
+ buildDerivation :: (MonadIO m )
154
+ => StorePath
152
155
-> Derivation StorePath Text
153
156
-> BuildMode
154
- -> MonadStore BuildResult
157
+ -> RemoteStoreT m BuildResult
155
158
buildDerivation p drv buildMode = do
156
159
runOpArgs BuildDerivation $ do
157
160
putPath p
@@ -165,12 +168,12 @@ buildDerivation p drv buildMode = do
165
168
res <- getSocketIncremental $ getBuildResult
166
169
return res
167
170
168
- ensurePath :: StorePath -> MonadStore ()
171
+ ensurePath :: ( MonadIO m ) => StorePath -> RemoteStoreT m ()
169
172
ensurePath pn = do
170
173
void $ simpleOpArgs EnsurePath $ putPath pn
171
174
172
175
-- | Find garbage collector roots.
173
- findRoots :: MonadStore (Map ByteString StorePath )
176
+ findRoots :: ( MonadIO m ) => RemoteStoreT m (Map ByteString StorePath )
174
177
findRoots = do
175
178
runOp FindRoots
176
179
sd <- getStoreDir
@@ -182,40 +185,42 @@ findRoots = do
182
185
r <- catRights res
183
186
return $ Data.Map.Strict. fromList r
184
187
where
185
- catRights :: [(a , Either String b )] -> MonadStore [(a , b )]
188
+ catRights :: ( MonadIO m ) => [(a , Either String b )] -> RemoteStoreT m [(a , b )]
186
189
catRights = mapM ex
187
190
188
- ex :: (a , Either [Char ] b ) -> MonadStore (a , b )
191
+ ex :: (MonadIO m ) => ( a , Either [Char ] b ) -> RemoteStoreT m (a , b )
189
192
ex (x, Right y) = return (x, y)
190
193
ex (_x , Left e) = error $ " Unable to decode root: " ++ e
191
194
192
- isValidPathUncached :: StorePath -> MonadStore Bool
195
+ isValidPathUncached :: ( MonadIO m ) => StorePath -> RemoteStoreT m Bool
193
196
isValidPathUncached p = do
194
197
simpleOpArgs IsValidPath $ putPath p
195
198
196
199
-- | 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
198
202
-> SubstituteFlag -- ^ Try substituting missing paths when `True`
199
- -> MonadStore StorePathSet
203
+ -> RemoteStoreT m StorePathSet
200
204
queryValidPaths ps substitute = do
201
205
runOpArgs QueryValidPaths $ do
202
206
putPaths ps
203
207
putBool substitute
204
208
sockGetPaths
205
209
206
- queryAllValidPaths :: MonadStore StorePathSet
210
+ queryAllValidPaths :: ( MonadIO m ) => RemoteStoreT m StorePathSet
207
211
queryAllValidPaths = do
208
212
runOp QueryAllValidPaths
209
213
sockGetPaths
210
214
211
- querySubstitutablePaths :: StorePathSet -> MonadStore StorePathSet
215
+ querySubstitutablePaths :: ( MonadIO m ) => StorePathSet -> RemoteStoreT m StorePathSet
212
216
querySubstitutablePaths ps = do
213
217
runOpArgs QuerySubstitutablePaths $ do
214
218
putPaths ps
215
219
sockGetPaths
216
220
217
- queryPathInfoUncached :: StorePath
218
- -> MonadStore StorePathMetadata
221
+ queryPathInfoUncached :: (MonadIO m )
222
+ => StorePath
223
+ -> RemoteStoreT m StorePathMetadata
219
224
queryPathInfoUncached path = do
220
225
runOpArgs QueryPathInfo $ do
221
226
putPath path
@@ -252,31 +257,31 @@ queryPathInfoUncached path = do
252
257
253
258
return $ StorePathMetadata {.. }
254
259
255
- queryReferrers :: StorePath -> MonadStore StorePathSet
260
+ queryReferrers :: ( MonadIO m ) => StorePath -> RemoteStoreT m StorePathSet
256
261
queryReferrers p = do
257
262
runOpArgs QueryReferrers $ do
258
263
putPath p
259
264
sockGetPaths
260
265
261
- queryValidDerivers :: StorePath -> MonadStore StorePathSet
266
+ queryValidDerivers :: ( MonadIO m ) => StorePath -> RemoteStoreT m StorePathSet
262
267
queryValidDerivers p = do
263
268
runOpArgs QueryValidDerivers $ do
264
269
putPath p
265
270
sockGetPaths
266
271
267
- queryDerivationOutputs :: StorePath -> MonadStore StorePathSet
272
+ queryDerivationOutputs :: ( MonadIO m ) => StorePath -> RemoteStoreT m StorePathSet
268
273
queryDerivationOutputs p = do
269
274
runOpArgs QueryDerivationOutputs $
270
275
putPath p
271
276
sockGetPaths
272
277
273
- queryDerivationOutputNames :: StorePath -> MonadStore StorePathSet
278
+ queryDerivationOutputNames :: ( MonadIO m ) => StorePath -> RemoteStoreT m StorePathSet
274
279
queryDerivationOutputNames p = do
275
280
runOpArgs QueryDerivationOutputNames $
276
281
putPath p
277
282
sockGetPaths
278
283
279
- queryPathFromHashPart :: Digest StorePathHashAlgo -> MonadStore StorePath
284
+ queryPathFromHashPart :: ( MonadIO m ) => Digest StorePathHashAlgo -> RemoteStoreT m StorePath
280
285
queryPathFromHashPart storePathHash = do
281
286
runOpArgs QueryPathFromHashPart $
282
287
putByteStringLen
@@ -285,12 +290,13 @@ queryPathFromHashPart storePathHash = do
285
290
$ System.Nix.Hash. encodeBase32 storePathHash
286
291
sockGetPath
287
292
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?
294
300
queryMissing ps = do
295
301
runOpArgs QueryMissing $ do
296
302
putPaths ps
@@ -302,14 +308,14 @@ queryMissing ps = do
302
308
narSize' <- sockGetInt
303
309
return (willBuild, willSubstitute, unknown, downloadSize', narSize')
304
310
305
- optimiseStore :: MonadStore ()
311
+ optimiseStore :: ( MonadIO m ) => RemoteStoreT m ()
306
312
optimiseStore = void $ simpleOp OptimiseStore
307
313
308
- syncWithGC :: MonadStore ()
314
+ syncWithGC :: ( MonadIO m ) => RemoteStoreT m ()
309
315
syncWithGC = void $ simpleOp SyncWithGC
310
316
311
317
-- returns True on errors
312
- verifyStore :: CheckFlag -> RepairFlag -> MonadStore Bool
318
+ verifyStore :: ( MonadIO m ) => CheckFlag -> RepairFlag -> RemoteStoreT m Bool
313
319
verifyStore check repair = simpleOpArgs VerifyStore $ do
314
320
putBool check
315
321
putBool repair
0 commit comments