diff --git a/cbits/nix.cpp b/cbits/nix.cpp index 8dbd715..80d5b81 100644 --- a/cbits/nix.cpp +++ b/cbits/nix.cpp @@ -37,6 +37,12 @@ static ref getStore() extern "C" { +// Must be called once before the server is stated to avoid races +void initStore() +{ + getStore(); +} + void freeString(struct string * const input) { free((void *) input->data); diff --git a/src/Main.hs b/src/Main.hs index 7201610..f7f354d 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -341,6 +341,8 @@ main = do options@Options{ priority, timeout, verbosity } <- do Options.execParser Options.parserInfo + Nix.initStore + storeDirectory <- Nix.getStoreDir secretKeyFile <- Environment.lookupEnv "NIX_SECRET_KEY_FILE" diff --git a/src/Nix.hsc b/src/Nix.hsc index 0bd007d..c4313c0 100644 --- a/src/Nix.hsc +++ b/src/Nix.hsc @@ -34,6 +34,8 @@ import qualified Foreign #include "nix.hh" +foreign import ccall "initStore" initStore :: IO () + foreign import ccall "freeString" freeString :: Ptr String_ -> IO () data String_ = String_ { data_ :: Ptr CChar, size :: CSize }