99{-# LANGUAGE TypeFamilies #-}
1010{-# LANGUAGE DataKinds #-}
1111{-# LANGUAGE TypeApplications #-}
12+ {-# LANGUAGE StandaloneDeriving #-}
13+ {-# LANGUAGE GeneralizedNewtypeDeriving #-}
14+ {-# LANGUAGE UndecidableInstances #-}
15+
16+ {-# OPTIONS_GHC -Wno-orphans #-}
17+
1218
1319module Nix.Effects where
1420
@@ -26,6 +32,7 @@ import qualified Data.Text.Encoding as T
2632import Network.HTTP.Client hiding ( path , Proxy )
2733import Network.HTTP.Client.TLS
2834import Network.HTTP.Types
35+ import Nix.Utils.Fix1
2936import Nix.Expr
3037import Nix.Frames hiding ( Proxy )
3138import Nix.Parser
@@ -40,7 +47,7 @@ import qualified System.Info
4047import System.Process
4148
4249import qualified System.Nix.Hash as Store
43- import qualified System.Nix.Store.Remote as Store
50+ import qualified System.Nix.Store.Remote as Store.Remote
4451import qualified System.Nix.StorePath as Store
4552
4653-- | A path into the nix store
@@ -70,6 +77,10 @@ class (MonadFile m,
7077
7178 traceEffect :: String -> m ()
7279
80+ instance (MonadFix1T t m , MonadStore m ) => MonadStore (Fix1T t m ) where
81+ addToStore a b c d = lift $ addToStore a b c d
82+ addTextToStore' a b c d = lift $ addTextToStore' a b c d
83+
7384class Monad m => MonadIntrospect m where
7485 recursiveSize :: a -> m Word
7586 default recursiveSize :: (MonadTrans t , MonadIntrospect m' , m ~ t m' ) => a -> m Word
@@ -219,11 +230,11 @@ instance MonadHttp IO where
219230
220231
221232class Monad m => MonadPutStr m where
222- -- TODO: Should this be used *only* when the Nix to be evaluated invokes a
223- -- `trace` operation?
224- putStr :: String -> m ()
225- default putStr :: (MonadTrans t , MonadPutStr m' , m ~ t m' ) => String -> m ()
226- putStr = lift . putStr
233+ -- TODO: Should this be used *only* when the Nix to be evaluated invokes a
234+ -- `trace` operation?
235+ putStr :: String -> m ()
236+ default putStr :: (MonadTrans t , MonadPutStr m' , m ~ t m' ) => String -> m ()
237+ putStr = lift . putStr
227238
228239putStrLn :: MonadPutStr m => String -> m ()
229240putStrLn = putStr . (<> " \n " )
@@ -243,20 +254,20 @@ type StorePathSet = HS.HashSet StorePath
243254
244255class Monad m => MonadStore m where
245256
246- -- | Copy the contents of a local path to the store. The resulting store
247- -- path is returned. Note: This does not support yet support the expected
248- -- `filter` function that allows excluding some files.
249- addToStore :: StorePathName -> FilePath -> RecursiveFlag -> RepairFlag -> m (Either ErrorCall StorePath )
250- default addToStore :: (MonadTrans t , MonadStore m' , m ~ t m' ) => StorePathName -> FilePath -> RecursiveFlag -> RepairFlag -> m (Either ErrorCall StorePath )
251- addToStore a b c d = lift $ addToStore a b c d
257+ -- | Copy the contents of a local path to the store. The resulting store
258+ -- path is returned. Note: This does not support yet support the expected
259+ -- `filter` function that allows excluding some files.
260+ addToStore :: StorePathName -> FilePath -> RecursiveFlag -> RepairFlag -> m (Either ErrorCall StorePath )
261+ default addToStore :: (MonadTrans t , MonadStore m' , m ~ t m' ) => StorePathName -> FilePath -> RecursiveFlag -> RepairFlag -> m (Either ErrorCall StorePath )
262+ addToStore a b c d = lift $ addToStore a b c d
252263
253- -- | Like addToStore, but the contents written to the output path is a
254- -- regular file containing the given string.
255- addTextToStore' :: StorePathName -> Text -> Store. StorePathSet -> RepairFlag -> m (Either ErrorCall StorePath )
256- default addTextToStore' :: (MonadTrans t , MonadStore m' , m ~ t m' ) => StorePathName -> Text -> Store. StorePathSet -> RepairFlag -> m (Either ErrorCall StorePath )
257- addTextToStore' a b c d = lift $ addTextToStore' a b c d
264+ -- | Like addToStore, but the contents written to the output path is a
265+ -- regular file containing the given string.
266+ addTextToStore' :: StorePathName -> Text -> Store. StorePathSet -> RepairFlag -> m (Either ErrorCall StorePath )
267+ default addTextToStore' :: (MonadTrans t , MonadStore m' , m ~ t m' ) => StorePathName -> Text -> Store. StorePathSet -> RepairFlag -> m (Either ErrorCall StorePath )
268+ addTextToStore' a b c d = lift $ addTextToStore' a b c d
258269
259- parseStoreResult :: Monad m => String -> (Either String a , [Store. Logger ]) -> m (Either ErrorCall a )
270+ parseStoreResult :: Monad m => String -> (Either String a , [Store.Remote. Logger ]) -> m (Either ErrorCall a )
260271parseStoreResult name res = case res of
261272 (Left msg, logs) -> return $ Left $ ErrorCall $ " Failed to execute '" <> name <> " ': " <> msg <> " \n " <> show logs
262273 (Right result, _) -> return $ Right result
@@ -267,13 +278,13 @@ instance MonadStore IO where
267278 Left err -> return $ Left $ ErrorCall $ " String '" <> show name <> " ' is not a valid path name: " <> err
268279 Right pathName -> do
269280 -- TODO: redesign the filter parameter
270- res <- Store. runStore $ Store. addToStore @ 'Store.SHA256 pathName path recursive (const False ) repair
281+ res <- Store.Remote. runStore $ Store.Remote . addToStore @ 'Store.SHA256 pathName path recursive (const False ) repair
271282 parseStoreResult " addToStore" res >>= \ case
272283 Left err -> return $ Left err
273284 Right storePath -> return $ Right $ StorePath $ T. unpack $ T. decodeUtf8 $ Store. storePathToRawFilePath storePath
274285
275286 addTextToStore' name text references repair = do
276- res <- Store. runStore $ Store. addTextToStore name text references repair
287+ res <- Store.Remote. runStore $ Store.Remote . addTextToStore name text references repair
277288 parseStoreResult " addTextToStore" res >>= \ case
278289 Left err -> return $ Left err
279290 Right path -> return $ Right $ StorePath $ T. unpack $ T. decodeUtf8 $ Store. storePathToRawFilePath path
@@ -286,3 +297,21 @@ addPath p = either throwError return =<< addToStore (T.pack $ takeFileName p) p
286297
287298toFile_ :: (Framed e m , MonadStore m ) => FilePath -> String -> m StorePath
288299toFile_ p contents = addTextToStore (T. pack p) (T. pack contents) HS. empty False
300+
301+ -- All of the following type classes defer to the underlying 'm'.
302+
303+ deriving instance MonadPutStr (t (Fix1 t )) => MonadPutStr (Fix1 t )
304+ deriving instance MonadHttp (t (Fix1 t )) => MonadHttp (Fix1 t )
305+ deriving instance MonadEnv (t (Fix1 t )) => MonadEnv (Fix1 t )
306+ deriving instance MonadPaths (t (Fix1 t )) => MonadPaths (Fix1 t )
307+ deriving instance MonadInstantiate (t (Fix1 t )) => MonadInstantiate (Fix1 t )
308+ deriving instance MonadExec (t (Fix1 t )) => MonadExec (Fix1 t )
309+ deriving instance MonadIntrospect (t (Fix1 t )) => MonadIntrospect (Fix1 t )
310+
311+ deriving instance MonadPutStr (t (Fix1T t m ) m ) => MonadPutStr (Fix1T t m )
312+ deriving instance MonadHttp (t (Fix1T t m ) m ) => MonadHttp (Fix1T t m )
313+ deriving instance MonadEnv (t (Fix1T t m ) m ) => MonadEnv (Fix1T t m )
314+ deriving instance MonadPaths (t (Fix1T t m ) m ) => MonadPaths (Fix1T t m )
315+ deriving instance MonadInstantiate (t (Fix1T t m ) m ) => MonadInstantiate (Fix1T t m )
316+ deriving instance MonadExec (t (Fix1T t m ) m ) => MonadExec (Fix1T t m )
317+ deriving instance MonadIntrospect (t (Fix1T t m ) m ) => MonadIntrospect (Fix1T t m )
0 commit comments