aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2020-06-29 10:05:44 +0200
committerMaximilian Bosch <maximilian@mbosch.me>2020-07-31 17:17:03 +0200
commit5a09eb86f17b7949b93724ecb51f1b909ea68592 (patch)
tree246a7ac2bbcfc0d663361901ef6bb8a92050813e
parent17f75f9cc4dd70e3e6de7e266ef2bd18a0da310b (diff)
nix/build: add `--rebuild` option
Occasionally, `nix-build --check` is fairly helpful and I'd like to be able to use this feature for flakes that need to be built with `nix build` as well.
-rw-r--r--src/nix/build.cc9
-rw-r--r--src/nix/command.hh3
-rw-r--r--src/nix/installables.cc4
3 files changed, 12 insertions, 4 deletions
diff --git a/src/nix/build.cc b/src/nix/build.cc
index 0f7e0e123..bec25d8d8 100644
--- a/src/nix/build.cc
+++ b/src/nix/build.cc
@@ -9,6 +9,7 @@ using namespace nix;
struct CmdBuild : InstallablesCommand, MixDryRun, MixProfile
{
Path outLink = "result";
+ BuildMode buildMode = bmNormal;
CmdBuild()
{
@@ -26,6 +27,12 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixProfile
.description = "do not create a symlink to the build result",
.handler = {&outLink, Path("")},
});
+
+ addFlag({
+ .longName = "rebuild",
+ .description = "Rebuild an already built package locally and compare the result to the existing store-paths.",
+ .handler = {&buildMode, bmCheck},
+ });
}
std::string description() override
@@ -53,7 +60,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixProfile
void run(ref<Store> store) override
{
- auto buildables = build(store, dryRun ? Realise::Nothing : Realise::Outputs, installables);
+ auto buildables = build(store, dryRun ? Realise::Nothing : Realise::Outputs, installables, buildMode);
if (dryRun) return;
diff --git a/src/nix/command.hh b/src/nix/command.hh
index 856721ebf..bc46a2028 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -5,6 +5,7 @@
#include "common-eval-args.hh"
#include "path.hh"
#include "flake/lockfile.hh"
+#include "store-api.hh"
#include <optional>
@@ -185,7 +186,7 @@ static RegisterCommand registerCommand(const std::string & name)
}
Buildables build(ref<Store> store, Realise mode,
- std::vector<std::shared_ptr<Installable>> installables);
+ std::vector<std::shared_ptr<Installable>> installables, BuildMode bMode = bmNormal);
std::set<StorePath> toStorePaths(ref<Store> store,
Realise mode, OperateOn operateOn,
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index a13e5a3df..56c62dbfe 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -642,7 +642,7 @@ std::shared_ptr<Installable> SourceExprCommand::parseInstallable(
}
Buildables build(ref<Store> store, Realise mode,
- std::vector<std::shared_ptr<Installable>> installables)
+ std::vector<std::shared_ptr<Installable>> installables, BuildMode bMode)
{
if (mode == Realise::Nothing)
settings.readOnlyMode = true;
@@ -668,7 +668,7 @@ Buildables build(ref<Store> store, Realise mode,
if (mode == Realise::Nothing)
printMissing(store, pathsToBuild, lvlError);
else if (mode == Realise::Outputs)
- store->buildPaths(pathsToBuild);
+ store->buildPaths(pathsToBuild, bMode);
return buildables;
}