nix: Support the --repair flag

This commit is contained in:
Eelco Dolstra 2023-04-28 16:57:37 +02:00
parent 89d3cc5a47
commit 17e6b85d05
7 changed files with 28 additions and 17 deletions

View file

@ -121,6 +121,8 @@ ref<EvalState> EvalCommand::getEvalState()
#endif
;
evalState->repair = repair;
if (startReplOnEvalErrors) {
evalState->debugRepl = &AbstractNixRepl::runSimple;
};

View file

@ -2,6 +2,7 @@
///@file
#include "args.hh"
#include "common-args.hh"
namespace nix {
@ -10,7 +11,7 @@ class EvalState;
class Bindings;
struct SourcePath;
struct MixEvalArgs : virtual Args
struct MixEvalArgs : virtual Args, virtual MixRepair
{
static constexpr auto category = "Common evaluation options";

View file

@ -2,6 +2,7 @@
///@file
#include "args.hh"
#include "repair-flag.hh"
namespace nix {
@ -49,4 +50,21 @@ struct MixJSON : virtual Args
}
};
struct MixRepair : virtual Args
{
RepairFlag repair = NoRepair;
MixRepair()
{
addFlag({
.longName = "repair",
.description =
"During evaluation, rewrite missing or corrupted files in the Nix store. "
"During building, rebuild missing or corrupted store paths.",
.category = miscCategory,
.handler = {&repair, Repair},
});
}
};
}

View file

@ -84,7 +84,6 @@ static void main_nix_build(int argc, char * * argv)
auto interactive = isatty(STDIN_FILENO) && isatty(STDERR_FILENO);
Strings attrPaths;
Strings left;
RepairFlag repair = NoRepair;
BuildMode buildMode = bmNormal;
bool readStdin = false;
@ -169,11 +168,6 @@ static void main_nix_build(int argc, char * * argv)
else if (*arg == "--dry-run")
dryRun = true;
else if (*arg == "--repair") {
repair = Repair;
buildMode = bmRepair;
}
else if (*arg == "--run-env") // obsolete
runEnv = true;
@ -249,7 +243,8 @@ static void main_nix_build(int argc, char * * argv)
auto evalStore = myArgs.evalStoreUrl ? openStore(*myArgs.evalStoreUrl) : store;
auto state = std::make_unique<EvalState>(myArgs.searchPath, evalStore, store);
state->repair = repair;
state->repair = myArgs.repair;
if (myArgs.repair) buildMode = bmRepair;
auto autoArgs = myArgs.getAutoArgs(*state);

View file

@ -1391,7 +1391,6 @@ static int main_nix_env(int argc, char * * argv)
Operation op = 0;
std::string opName;
bool showHelp = false;
RepairFlag repair = NoRepair;
std::string file;
Globals globals;
@ -1489,8 +1488,6 @@ static int main_nix_env(int argc, char * * argv)
globals.instSource.systemFilter = getArg(*arg, arg, end);
else if (*arg == "--prebuilt-only" || *arg == "-b")
globals.prebuiltOnly = true;
else if (*arg == "--repair")
repair = Repair;
else if (*arg != "" && arg->at(0) == '-') {
opFlags.push_back(*arg);
/* FIXME: hacky */
@ -1515,7 +1512,7 @@ static int main_nix_env(int argc, char * * argv)
auto store = openStore();
globals.state = std::shared_ptr<EvalState>(new EvalState(myArgs.searchPath, store));
globals.state->repair = repair;
globals.state->repair = myArgs.repair;
globals.instSource.nixExprPath = std::make_shared<SourcePath>(
file != ""

View file

@ -102,7 +102,6 @@ static int main_nix_instantiate(int argc, char * * argv)
bool strict = false;
Strings attrPaths;
bool wantsReadWrite = false;
RepairFlag repair = NoRepair;
struct MyArgs : LegacyArgs, MixEvalArgs
{
@ -140,8 +139,6 @@ static int main_nix_instantiate(int argc, char * * argv)
xmlOutputSourceLocation = false;
else if (*arg == "--strict")
strict = true;
else if (*arg == "--repair")
repair = Repair;
else if (*arg == "--dry-run")
settings.readOnlyMode = true;
else if (*arg != "" && arg->at(0) == '-')
@ -160,7 +157,7 @@ static int main_nix_instantiate(int argc, char * * argv)
auto evalStore = myArgs.evalStoreUrl ? openStore(*myArgs.evalStoreUrl) : store;
auto state = std::make_unique<EvalState>(myArgs.searchPath, evalStore, store);
state->repair = repair;
state->repair = myArgs.repair;
Bindings & autoArgs = *myArgs.getAutoArgs(*state);

View file

@ -133,7 +133,8 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
auto buildables = Installable::build(
getEvalStore(), store,
Realise::Outputs,
installables, buildMode);
installables,
repair ? bmRepair : buildMode);
if (json) logger->cout("%s", builtPathsWithResultToJSON(buildables, store).dump());