nix: Support the --repair flag
This commit is contained in:
parent
89d3cc5a47
commit
17e6b85d05
7 changed files with 28 additions and 17 deletions
|
@ -121,6 +121,8 @@ ref<EvalState> EvalCommand::getEvalState()
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
|
evalState->repair = repair;
|
||||||
|
|
||||||
if (startReplOnEvalErrors) {
|
if (startReplOnEvalErrors) {
|
||||||
evalState->debugRepl = &AbstractNixRepl::runSimple;
|
evalState->debugRepl = &AbstractNixRepl::runSimple;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
///@file
|
///@file
|
||||||
|
|
||||||
#include "args.hh"
|
#include "args.hh"
|
||||||
|
#include "common-args.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
@ -10,7 +11,7 @@ class EvalState;
|
||||||
class Bindings;
|
class Bindings;
|
||||||
struct SourcePath;
|
struct SourcePath;
|
||||||
|
|
||||||
struct MixEvalArgs : virtual Args
|
struct MixEvalArgs : virtual Args, virtual MixRepair
|
||||||
{
|
{
|
||||||
static constexpr auto category = "Common evaluation options";
|
static constexpr auto category = "Common evaluation options";
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
///@file
|
///@file
|
||||||
|
|
||||||
#include "args.hh"
|
#include "args.hh"
|
||||||
|
#include "repair-flag.hh"
|
||||||
|
|
||||||
namespace nix {
|
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},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,6 @@ static void main_nix_build(int argc, char * * argv)
|
||||||
auto interactive = isatty(STDIN_FILENO) && isatty(STDERR_FILENO);
|
auto interactive = isatty(STDIN_FILENO) && isatty(STDERR_FILENO);
|
||||||
Strings attrPaths;
|
Strings attrPaths;
|
||||||
Strings left;
|
Strings left;
|
||||||
RepairFlag repair = NoRepair;
|
|
||||||
BuildMode buildMode = bmNormal;
|
BuildMode buildMode = bmNormal;
|
||||||
bool readStdin = false;
|
bool readStdin = false;
|
||||||
|
|
||||||
|
@ -169,11 +168,6 @@ static void main_nix_build(int argc, char * * argv)
|
||||||
else if (*arg == "--dry-run")
|
else if (*arg == "--dry-run")
|
||||||
dryRun = true;
|
dryRun = true;
|
||||||
|
|
||||||
else if (*arg == "--repair") {
|
|
||||||
repair = Repair;
|
|
||||||
buildMode = bmRepair;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (*arg == "--run-env") // obsolete
|
else if (*arg == "--run-env") // obsolete
|
||||||
runEnv = true;
|
runEnv = true;
|
||||||
|
|
||||||
|
@ -249,7 +243,8 @@ static void main_nix_build(int argc, char * * argv)
|
||||||
auto evalStore = myArgs.evalStoreUrl ? openStore(*myArgs.evalStoreUrl) : store;
|
auto evalStore = myArgs.evalStoreUrl ? openStore(*myArgs.evalStoreUrl) : store;
|
||||||
|
|
||||||
auto state = std::make_unique<EvalState>(myArgs.searchPath, evalStore, 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);
|
auto autoArgs = myArgs.getAutoArgs(*state);
|
||||||
|
|
||||||
|
|
|
@ -1391,7 +1391,6 @@ static int main_nix_env(int argc, char * * argv)
|
||||||
Operation op = 0;
|
Operation op = 0;
|
||||||
std::string opName;
|
std::string opName;
|
||||||
bool showHelp = false;
|
bool showHelp = false;
|
||||||
RepairFlag repair = NoRepair;
|
|
||||||
std::string file;
|
std::string file;
|
||||||
|
|
||||||
Globals globals;
|
Globals globals;
|
||||||
|
@ -1489,8 +1488,6 @@ static int main_nix_env(int argc, char * * argv)
|
||||||
globals.instSource.systemFilter = getArg(*arg, arg, end);
|
globals.instSource.systemFilter = getArg(*arg, arg, end);
|
||||||
else if (*arg == "--prebuilt-only" || *arg == "-b")
|
else if (*arg == "--prebuilt-only" || *arg == "-b")
|
||||||
globals.prebuiltOnly = true;
|
globals.prebuiltOnly = true;
|
||||||
else if (*arg == "--repair")
|
|
||||||
repair = Repair;
|
|
||||||
else if (*arg != "" && arg->at(0) == '-') {
|
else if (*arg != "" && arg->at(0) == '-') {
|
||||||
opFlags.push_back(*arg);
|
opFlags.push_back(*arg);
|
||||||
/* FIXME: hacky */
|
/* FIXME: hacky */
|
||||||
|
@ -1515,7 +1512,7 @@ static int main_nix_env(int argc, char * * argv)
|
||||||
auto store = openStore();
|
auto store = openStore();
|
||||||
|
|
||||||
globals.state = std::shared_ptr<EvalState>(new EvalState(myArgs.searchPath, store));
|
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>(
|
globals.instSource.nixExprPath = std::make_shared<SourcePath>(
|
||||||
file != ""
|
file != ""
|
||||||
|
|
|
@ -102,7 +102,6 @@ static int main_nix_instantiate(int argc, char * * argv)
|
||||||
bool strict = false;
|
bool strict = false;
|
||||||
Strings attrPaths;
|
Strings attrPaths;
|
||||||
bool wantsReadWrite = false;
|
bool wantsReadWrite = false;
|
||||||
RepairFlag repair = NoRepair;
|
|
||||||
|
|
||||||
struct MyArgs : LegacyArgs, MixEvalArgs
|
struct MyArgs : LegacyArgs, MixEvalArgs
|
||||||
{
|
{
|
||||||
|
@ -140,8 +139,6 @@ static int main_nix_instantiate(int argc, char * * argv)
|
||||||
xmlOutputSourceLocation = false;
|
xmlOutputSourceLocation = false;
|
||||||
else if (*arg == "--strict")
|
else if (*arg == "--strict")
|
||||||
strict = true;
|
strict = true;
|
||||||
else if (*arg == "--repair")
|
|
||||||
repair = Repair;
|
|
||||||
else if (*arg == "--dry-run")
|
else if (*arg == "--dry-run")
|
||||||
settings.readOnlyMode = true;
|
settings.readOnlyMode = true;
|
||||||
else if (*arg != "" && arg->at(0) == '-')
|
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 evalStore = myArgs.evalStoreUrl ? openStore(*myArgs.evalStoreUrl) : store;
|
||||||
|
|
||||||
auto state = std::make_unique<EvalState>(myArgs.searchPath, evalStore, store);
|
auto state = std::make_unique<EvalState>(myArgs.searchPath, evalStore, store);
|
||||||
state->repair = repair;
|
state->repair = myArgs.repair;
|
||||||
|
|
||||||
Bindings & autoArgs = *myArgs.getAutoArgs(*state);
|
Bindings & autoArgs = *myArgs.getAutoArgs(*state);
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,8 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
|
||||||
auto buildables = Installable::build(
|
auto buildables = Installable::build(
|
||||||
getEvalStore(), store,
|
getEvalStore(), store,
|
||||||
Realise::Outputs,
|
Realise::Outputs,
|
||||||
installables, buildMode);
|
installables,
|
||||||
|
repair ? bmRepair : buildMode);
|
||||||
|
|
||||||
if (json) logger->cout("%s", builtPathsWithResultToJSON(buildables, store).dump());
|
if (json) logger->cout("%s", builtPathsWithResultToJSON(buildables, store).dump());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue