Skip to content

Instantly share code, notes, and snippets.

@domenkozar
Last active February 25, 2021 23:25
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save domenkozar/29cff75ef2a538770bd331af22383585 to your computer and use it in GitHub Desktop.
Cachix Server Repl using hint
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Repl where
import Cachix.Config (readConfig)
import Cachix.Env (setupApp)
import Cachix.Server.Prelude
import qualified Control.Exception.Safe as Safe
import qualified Language.Haskell.Interpreter as Interpreter
import Protolude
import qualified System.IO
import qualified Prelude
extensions :: Interpreter.OptionVal (Interpreter.InterpreterT App)
extensions =
Interpreter.languageExtensions
Interpreter.:= [ Interpreter.NoImplicitPrelude,
Interpreter.DeriveGeneric,
Interpreter.LambdaCase,
Interpreter.OverloadedStrings
]
main :: FilePath -> IO ()
main configPath = do
config <- readConfig $ toS configPath
finished <- setupApp config $ Interpreter.runInterpreter $ do
Interpreter.set
[ extensions,
Interpreter.searchPath Interpreter.:= ["src"],
Interpreter.installedModulesInScope Interpreter.:= True
]
putText "Loading modules ..."
Interpreter.loadModules ["Cachix.Server"]
Interpreter.setImports ["Prelude"]
putText ""
putText "Welcome to Cachix Server REPL!"
putText ""
loop
escalate finished
loop :: Interpreter.InterpreterT App ()
loop = do
liftIO $ putStr ("> " :: Text)
liftIO $ System.IO.hFlush System.IO.stdout
statement <- liftIO Prelude.getLine
type_ <- Interpreter.typeOf statement
Safe.handle handleInterpreterError $ Interpreter.runStmt statement
liftIO $ putStrLn $ ":: " <> type_
loop
handleInterpreterError :: Interpreter.InterpreterError -> Interpreter.InterpreterT App ()
handleInterpreterError = print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment