diff --git a/lix/libcmd/repl.cc b/lix/libcmd/repl.cc index a9c059c37..8a4547e34 100644 --- a/lix/libcmd/repl.cc +++ b/lix/libcmd/repl.cc @@ -1092,43 +1092,30 @@ Value * NixRepl::evalFile(SourcePath & path) return result; } - -std::unique_ptr AbstractNixRepl::create( - const SearchPath & searchPath, nix::ref store, ref state, - std::function getValues) +ReplExitStatus AbstractNixRepl::run( + const SearchPath & searchPath, + nix::ref store, + ref state, + std::function getValues, + const ValMap & extraEnv, + Bindings * autoArgs +) { - return std::make_unique( - searchPath, - openStore(), - state, - getValues + NixRepl repl(searchPath, store, state, getValues); + + repl.autoArgs = autoArgs; + repl.initEnv(); + for (auto & [name, value] : extraEnv) { + repl.addVarToScope(repl.state->symbols.create(name), *value); + } + return repl.mainLoop(); +} + +ReplExitStatus AbstractNixRepl::runSimple(ref evalState, const ValMap & extraEnv) +{ + return run( + {}, openStore(), evalState, [] { return AnnotatedValues{}; }, extraEnv, nullptr ); } - -ReplExitStatus AbstractNixRepl::runSimple( - ref evalState, - const ValMap & extraEnv) -{ - auto getValues = [&]()->NixRepl::AnnotatedValues{ - NixRepl::AnnotatedValues values; - return values; - }; - SearchPath searchPath = {}; - auto repl = std::make_unique( - searchPath, - openStore(), - evalState, - getValues - ); - - repl->initEnv(); - - // add 'extra' vars. - for (auto & [name, value] : extraEnv) - repl->addVarToScope(repl->state->symbols.create(name), *value); - - return repl->mainLoop(); -} - } diff --git a/lix/libcmd/repl.hh b/lix/libcmd/repl.hh index fba582930..12b3198a2 100644 --- a/lix/libcmd/repl.hh +++ b/lix/libcmd/repl.hh @@ -7,6 +7,21 @@ namespace nix { struct AbstractNixRepl { + typedef std::vector> AnnotatedValues; + + static ReplExitStatus + run(const SearchPath & searchPath, + nix::ref store, + ref state, + std::function getValues, + const ValMap & extraEnv, + Bindings * autoArgs); + + static ReplExitStatus runSimple( + ref evalState, + const ValMap & extraEnv); + +protected: ref state; Bindings * autoArgs; @@ -14,19 +29,6 @@ struct AbstractNixRepl : state(state) { } - virtual ~AbstractNixRepl() - { } - - typedef std::vector> AnnotatedValues; - - static std::unique_ptr create( - const SearchPath & searchPath, nix::ref store, ref state, - std::function getValues); - - static ReplExitStatus runSimple( - ref evalState, - const ValMap & extraEnv); - virtual void initEnv() = 0; virtual ReplExitStatus mainLoop() = 0; diff --git a/lix/nix/repl.cc b/lix/nix/repl.cc index b74d01c49..186c10b51 100644 --- a/lix/nix/repl.cc +++ b/lix/nix/repl.cc @@ -86,15 +86,7 @@ struct CmdRepl : RawInstallablesCommand } return values; }; - auto repl = AbstractNixRepl::create( - searchPath, - openStore(), - state, - getValues - ); - repl->autoArgs = getAutoArgs(*repl->state); - repl->initEnv(); - repl->mainLoop(); + AbstractNixRepl::run(searchPath, openStore(), state, getValues, {}, getAutoArgs(*state)); } };