mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
Merge pull request #13180 from Jaculabilis/reload-flakes
nix repl: remember :load-flake calls for :reload
This commit is contained in:
commit
addb9f8418
1 changed files with 24 additions and 4 deletions
|
@ -61,7 +61,10 @@ struct NixRepl
|
|||
{
|
||||
size_t debugTraceIndex;
|
||||
|
||||
// Arguments passed to :load, saved so they can be reloaded with :reload
|
||||
Strings loadedFiles;
|
||||
// Arguments passed to :load-flake, saved so they can be reloaded with :reload
|
||||
Strings loadedFlakes;
|
||||
std::function<AnnotatedValues()> getValues;
|
||||
|
||||
const static int envSize = 32768;
|
||||
|
@ -90,7 +93,8 @@ struct NixRepl
|
|||
void loadFile(const Path & path);
|
||||
void loadFlake(const std::string & flakeRef);
|
||||
void loadFiles();
|
||||
void reloadFiles();
|
||||
void loadFlakes();
|
||||
void reloadFilesAndFlakes();
|
||||
void addAttrsToScope(Value & attrs);
|
||||
void addVarToScope(const Symbol name, Value & v);
|
||||
Expr * parseString(std::string s);
|
||||
|
@ -466,7 +470,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
|
|||
|
||||
else if (command == ":r" || command == ":reload") {
|
||||
state->resetFileCache();
|
||||
reloadFiles();
|
||||
reloadFilesAndFlakes();
|
||||
}
|
||||
|
||||
else if (command == ":e" || command == ":edit") {
|
||||
|
@ -501,7 +505,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
|
|||
|
||||
// Reload right after exiting the editor
|
||||
state->resetFileCache();
|
||||
reloadFiles();
|
||||
reloadFilesAndFlakes();
|
||||
}
|
||||
|
||||
else if (command == ":t") {
|
||||
|
@ -716,6 +720,9 @@ void NixRepl::loadFlake(const std::string & flakeRefS)
|
|||
if (flakeRefS.empty())
|
||||
throw Error("cannot use ':load-flake' without a path specified. (Use '.' for the current working directory.)");
|
||||
|
||||
loadedFlakes.remove(flakeRefS);
|
||||
loadedFlakes.push_back(flakeRefS);
|
||||
|
||||
std::filesystem::path cwd;
|
||||
try {
|
||||
cwd = std::filesystem::current_path();
|
||||
|
@ -754,11 +761,12 @@ void NixRepl::initEnv()
|
|||
}
|
||||
|
||||
|
||||
void NixRepl::reloadFiles()
|
||||
void NixRepl::reloadFilesAndFlakes()
|
||||
{
|
||||
initEnv();
|
||||
|
||||
loadFiles();
|
||||
loadFlakes();
|
||||
}
|
||||
|
||||
|
||||
|
@ -779,6 +787,18 @@ void NixRepl::loadFiles()
|
|||
}
|
||||
|
||||
|
||||
void NixRepl::loadFlakes()
|
||||
{
|
||||
Strings old = loadedFlakes;
|
||||
loadedFlakes.clear();
|
||||
|
||||
for (auto & i : old) {
|
||||
notice("Loading flake '%1%'...", i);
|
||||
loadFlake(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NixRepl::addAttrsToScope(Value & attrs)
|
||||
{
|
||||
state->forceAttrs(attrs, [&]() { return attrs.determinePos(noPos); }, "while evaluating an attribute set to be merged in the global scope");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue