Skip to content

Commit 4c0edff

Browse files
committed
server: add proxyNarSource
1 parent e2381c8 commit 4c0edff

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ justdoit = do
108108
def
109109
"/nix/store/yyznqbwam67cmp7zfwk0rkgmi9yqsdsm-hnix-store-core-0.8.0.0"
110110

111-
handler :: MonadIO m => WorkerHelper m
111+
handler :: RemoteStoreT IO a -> IO a
112112
handler k = do
113-
x <- liftIO $ runStore $ doReq k
113+
x <- runStore k
114114
either (error . show) pure (fst x)
115115

116116
runDaemon

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import Data.Word (Word32)
2222
import qualified Data.Text
2323
import qualified Data.Text.IO
2424
import Network.Socket (Socket, accept, close, listen, maxListenQueue)
25+
import System.Nix.Nar (NarSource)
26+
import System.Nix.Store.Remote.Client (doReq)
2527
import System.Nix.Store.Remote.Serializer (LoggerSError, mapErrorS, storeRequest, workerMagic, protoVersion, int, logger, text, trustedFlag)
2628
import System.Nix.Store.Remote.Socket
2729
import System.Nix.Store.Remote.Types.StoreRequest as R
@@ -34,13 +36,16 @@ import System.Nix.Store.Remote.Types.WorkerMagic (WorkerMagic(..))
3436

3537
-- wip
3638
import Data.Some (withSome)
39+
import qualified System.Timeout
40+
import qualified Network.Socket.ByteString
3741

3842
type WorkerHelper m
3943
= forall a
4044
. ( Show a
4145
, StoreReply a
4246
)
43-
=> StoreRequest a -> m a
47+
=> RemoteStoreT m a
48+
-> m a
4449

4550
chatty :: Bool
4651
chatty = False
@@ -119,7 +124,30 @@ processConnection workerHelper postGreet sock = do
119124
=> StoreRequest a
120125
-> RemoteStoreT m ()
121126
perform req = do
122-
resp <- bracketLogger tunnelLogger $ lift $ workerHelper req
127+
128+
special <- case req of
129+
AddToStore {} -> do
130+
let proxyNarSource :: NarSource IO
131+
proxyNarSource f =
132+
liftIO
133+
(System.Timeout.timeout
134+
1000000
135+
(Network.Socket.ByteString.recv sock 8)
136+
)
137+
>>= \case
138+
Nothing -> pure ()
139+
Just x -> f x >> proxyNarSource f
140+
141+
pure $ setNarSource proxyNarSource
142+
_ -> pure $ pure ()
143+
144+
resp <-
145+
bracketLogger
146+
tunnelLogger
147+
$ lift
148+
$ workerHelper
149+
$ special >> doReq req
150+
123151
sockPutS
124152
(mapErrorS
125153
RemoteStoreError_SerializerReply

hnix-store-remote/tests-io/NixDaemonSpec.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ withManInTheMiddleNixDaemon action =
213213
<=< fmap fst
214214
. runStoreConnection storeConn
215215
. (setStoreDir storeDir >>)
216-
. doReq
217216

218217
in action $ \(mstore :: RemoteStoreT m a) ->
219218
runDaemonConnection handler

0 commit comments

Comments
 (0)