forked from lix-project/lix
Merge remote-tracking branch 'origin/repl-flake-support'
This commit is contained in:
commit
c5fafca5a4
|
@ -68,6 +68,7 @@ struct NixRepl
|
||||||
StorePath getDerivationPath(Value & v);
|
StorePath getDerivationPath(Value & v);
|
||||||
bool processLine(string line);
|
bool processLine(string line);
|
||||||
void loadFile(const Path & path);
|
void loadFile(const Path & path);
|
||||||
|
void loadFlake(const std::string & flakeRef);
|
||||||
void initEnv();
|
void initEnv();
|
||||||
void reloadFiles();
|
void reloadFiles();
|
||||||
void addAttrsToScope(Value & attrs);
|
void addAttrsToScope(Value & attrs);
|
||||||
|
@ -415,6 +416,7 @@ bool NixRepl::processLine(string line)
|
||||||
<< " :e <expr> Open package or function in $EDITOR\n"
|
<< " :e <expr> Open package or function in $EDITOR\n"
|
||||||
<< " :i <expr> Build derivation, then install result into current profile\n"
|
<< " :i <expr> Build derivation, then install result into current profile\n"
|
||||||
<< " :l <path> Load Nix expression and add it to scope\n"
|
<< " :l <path> Load Nix expression and add it to scope\n"
|
||||||
|
<< " :lf <ref> Load Nix flake and add it to scope\n"
|
||||||
<< " :p <expr> Evaluate and print expression recursively\n"
|
<< " :p <expr> Evaluate and print expression recursively\n"
|
||||||
<< " :q Exit nix-repl\n"
|
<< " :q Exit nix-repl\n"
|
||||||
<< " :r Reload all files\n"
|
<< " :r Reload all files\n"
|
||||||
|
@ -435,6 +437,10 @@ bool NixRepl::processLine(string line)
|
||||||
loadFile(arg);
|
loadFile(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (command == ":lf" || command == ":load-flake") {
|
||||||
|
loadFlake(arg);
|
||||||
|
}
|
||||||
|
|
||||||
else if (command == ":r" || command == ":reload") {
|
else if (command == ":r" || command == ":reload") {
|
||||||
state->resetFileCache();
|
state->resetFileCache();
|
||||||
reloadFiles();
|
reloadFiles();
|
||||||
|
@ -576,6 +582,25 @@ void NixRepl::loadFile(const Path & path)
|
||||||
addAttrsToScope(v2);
|
addAttrsToScope(v2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NixRepl::loadFlake(const std::string & flakeRefS)
|
||||||
|
{
|
||||||
|
auto flakeRef = parseFlakeRef(flakeRefS, absPath("."), true);
|
||||||
|
if (evalSettings.pureEval && !flakeRef.input.isImmutable())
|
||||||
|
throw Error("cannot use ':load-flake' on mutable flake reference '%s' (use --impure to override)", flakeRefS);
|
||||||
|
|
||||||
|
Value v;
|
||||||
|
|
||||||
|
flake::callFlake(*state,
|
||||||
|
flake::lockFlake(*state, flakeRef,
|
||||||
|
flake::LockFlags {
|
||||||
|
.updateLockFile = false,
|
||||||
|
.useRegistries = !evalSettings.pureEval,
|
||||||
|
.allowMutable = !evalSettings.pureEval,
|
||||||
|
}),
|
||||||
|
v);
|
||||||
|
addAttrsToScope(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void NixRepl::initEnv()
|
void NixRepl::initEnv()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue