{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeSynonymInstances #-}

{-# OPTIONS_GHC -Wno-orphans #-}

module Nix.Fresh.Basic where

#if !MIN_VERSION_base(4,13,0)
import           Control.Monad.Fail ( MonadFail )
#endif
import           Control.Monad.Reader
import           Nix.Effects
import           Nix.Render
import           Nix.Fresh
import           Nix.Value

type StdIdT = FreshIdT Int

instance (MonadFail m, MonadFile m) => MonadFile (StdIdT m)
instance MonadIntrospect m => MonadIntrospect (StdIdT m)
instance MonadStore m => MonadStore (StdIdT m) where
  addPath' :: FilePath -> StdIdT m (Either ErrorCall StorePath)
addPath' = m (Either ErrorCall StorePath)
-> StdIdT m (Either ErrorCall StorePath)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Either ErrorCall StorePath)
 -> StdIdT m (Either ErrorCall StorePath))
-> (FilePath -> m (Either ErrorCall StorePath))
-> FilePath
-> StdIdT m (Either ErrorCall StorePath)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> m (Either ErrorCall StorePath)
forall (m :: * -> *).
MonadStore m =>
FilePath -> m (Either ErrorCall StorePath)
addPath'
  toFile_' :: FilePath -> FilePath -> StdIdT m (Either ErrorCall StorePath)
toFile_' = (m (Either ErrorCall StorePath)
-> StdIdT m (Either ErrorCall StorePath)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Either ErrorCall StorePath)
 -> StdIdT m (Either ErrorCall StorePath))
-> (FilePath -> m (Either ErrorCall StorePath))
-> FilePath
-> StdIdT m (Either ErrorCall StorePath)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((FilePath -> m (Either ErrorCall StorePath))
 -> FilePath -> StdIdT m (Either ErrorCall StorePath))
-> (FilePath -> FilePath -> m (Either ErrorCall StorePath))
-> FilePath
-> FilePath
-> StdIdT m (Either ErrorCall StorePath)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> FilePath -> m (Either ErrorCall StorePath)
forall (m :: * -> *).
MonadStore m =>
FilePath -> FilePath -> m (Either ErrorCall StorePath)
toFile_'
instance MonadPutStr m => MonadPutStr (StdIdT m)
instance MonadHttp m => MonadHttp (StdIdT m)
instance MonadEnv m => MonadEnv (StdIdT m)
instance MonadPaths m => MonadPaths (StdIdT m)
instance MonadInstantiate m => MonadInstantiate (StdIdT m)
instance MonadExec m => MonadExec (StdIdT m)

instance (MonadEffects t f m, MonadDataContext f m)
  => MonadEffects t f (StdIdT m) where
  makeAbsolutePath :: FilePath -> StdIdT m FilePath
makeAbsolutePath = m FilePath -> StdIdT m FilePath
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m FilePath -> StdIdT m FilePath)
-> (FilePath -> m FilePath) -> FilePath -> StdIdT m FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonadEffects t f m => FilePath -> m FilePath
forall t (f :: * -> *) (m :: * -> *).
MonadEffects t f m =>
FilePath -> m FilePath
makeAbsolutePath @t @f @m
  findEnvPath :: FilePath -> StdIdT m FilePath
findEnvPath      = m FilePath -> StdIdT m FilePath
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m FilePath -> StdIdT m FilePath)
-> (FilePath -> m FilePath) -> FilePath -> StdIdT m FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonadEffects t f m => FilePath -> m FilePath
forall t (f :: * -> *) (m :: * -> *).
MonadEffects t f m =>
FilePath -> m FilePath
findEnvPath @t @f @m
  findPath :: [NValue t f (StdIdT m)] -> FilePath -> StdIdT m FilePath
findPath vs :: [NValue t f (StdIdT m)]
vs path :: FilePath
path = do
    Ref m Int
i <- ReaderT (Ref m Int) m (Ref m Int) -> FreshIdT Int m (Ref m Int)
forall i (m :: * -> *) a. ReaderT (Var m i) m a -> FreshIdT i m a
FreshIdT ReaderT (Ref m Int) m (Ref m Int)
forall r (m :: * -> *). MonadReader r m => m r
ask
    let vs' :: [NValue t f m]
vs' = (NValue t f (StdIdT m) -> NValue t f m)
-> [NValue t f (StdIdT m)] -> [NValue t f m]
forall a b. (a -> b) -> [a] -> [b]
map ((forall x. FreshIdT Int m x -> m x)
-> NValue t f (StdIdT m) -> NValue t f m
forall (u :: (* -> *) -> * -> *) (m :: * -> *) (f :: * -> *) t.
(MonadTrans u, Monad m, Functor (u m), Functor f) =>
(forall x. u m x -> m x) -> NValue t f (u m) -> NValue t f m
unliftNValue (Ref m Int -> FreshIdT Int m x -> m x
forall (m :: * -> *) i a.
Functor m =>
Var m i -> FreshIdT i m a -> m a
runFreshIdT Ref m Int
i)) [NValue t f (StdIdT m)]
vs
    m FilePath -> StdIdT m FilePath
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m FilePath -> StdIdT m FilePath)
-> m FilePath -> StdIdT m FilePath
forall a b. (a -> b) -> a -> b
$ [NValue t f m] -> FilePath -> m FilePath
forall t (f :: * -> *) (m :: * -> *).
MonadEffects t f m =>
[NValue t f m] -> FilePath -> m FilePath
findPath @t @f @m [NValue t f m]
vs' FilePath
path
  importPath :: FilePath -> StdIdT m (NValue t f (StdIdT m))
importPath path :: FilePath
path = do
    Ref m Int
i <- ReaderT (Ref m Int) m (Ref m Int) -> FreshIdT Int m (Ref m Int)
forall i (m :: * -> *) a. ReaderT (Var m i) m a -> FreshIdT i m a
FreshIdT ReaderT (Ref m Int) m (Ref m Int)
forall r (m :: * -> *). MonadReader r m => m r
ask
    NValue t f m
p <- m (NValue t f m) -> FreshIdT Int m (NValue t f m)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (NValue t f m) -> FreshIdT Int m (NValue t f m))
-> m (NValue t f m) -> FreshIdT Int m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> m (NValue t f m)
forall t (f :: * -> *) (m :: * -> *).
MonadEffects t f m =>
FilePath -> m (NValue t f m)
importPath @t @f @m FilePath
path
    NValue t f (StdIdT m) -> StdIdT m (NValue t f (StdIdT m))
forall (m :: * -> *) a. Monad m => a -> m a
return (NValue t f (StdIdT m) -> StdIdT m (NValue t f (StdIdT m)))
-> NValue t f (StdIdT m) -> StdIdT m (NValue t f (StdIdT m))
forall a b. (a -> b) -> a -> b
$ (forall x. FreshIdT Int m x -> m x)
-> NValue t f m -> NValue t f (StdIdT m)
forall (u :: (* -> *) -> * -> *) (m :: * -> *) (f :: * -> *) t.
(MonadTrans u, Monad m, Functor (u m), Functor f) =>
(forall x. u m x -> m x) -> NValue t f m -> NValue t f (u m)
liftNValue (Ref m Int -> FreshIdT Int m x -> m x
forall (m :: * -> *) i a.
Functor m =>
Var m i -> FreshIdT i m a -> m a
runFreshIdT Ref m Int
i) NValue t f m
p
  pathToDefaultNix :: FilePath -> StdIdT m FilePath
pathToDefaultNix = m FilePath -> StdIdT m FilePath
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m FilePath -> StdIdT m FilePath)
-> (FilePath -> m FilePath) -> FilePath -> StdIdT m FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonadEffects t f m => FilePath -> m FilePath
forall t (f :: * -> *) (m :: * -> *).
MonadEffects t f m =>
FilePath -> m FilePath
pathToDefaultNix @t @f @m
  derivationStrict :: NValue t f (StdIdT m) -> StdIdT m (NValue t f (StdIdT m))
derivationStrict v :: NValue t f (StdIdT m)
v = do
    Ref m Int
i <- ReaderT (Ref m Int) m (Ref m Int) -> FreshIdT Int m (Ref m Int)
forall i (m :: * -> *) a. ReaderT (Var m i) m a -> FreshIdT i m a
FreshIdT ReaderT (Ref m Int) m (Ref m Int)
forall r (m :: * -> *). MonadReader r m => m r
ask
    NValue t f m
p <- m (NValue t f m) -> FreshIdT Int m (NValue t f m)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (NValue t f m) -> FreshIdT Int m (NValue t f m))
-> m (NValue t f m) -> FreshIdT Int m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NValue t f m -> m (NValue t f m)
forall t (f :: * -> *) (m :: * -> *).
MonadEffects t f m =>
NValue t f m -> m (NValue t f m)
derivationStrict @t @f @m ((forall x. FreshIdT Int m x -> m x)
-> NValue t f (StdIdT m) -> NValue t f m
forall (u :: (* -> *) -> * -> *) (m :: * -> *) (f :: * -> *) t.
(MonadTrans u, Monad m, Functor (u m), Functor f) =>
(forall x. u m x -> m x) -> NValue t f (u m) -> NValue t f m
unliftNValue (Ref m Int -> FreshIdT Int m x -> m x
forall (m :: * -> *) i a.
Functor m =>
Var m i -> FreshIdT i m a -> m a
runFreshIdT Ref m Int
i) NValue t f (StdIdT m)
v)
    NValue t f (StdIdT m) -> StdIdT m (NValue t f (StdIdT m))
forall (m :: * -> *) a. Monad m => a -> m a
return (NValue t f (StdIdT m) -> StdIdT m (NValue t f (StdIdT m)))
-> NValue t f (StdIdT m) -> StdIdT m (NValue t f (StdIdT m))
forall a b. (a -> b) -> a -> b
$ (forall x. FreshIdT Int m x -> m x)
-> NValue t f m -> NValue t f (StdIdT m)
forall (u :: (* -> *) -> * -> *) (m :: * -> *) (f :: * -> *) t.
(MonadTrans u, Monad m, Functor (u m), Functor f) =>
(forall x. u m x -> m x) -> NValue t f m -> NValue t f (u m)
liftNValue (Ref m Int -> FreshIdT Int m x -> m x
forall (m :: * -> *) i a.
Functor m =>
Var m i -> FreshIdT i m a -> m a
runFreshIdT Ref m Int
i) NValue t f m
p
  traceEffect :: FilePath -> StdIdT m ()
traceEffect = m () -> StdIdT m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> StdIdT m ())
-> (FilePath -> m ()) -> FilePath -> StdIdT m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonadEffects t f m => FilePath -> m ()
forall t (f :: * -> *) (m :: * -> *).
MonadEffects t f m =>
FilePath -> m ()
traceEffect @t @f @m