1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

Merge pull request #13180 from Jaculabilis/reload-flakes

nix repl: remember :load-flake calls for :reload
This commit is contained in:
Jörg Thalheim 2025-05-14 20:35:58 +02:00 committed by GitHub
commit addb9f8418
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -61,7 +61,10 @@ struct NixRepl
{ {
size_t debugTraceIndex; size_t debugTraceIndex;
// Arguments passed to :load, saved so they can be reloaded with :reload
Strings loadedFiles; Strings loadedFiles;
// Arguments passed to :load-flake, saved so they can be reloaded with :reload
Strings loadedFlakes;
std::function<AnnotatedValues()> getValues; std::function<AnnotatedValues()> getValues;
const static int envSize = 32768; const static int envSize = 32768;
@ -90,7 +93,8 @@ struct NixRepl
void loadFile(const Path & path); void loadFile(const Path & path);
void loadFlake(const std::string & flakeRef); void loadFlake(const std::string & flakeRef);
void loadFiles(); void loadFiles();
void reloadFiles(); void loadFlakes();
void reloadFilesAndFlakes();
void addAttrsToScope(Value & attrs); void addAttrsToScope(Value & attrs);
void addVarToScope(const Symbol name, Value & v); void addVarToScope(const Symbol name, Value & v);
Expr * parseString(std::string s); Expr * parseString(std::string s);
@ -466,7 +470,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
else if (command == ":r" || command == ":reload") { else if (command == ":r" || command == ":reload") {
state->resetFileCache(); state->resetFileCache();
reloadFiles(); reloadFilesAndFlakes();
} }
else if (command == ":e" || command == ":edit") { else if (command == ":e" || command == ":edit") {
@ -501,7 +505,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
// Reload right after exiting the editor // Reload right after exiting the editor
state->resetFileCache(); state->resetFileCache();
reloadFiles(); reloadFilesAndFlakes();
} }
else if (command == ":t") { else if (command == ":t") {
@ -716,6 +720,9 @@ void NixRepl::loadFlake(const std::string & flakeRefS)
if (flakeRefS.empty()) if (flakeRefS.empty())
throw Error("cannot use ':load-flake' without a path specified. (Use '.' for the current working directory.)"); 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; std::filesystem::path cwd;
try { try {
cwd = std::filesystem::current_path(); cwd = std::filesystem::current_path();
@ -754,11 +761,12 @@ void NixRepl::initEnv()
} }
void NixRepl::reloadFiles() void NixRepl::reloadFilesAndFlakes()
{ {
initEnv(); initEnv();
loadFiles(); 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) void NixRepl::addAttrsToScope(Value & attrs)
{ {
state->forceAttrs(attrs, [&]() { return attrs.determinePos(noPos); }, "while evaluating an attribute set to be merged in the global scope"); state->forceAttrs(attrs, [&]() { return attrs.determinePos(noPos); }, "while evaluating an attribute set to be merged in the global scope");