mirror of
https://github.com/NixOS/nix
synced 2025-06-25 19:01:16 +02:00
nix repl: remember :load-flake calls for :reload
Fixes #8753
(cherry picked from commit fb510a9e50
)
This commit is contained in:
parent
c0cef69790
commit
0acb13b7fe
1 changed files with 24 additions and 4 deletions
|
@ -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");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue