{-# 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
    forall a. Semigroup a => a -> a -> a
<> Context
C.fptrCtx
    forall a. Semigroup a => a -> a -> a
<> Context
C.bsCtx
    forall a. Semigroup a => a -> a -> a
<> forall a. Monoid a => a
mempty
      { ctxTypesTable :: TypesTable
C.ctxTypesTable =
          forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"refStore") [t|Ref NixStore|]
            forall a. Semigroup a => a -> a -> a
<> forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"nix::StorePath") [t|NixStorePath|]
            forall a. Semigroup a => a -> a -> a
<> forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"nix::StorePathWithOutputs") [t|NixStorePathWithOutputs|]
            forall a. Semigroup a => a -> a -> a
<> forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"refValidPathInfo") [t|Ref ValidPathInfo|]
            forall a. Semigroup a => a -> a -> a
<> forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"Strings") [t|Strings|]
            forall a. Semigroup a => a -> a -> a
<> forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"StringsIterator") [t|StringsIterator|]
            forall a. Semigroup a => a -> a -> a
<> forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"StringPairs") [t|StringPairs|]
            forall a. Semigroup a => a -> a -> a
<> forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"StringPairsIterator") [t|StringPairsIterator|]
            forall a. Semigroup a => a -> a -> a
<> forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"Derivation") [t|Derivation|]
            forall a. Semigroup a => a -> a -> a
<> forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"DerivationOutputsIterator") [t|DerivationOutputsIterator|]
            forall a. Semigroup a => a -> a -> a
<> forall k a. k -> a -> Map k a
M.singleton (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"DerivationInputsIterator") [t|DerivationInputsIterator|]
            forall a. Semigroup a => a -> a -> a
<> 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 = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (CString -> IO ByteString
unsafePackMallocCString forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IO CString
m)