Add --override-input

This commit is contained in:
Andrea Bedini 2023-07-14 13:03:41 +08:00 committed by mergify[bot]
parent ab07651f74
commit 15e5f5f7c8

View file

@ -53,6 +53,14 @@ struct MyArgs : MixEvalArgs, MixCommonArgs {
size_t nrWorkers = 1; size_t nrWorkers = 1;
size_t maxMemorySize = 4096; size_t maxMemorySize = 4096;
// usually in MixFlakeOptions
flake::LockFlags lockFlags = {
.updateLockFile = false,
.writeLockFile = false,
.useRegistries = false,
.allowUnlocked = false
};
MyArgs() : MixCommonArgs("nix-eval-jobs") { MyArgs() : MixCommonArgs("nix-eval-jobs") {
addFlag({ addFlag({
.longName = "help", .longName = "help",
@ -125,6 +133,21 @@ struct MyArgs : MixEvalArgs, MixCommonArgs {
.description = "treat the argument as a Nix expression", .description = "treat the argument as a Nix expression",
.handler = {&fromArgs, true}}); .handler = {&fromArgs, true}});
// usually in MixFlakeOptions
addFlag({
.longName = "override-input",
.description = "Override a specific flake input (e.g. `dwarffs/nixpkgs`).",
.category = category,
.labels = {"input-path", "flake-url"},
.handler = {[&](std::string inputPath, std::string flakeRef) {
// overriden inputs are unlocked
lockFlags.allowUnlocked = true;
lockFlags.inputOverrides.insert_or_assign(
flake::parseInputPath(inputPath),
parseFlakeRef(flakeRef, absPath("."), true));
}},
});
expectArg("expr", &releaseExpr); expectArg("expr", &releaseExpr);
} }
}; };
@ -265,12 +288,8 @@ static void worker(ref<EvalState> state, Bindings &autoArgs, AutoCloseFD &to,
absPath(".")); absPath("."));
InstallableFlake flake { InstallableFlake flake {
{}, state, std::move(flakeRef), fragment, {}, state, std::move(flakeRef), fragment,
outputSpec, {}, {}, outputSpec, {}, {}, myArgs.lockFlags
flake::LockFlags{ };
.updateLockFile = false,
.useRegistries = false,
.allowUnlocked = false,
}};
return flake.toValue(*state).first; return flake.toValue(*state).first;
} else { } else {