I've been playing around with the plugins package. I want a host application to dynamically compile and load Haskell source files in a sandboxed environment. Compilation works just fine. Loading fails as soon as the plugin references modules available in the sandbox only. Here is what I've got for the plugin:
module Plugin (resource) where
import ServerAPI
import System.Plugins -- this module is only available in the sandbox
resource = Interface { action = timesTwo }
timesTwo :: Integer -> IO Integer
timesTwo n = return $ n * 2
Loading the plugin from the host application looks like this:
pkgConfDir = "/home/me/plugins/.cabal-sandbox/x86_64-osx-ghc-7.8.4-packages.conf.d
loadedOk <- pdynload "Plugin.o" ["."] [pkgConfDir] "ServerAPI.Interface" "resource"
This is what I've got in the sandbox:
> cabal sandbox hc-pkg list
…
/home/me/plugins/.cabal-sandbox/x86_64-osx-ghc-7.8.4-packages.conf.d
plugins-1.5.4.0
…
This is what I get when running the host application:
Failed to load interface for ‘System.Plugins.Env’
no package matching ‘plugins-1.5.4.0’ was found
As mentioned above, when I get rid of the import System.Plugins
statement in the plugin the code does load. What am I missing?
Edit:
The cabal file:
name: plugins
version: 0.1.0.0
-- synopsis:
-- description:
-- license:
license-file: LICENSE
author: W. Davis
maintainer: w.davis@spam.me.not
-- copyright:
-- category:
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
executable plugins
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.7 && <4.8, plugins >=1.5 && <1.6
-- hs-source-dirs:
default-language: Haskell2010