From 15e5f5f7c8d7fd054813ed112ea5d6b267b860bc Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Fri, 14 Jul 2023 13:03:41 +0800 Subject: [PATCH] Add --override-input --- src/nix-eval-jobs.cc | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/nix-eval-jobs.cc b/src/nix-eval-jobs.cc index 72f784d..8f8b00a 100644 --- a/src/nix-eval-jobs.cc +++ b/src/nix-eval-jobs.cc @@ -53,6 +53,14 @@ struct MyArgs : MixEvalArgs, MixCommonArgs { size_t nrWorkers = 1; size_t maxMemorySize = 4096; + // usually in MixFlakeOptions + flake::LockFlags lockFlags = { + .updateLockFile = false, + .writeLockFile = false, + .useRegistries = false, + .allowUnlocked = false + }; + MyArgs() : MixCommonArgs("nix-eval-jobs") { addFlag({ .longName = "help", @@ -125,6 +133,21 @@ struct MyArgs : MixEvalArgs, MixCommonArgs { .description = "treat the argument as a Nix expression", .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); } }; @@ -265,12 +288,8 @@ static void worker(ref state, Bindings &autoArgs, AutoCloseFD &to, absPath(".")); InstallableFlake flake { {}, state, std::move(flakeRef), fragment, - outputSpec, {}, {}, - flake::LockFlags{ - .updateLockFile = false, - .useRegistries = false, - .allowUnlocked = false, - }}; + outputSpec, {}, {}, myArgs.lockFlags + }; return flake.toValue(*state).first; } else {