{-# LANGUAGE BlockArguments #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} module Hercules.CNix ( module Hercules.CNix, module Hercules.CNix.Store, ) where -- TODO: No more Ptr EvalState -- TODO: No more NixStore when EvalState is already there -- TODO: Map Nix-specific C++ exceptions to a CNix exception type import Hercules.CNix.Store import qualified Language.C.Inline.Cpp as C import qualified Language.C.Inline.Cpp.Exceptions as C import Protolude hiding (evalState, throwIO) C.context context C.include "" C.include "" C.include "" C.include "" C.include "" C.include "" C.include "" C.include "" C.include "" C.include "" C.include "hercules-ci-cnix/store.hxx" C.include "" C.include "" C.include "" C.using "namespace nix" init :: IO () init = void [C.throwBlock| void { nix::initNix(); } |] setTalkative :: IO () setTalkative = [C.throwBlock| void { nix::verbosity = nix::lvlTalkative; } |] setDebug :: IO () setDebug = [C.throwBlock| void { nix::verbosity = nix::lvlVomit; } |] setGlobalOption :: Text -> Text -> IO () setGlobalOption opt value = do let optionStr = encodeUtf8 opt valueStr = encodeUtf8 value [C.throwBlock| void { globalConfig.set($bs-cstr:optionStr, $bs-cstr:valueStr); }|] setOption :: Text -> Text -> IO () setOption opt value = do let optionStr = encodeUtf8 opt valueStr = encodeUtf8 value [C.throwBlock| void { settings.set($bs-cstr:optionStr, $bs-cstr:valueStr); }|] logInfo :: Text -> IO () logInfo t = do let bstr = encodeUtf8 t [C.throwBlock| void { printInfo($bs-cstr:bstr); }|] appendString :: Ptr Strings -> ByteString -> IO () appendString ss s = [C.block| void { $(Strings *ss)->push_back(std::string($bs-ptr:s, $bs-len:s)); }|]