diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 6777b23be..93f20a8c3 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -54,6 +54,38 @@ void StoreCommand::run() run(getStore()); } +EvalCommand::EvalCommand() +{ + // FIXME: move to MixEvalArgs? + addFlag({ + .longName = "eval-store", + .description = "The Nix store to use for evaluations.", + .labels = {"store-url"}, + //.category = ..., + .handler = {&evalStoreUrl}, + }); +} + +EvalCommand::~EvalCommand() +{ + if (evalState) + evalState->printStats(); +} + +ref EvalCommand::getEvalStore() +{ + if (!evalStore) + evalStore = evalStoreUrl ? openStore(*evalStoreUrl) : getStore(); + return ref(evalStore); +} + +ref EvalCommand::getEvalState() +{ + if (!evalState) + evalState = std::make_shared(searchPath, getEvalStore(), getStore()); + return ref(evalState); +} + BuiltPathsCommand::BuiltPathsCommand(bool recursive) : recursive(recursive) { diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh index 35b3a384b..3aba8f25f 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/command.hh @@ -45,11 +45,20 @@ private: struct EvalCommand : virtual StoreCommand, MixEvalArgs { - ref getEvalState(); - - std::shared_ptr evalState; + EvalCommand(); ~EvalCommand(); + + ref getEvalStore(); + + ref getEvalState(); + +private: + std::optional evalStoreUrl; + + std::shared_ptr evalStore; + + std::shared_ptr evalState; }; struct MixFlakeOptions : virtual Args, EvalCommand diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 95327f958..66ec63da2 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -289,19 +289,6 @@ void completeFlakeRefWithFragment( completeFlakeRef(evalState->store, prefix); } -ref EvalCommand::getEvalState() -{ - if (!evalState) - evalState = std::make_shared(searchPath, getStore()); - return ref(evalState); -} - -EvalCommand::~EvalCommand() -{ - if (evalState) - evalState->printStats(); -} - void completeFlakeRef(ref store, std::string_view prefix) { if (prefix == "") diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index c3206a577..b3e952aaa 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -378,7 +378,10 @@ static Strings parseNixPath(const string & s) } -EvalState::EvalState(const Strings & _searchPath, ref store) +EvalState::EvalState( + const Strings & _searchPath, + ref store, + std::shared_ptr buildStore) : sWith(symbols.create("")) , sOutPath(symbols.create("outPath")) , sDrvPath(symbols.create("drvPath")) @@ -411,6 +414,7 @@ EvalState::EvalState(const Strings & _searchPath, ref store) , sEpsilon(symbols.create("")) , repair(NoRepair) , store(store) + , buildStore(buildStore ? buildStore : store) , regexCache(makeRegexCache()) , baseEnv(allocEnv(128)) , staticBaseEnv(false, 0) diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index e3eaed6d3..a7aebb8ef 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -94,8 +94,12 @@ public: Value vEmptySet; + /* Store used to materialise .drv files. */ const ref store; + /* Store used to build stuff. */ + const ref buildStore; + private: SrcToStore srcToStore; @@ -128,7 +132,10 @@ private: public: - EvalState(const Strings & _searchPath, ref store); + EvalState( + const Strings & _searchPath, + ref store, + std::shared_ptr buildStore = nullptr); ~EvalState(); void addToSearchPath(const string & s);