Fix Nix.Exec

This commit is contained in:
Ken Micklas 2019-03-09 17:52:20 -05:00
parent 91d5be6e49
commit d9293cf034
3 changed files with 55 additions and 8 deletions

View file

@ -487,13 +487,13 @@ fromStringNoContext ns =
newtype Lazy m a = Lazy
{ runLazy :: ReaderT (Context (Lazy m) (NThunk (Lazy m)))
(StateT (HashMap FilePath NExprLoc) m) a }
(StateT (HashMap FilePath NExprLoc) (FreshIdT Int m)) a }
deriving (Functor, Applicative, Alternative, Monad, MonadPlus,
MonadFix, MonadIO,
MonadFix, MonadIO, MonadFreshId Int,
MonadReader (Context (Lazy m) (NThunk (Lazy m))))
instance MonadTrans Lazy where
lift = Lazy . lift . lift
lift = Lazy . lift . lift . lift
instance MonadRef m => MonadRef (Lazy m) where
type Ref (Lazy m) = Ref m
@ -612,7 +612,8 @@ getRecursiveSize :: MonadIntrospect m => a -> m (NValue m)
getRecursiveSize = toNix @Integer . fromIntegral <=< recursiveSize
runLazyM :: Options -> MonadIO m => Lazy m a -> m a
runLazyM opts = (`evalStateT` M.empty)
runLazyM opts = runFreshIdT 0
. (`evalStateT` M.empty)
. (`runReaderT` newContext opts)
. runLazy
@ -791,10 +792,44 @@ fetchTarball v = v >>= \case
++ "url = \"" ++ Text.unpack url ++ "\"; "
++ "sha256 = \"" ++ Text.unpack sha ++ "\"; }"
exec :: (MonadExec m, Framed e m, MonadThrow m, Alternative m, MonadCatch m, MonadFix m, MonadEffects m, GEq (Ref m), MonadAtomicRef m, Typeable m, Has e Options, Has e SrcSpan, Scoped (NThunk m) m) => [String] -> m (NValue m)
exec
:: ( MonadExec m
, Framed e m
, MonadThrow m
, Alternative m
, MonadCatch m
, MonadFix m
, MonadEffects m
, MonadFreshId Int m
, GEq (Ref m)
, MonadAtomicRef m
, Typeable m
, Has e Options
, Has e SrcSpan
, Scoped (NThunk m) m
)
=> [String]
-> m (NValue m)
exec args = either throwError evalExprLoc =<< exec' args
nixInstantiateExpr :: (MonadInstantiate m, Framed e m, MonadThrow m, Alternative m, MonadCatch m, MonadFix m, MonadEffects m, GEq (Ref m), MonadAtomicRef m, Typeable m, Has e Options, Has e SrcSpan, Scoped (NThunk m) m) => String -> m (NValue m)
nixInstantiateExpr
:: ( MonadInstantiate m
, Framed e m
, MonadThrow m
, Alternative m
, MonadCatch m
, MonadFix m
, MonadEffects m
, MonadFreshId Int m
, GEq (Ref m)
, MonadAtomicRef m
, Typeable m
, Has e Options
, Has e SrcSpan
, Scoped (NThunk m) m
)
=> String
-> m (NValue m)
nixInstantiateExpr s = either throwError evalExprLoc =<< instantiateExpr s
instance Monad m => Scoped (NThunk (Lazy m)) (Lazy m) where

View file

@ -20,12 +20,13 @@
module Nix.Thunk where
import Control.Applicative
import Control.Exception hiding (catch)
import Control.Monad.Catch
import Control.Monad.Except
import Control.Monad.Reader
import Control.Monad.Ref
import Control.Monad.State
import Control.Monad.State.Strict
import Control.Monad.ST
import Control.Monad.Writer
import Data.GADT.Compare
@ -33,6 +34,9 @@ import Data.IORef
import Data.Maybe
import Data.STRef
import Data.Typeable
#ifdef MIN_VERSION_haskeline
import System.Console.Haskeline.MonadException hiding (catch)
#endif
import Unsafe.Coerce
@ -66,11 +70,19 @@ newtype FreshIdT i m a = FreshIdT { unFreshIdT :: StateT i m a }
deriving
( Functor
, Applicative
, Alternative
, Monad
, MonadPlus
, MonadTrans
, MonadFix
, MonadRef
, MonadAtomicRef
, MonadIO
, MonadCatch
, MonadThrow
#ifdef MIN_VERSION_haskeline
, MonadException
#endif
)
instance (Monad m, Num i) => MonadFreshId i (FreshIdT i m) where

View file

@ -32,7 +32,7 @@ import Control.Monad.Logic
import Control.Monad.Reader
import Control.Monad.Ref
import Control.Monad.ST
import Control.Monad.State
import Control.Monad.State.Strict
import Data.Fix
import Data.Foldable
import qualified Data.HashMap.Lazy as M