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
+ }