libcmd/repl: track loaded flake references

Only successful loads counts towards the list of loaded flake
references.

Change-Id: I04128f90e57ef8352183d72dc6def7a09d52173a
Signed-off-by: Raito Bezarius <raito@lix.systems>
This commit is contained in:
Raito Bezarius
2026-01-07 16:28:30 +01:00
committed by Qyriad
parent 1ae5610a4e
commit 43434d675e
+24 -9
View File
@@ -137,6 +137,7 @@ struct NixRepl
size_t debugTraceIndex;
Strings loadedFiles;
Strings loadedFlakeRefs;
std::function<AnnotatedValues()> getValues;
std::map<std::string, std::shared_ptr<REPLCommand>> registeredCommands;
@@ -1289,15 +1290,29 @@ void NixRepl::loadFlake(const std::string & flakeRefS)
Value v;
flake::callFlake(state,
flake::lockFlake(state, flakeRef,
flake::LockFlags {
.updateLockFile = false,
.useRegistries = !evalSettings.pureEval,
.allowUnlocked = !evalSettings.pureEval,
}),
v);
addAttrsToScope(v);
try {
loadedFlakeRefs.remove(flakeRefS);
loadedFlakeRefs.push_back(flakeRefS);
flake::callFlake(
state,
flake::lockFlake(
state,
flakeRef,
flake::LockFlags{
.updateLockFile = false,
.useRegistries = !evalSettings.pureEval,
.allowUnlocked = !evalSettings.pureEval,
}
),
v
);
addAttrsToScope(v);
} catch (...) {
// In case of failure, do not keep the flake reference.
// Let the user re-load it again later.
loadedFlakeRefs.remove(flakeRefS);
throw;
}
}