mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-30 01:26:15 +02:00
Add a :load-flake
command to the nix repl
`:lf ref` does essentially the same thing as `:a (builtins.getFlake "ref")` (but cannonicalising `ref` if needs be, so that `:lf .` works) Fix #3803
This commit is contained in:
parent
58cb411db6
commit
765a3a20cb
1 changed files with 25 additions and 0 deletions
|
@ -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 the derivation in $EDITOR\n"
|
<< " :e <expr> Open the derivation 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