Skip to content

Commit

Permalink
remote: add postGreet so we setStoreDir in Server as well
Browse files Browse the repository at this point in the history
  • Loading branch information
sorki committed Dec 10, 2023
1 parent 4651980 commit 3dc7ab6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
13 changes: 8 additions & 5 deletions hnix-store-remote/src/System/Nix/Store/Remote.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ runStoreSocket sockFamily sockAddr code =

justdoit :: Run IO (Bool, Bool)
justdoit = do
runDaemonConnection handler (StoreConnection_Socket "/tmp/dsock") $
runDaemonConnection handler (pure ()) (StoreConnection_Socket "/tmp/dsock") $
runStoreConnection (StoreConnection_Socket "/tmp/dsock")
$ do
a <- isValidPath pth
Expand Down Expand Up @@ -124,6 +124,7 @@ runDaemon
runDaemon workerHelper =
runDaemonConnection
workerHelper
(pure ())
def

-- | Run an emulated nix daemon using given @StoreConnection@
Expand All @@ -134,14 +135,15 @@ runDaemonConnection
, MonadConc m
)
=> WorkerHelper m
-> RemoteStoreT m ()
-> StoreConnection
-> m a
-> m a
runDaemonConnection workerHelper sc k =
runDaemonConnection workerHelper postGreet sc k =
connectionToSocket sc
>>= \case
Left e -> error $ show e
Right (fam, sock) -> runDaemonSocket workerHelper fam sock k
Right (fam, sock) -> runDaemonSocket workerHelper postGreet fam sock k

-- | Run an emulated nix daemon using given @StoreConnection@
-- the deamon will close when the continuation returns.
Expand All @@ -151,11 +153,12 @@ runDaemonSocket
, MonadConc m
)
=> WorkerHelper m
-> RemoteStoreT m ()
-> Family
-> SockAddr
-> m a
-> m a
runDaemonSocket workerHelper sockFamily sockAddr k =
runDaemonSocket workerHelper postGreet sockFamily sockAddr k =
Control.Monad.Catch.bracket
(liftIO
$ Network.Socket.socket
Expand All @@ -177,7 +180,7 @@ runDaemonSocket workerHelper sockFamily sockAddr k =

-- set up the listening socket
liftIO $ Network.Socket.bind lsock sockAddr
runProxyDaemon workerHelper lsock k
runProxyDaemon workerHelper postGreet lsock k

connectionToSocket
:: MonadIO m
Expand Down
11 changes: 8 additions & 3 deletions hnix-store-remote/src/System/Nix/Store/Remote/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ runProxyDaemon
, MonadConc m
)
=> WorkerHelper m
-> RemoteStoreT m ()
-> Socket
-> m a
-> m a
runProxyDaemon workerHelper lsock k = do
runProxyDaemon workerHelper postGreet lsock k = do
liftIO $ listen lsock maxListenQueue

liftIO $ Data.Text.IO.putStrLn "listening"
Expand All @@ -66,7 +67,7 @@ runProxyDaemon workerHelper lsock k = do
-- TODO: this, but without the space leak
fmap fst
$ concurrently listener
$ processConnection workerHelper sock
$ processConnection workerHelper postGreet sock

either absurd id <$> race listener k

Expand All @@ -77,9 +78,10 @@ processConnection
:: forall m
. MonadIO m
=> WorkerHelper m
-> RemoteStoreT m ()
-> Socket
-> m ()
processConnection workerHelper sock = do
processConnection workerHelper postGreet sock = do
~() <- void $ runRemoteStoreT sock $ do

ServerHandshakeOutput{..}
Expand All @@ -101,6 +103,9 @@ processConnection workerHelper sock = do
--authHook(*store);
stopWork tunnelLogger

-- so we can set store dir
postGreet

let perform
:: ( Show a
, StoreReply a
Expand Down
4 changes: 3 additions & 1 deletion hnix-store-remote/tests-io/NixDaemonSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ withManInTheMiddleNixDaemon action =
. doReq

in action $ \(mstore :: RemoteStoreT m a) ->
runDaemonConnection handler storeConn2
runDaemonConnection handler
(setStoreDir storeDir)
storeConn2
$ runStoreConnection storeConn2
( setStoreDir storeDir
>> mstore
Expand Down

0 comments on commit 3dc7ab6

Please sign in to comment.