{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskellQuotes #-}

module Hercules.CNix.Store.Context where

import Data.ByteString.Unsafe (unsafePackMallocCString)
import qualified Data.Map as M
import qualified Foreign.C.String
import qualified Language.C.Inline.Context as C
import qualified Language.C.Inline.Cpp as C
import qualified Language.C.Types as C
import Protolude

-- | A C++ @std::string@
data StdString

-- | A Nix @ref@, to be used in phantom types.
data Ref a

-- | A Nix @Strings@ aka @std::list<std::string>@
data Strings

data NixStore

data ValidPathInfo

data Derivation

data StringsIterator

data DerivationOutputsIterator

data DerivationInputsIterator

data StringPairsIterator

data StringPairs

data SecretKey

data NixStorePath

data NixStorePathWithOutputs

data CDerivation

context :: C.Context
context :: Context
context =
  Context
C.cppCtx Context -> Context -> Context
forall a. Semigroup a => a -> a -> a
<> Context
C.fptrCtx
    Context -> Context -> Context
forall a. Semigroup a => a -> a -> a
<> Context
C.bsCtx
    Context -> Context -> Context
forall a. Semigroup a => a -> a -> a
<> Context
forall a. Monoid a => a
mempty
      { ctxTypesTable :: Map TypeSpecifier (Q Type)
C.ctxTypesTable =
          TypeSpecifier -> Q Type -> Map TypeSpecifier (Q Type)
forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"refStore") [t|Ref NixStore|]
            Map TypeSpecifier (Q Type)
-> Map TypeSpecifier (Q Type) -> Map TypeSpecifier (Q Type)
forall a. Semigroup a => a -> a -> a
<> TypeSpecifier -> Q Type -> Map TypeSpecifier (Q Type)
forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"nix::StorePath") [t|NixStorePath|]
            Map TypeSpecifier (Q Type)
-> Map TypeSpecifier (Q Type) -> Map TypeSpecifier (Q Type)
forall a. Semigroup a => a -> a -> a
<> TypeSpecifier -> Q Type -> Map TypeSpecifier (Q Type)
forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"nix::StorePathWithOutputs") [t|NixStorePathWithOutputs|]
            Map TypeSpecifier (Q Type)
-> Map TypeSpecifier (Q Type) -> Map TypeSpecifier (Q Type)
forall a. Semigroup a => a -> a -> a
<> TypeSpecifier -> Q Type -> Map TypeSpecifier (Q Type)
forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"refValidPathInfo") [t|Ref ValidPathInfo|]
            Map TypeSpecifier (Q Type)
-> Map TypeSpecifier (Q Type) -> Map TypeSpecifier (Q Type)
forall a. Semigroup a => a -> a -> a
<> TypeSpecifier -> Q Type -> Map TypeSpecifier (Q Type)
forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"Strings") [t|Strings|]
            Map TypeSpecifier (Q Type)
-> Map TypeSpecifier (Q Type) -> Map TypeSpecifier (Q Type)
forall a. Semigroup a => a -> a -> a
<> TypeSpecifier -> Q Type -> Map TypeSpecifier (Q Type)
forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"StringsIterator") [t|StringsIterator|]
            Map TypeSpecifier (Q Type)
-> Map TypeSpecifier (Q Type) -> Map TypeSpecifier (Q Type)
forall a. Semigroup a => a -> a -> a
<> TypeSpecifier -> Q Type -> Map TypeSpecifier (Q Type)
forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"StringPairs") [t|StringPairs|]
            Map TypeSpecifier (Q Type)
-> Map TypeSpecifier (Q Type) -> Map TypeSpecifier (Q Type)
forall a. Semigroup a => a -> a -> a
<> TypeSpecifier -> Q Type -> Map TypeSpecifier (Q Type)
forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"StringPairsIterator") [t|StringPairsIterator|]
            Map TypeSpecifier (Q Type)
-> Map TypeSpecifier (Q Type) -> Map TypeSpecifier (Q Type)
forall a. Semigroup a => a -> a -> a
<> TypeSpecifier -> Q Type -> Map TypeSpecifier (Q Type)
forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"Derivation") [t|Derivation|]
            Map TypeSpecifier (Q Type)
-> Map TypeSpecifier (Q Type) -> Map TypeSpecifier (Q Type)
forall a. Semigroup a => a -> a -> a
<> TypeSpecifier -> Q Type -> Map TypeSpecifier (Q Type)
forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"DerivationOutputsIterator") [t|DerivationOutputsIterator|]
            Map TypeSpecifier (Q Type)
-> Map TypeSpecifier (Q Type) -> Map TypeSpecifier (Q Type)
forall a. Semigroup a => a -> a -> a
<> TypeSpecifier -> Q Type -> Map TypeSpecifier (Q Type)
forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"DerivationInputsIterator") [t|DerivationInputsIterator|]
            Map TypeSpecifier (Q Type)
-> Map TypeSpecifier (Q Type) -> Map TypeSpecifier (Q Type)
forall a. Semigroup a => a -> a -> a
<> TypeSpecifier -> Q Type -> Map TypeSpecifier (Q Type)
forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"SecretKey") [t|SecretKey|]
      }

unsafeMallocBS :: MonadIO m => IO Foreign.C.String.CString -> m ByteString
unsafeMallocBS :: forall (m :: * -> *). MonadIO m => IO CString -> m ByteString
unsafeMallocBS IO CString
m = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (CString -> IO ByteString
unsafePackMallocCString (CString -> IO ByteString) -> IO CString -> IO ByteString
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IO CString
m)