~fgaz/orchid

87eb10090e82035a64c20b0fd0800fa8b1975d99 — Francesco Gazzetta 3 years ago be664b6
Obtain the store path from nix
2 files changed, 11 insertions(+), 4 deletions(-)

M Main.hs
M src/BaseContext.hs
M Main.hs => Main.hs +1 -1
@@ 11,6 11,6 @@ import Options.Applicative
main :: IO ()
main = do
  (globalOpts, cmd) <- execParser optionsInfo
  let baseCtx = establishBaseContext globalOpts
  baseCtx <- establishBaseContext globalOpts
  case cmd of
    Pin p -> pinAction baseCtx p

M src/BaseContext.hs => src/BaseContext.hs +10 -3
@@ 5,6 5,8 @@ import qualified Options.GlobalOptions as GlobalOptions

import Data.Maybe (fromMaybe)

import System.Process (readProcess)


-- | The context we need to execute any command.
-- Contains just the store path for now, but what is lost in verbosity is gained


@@ 12,6 14,11 @@ import Data.Maybe (fromMaybe)
data BaseContext = BaseContext
  { storeDir :: FilePath }

establishBaseContext :: GlobalOptions -> BaseContext
establishBaseContext globalOpts = BaseContext
  { storeDir = fromMaybe "/nix/store" $ GlobalOptions.storeDir globalOpts }
establishBaseContext :: GlobalOptions -> IO BaseContext
establishBaseContext globalOpts = do
  defaultStoreDir <- readProcess "nix"
                       ["eval", "--raw", "(builtins.storeDir)"]
                       mempty
  pure BaseContext
    { storeDir = fromMaybe defaultStoreDir $ GlobalOptions.storeDir globalOpts
    }