aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-07-15 20:05:42 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-07-15 20:05:42 +0200
commit94eb5fad76cd086e3f49329532f81083726f89b3 (patch)
treec1e8f7b3a623a0bb083b6c7facab2a9135bffbc9
parente3c2b0023774eed05657ca1dbb469a85bd294d23 (diff)
Clean up RealiseMode
-rw-r--r--src/nix/build.cc2
-rw-r--r--src/nix/command.cc2
-rw-r--r--src/nix/command.hh19
-rw-r--r--src/nix/copy.cc2
-rw-r--r--src/nix/develop.cc2
-rw-r--r--src/nix/installables.cc12
-rw-r--r--src/nix/make-content-addressable.cc2
-rw-r--r--src/nix/run.cc2
-rw-r--r--src/nix/why-depends.cc4
9 files changed, 28 insertions, 19 deletions
diff --git a/src/nix/build.cc b/src/nix/build.cc
index 474337208..0f7e0e123 100644
--- a/src/nix/build.cc
+++ b/src/nix/build.cc
@@ -53,7 +53,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixProfile
void run(ref<Store> store) override
{
- auto buildables = build(store, dryRun ? DryRun : Build, installables);
+ auto buildables = build(store, dryRun ? Realise::Nothing : Realise::Outputs, installables);
if (dryRun) return;
diff --git a/src/nix/command.cc b/src/nix/command.cc
index dbf5e0988..a4faccb6d 100644
--- a/src/nix/command.cc
+++ b/src/nix/command.cc
@@ -80,7 +80,7 @@ void StorePathsCommand::run(ref<Store> store)
void StorePathCommand::run(ref<Store> store)
{
- auto storePaths = toStorePaths(store, NoBuild, installables);
+ auto storePaths = toStorePaths(store, Realise::Nothing, installables);
if (storePaths.size() != 1)
throw UsageError("this command requires exactly one store path");
diff --git a/src/nix/command.hh b/src/nix/command.hh
index a8779b0e6..5fa8f9333 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -70,7 +70,16 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions
void completeInstallable(std::string_view prefix);
};
-enum RealiseMode { Build, NoBuild, DryRun };
+enum class Realise {
+ /* Build the derivation. Postcondition: the
+ derivation outputs exist. */
+ Outputs,
+ /* Don't build the derivation. Postcondition: the store derivation
+ exists. */
+ Derivation,
+ /* Evaluate in dry-run mode. Postcondition: nothing. */
+ Nothing
+};
/* A command that operates on a list of "installables", which can be
store paths, attribute paths, Nix expressions, etc. */
@@ -120,7 +129,7 @@ private:
protected:
- RealiseMode realiseMode = NoBuild;
+ Realise realiseMode = Realise::Derivation;
public:
@@ -164,13 +173,13 @@ static RegisterCommand registerCommand(const std::string & name)
return RegisterCommand(name, [](){ return make_ref<T>(); });
}
-Buildables build(ref<Store> store, RealiseMode mode,
+Buildables build(ref<Store> store, Realise mode,
std::vector<std::shared_ptr<Installable>> installables);
-std::set<StorePath> toStorePaths(ref<Store> store, RealiseMode mode,
+std::set<StorePath> toStorePaths(ref<Store> store, Realise mode,
std::vector<std::shared_ptr<Installable>> installables);
-StorePath toStorePath(ref<Store> store, RealiseMode mode,
+StorePath toStorePath(ref<Store> store, Realise mode,
std::shared_ptr<Installable> installable);
std::set<StorePath> toDerivations(ref<Store> store,
diff --git a/src/nix/copy.cc b/src/nix/copy.cc
index 815e653b0..5281ff5ee 100644
--- a/src/nix/copy.cc
+++ b/src/nix/copy.cc
@@ -46,7 +46,7 @@ struct CmdCopy : StorePathsCommand
.handler = {&substitute, Substitute},
});
- realiseMode = Build;
+ realiseMode = Realise::Outputs;
}
std::string description() override
diff --git a/src/nix/develop.cc b/src/nix/develop.cc
index 171eeeb3c..bf4890e95 100644
--- a/src/nix/develop.cc
+++ b/src/nix/develop.cc
@@ -321,7 +321,7 @@ struct CmdDevelop : Common, MixEnvironment
Strings{"legacyPackages." + settings.thisSystem.get() + "."},
lockFlags);
- shell = state->store->printStorePath(toStorePath(state->store, Build, bashInstallable)) + "/bin/bash";
+ shell = state->store->printStorePath(toStorePath(state->store, Realise::Outputs, bashInstallable)) + "/bin/bash";
} catch (Error &) {
ignoreException();
}
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 415358970..d464efc35 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -635,10 +635,10 @@ std::shared_ptr<Installable> SourceExprCommand::parseInstallable(
return installables.front();
}
-Buildables build(ref<Store> store, RealiseMode mode,
+Buildables build(ref<Store> store, Realise mode,
std::vector<std::shared_ptr<Installable>> installables)
{
- if (mode != Build)
+ if (mode == Realise::Nothing)
settings.readOnlyMode = true;
Buildables buildables;
@@ -659,15 +659,15 @@ Buildables build(ref<Store> store, RealiseMode mode,
}
}
- if (mode == DryRun)
+ if (mode == Realise::Nothing)
printMissing(store, pathsToBuild, lvlError);
- else if (mode == Build)
+ else if (mode == Realise::Outputs)
store->buildPaths(pathsToBuild);
return buildables;
}
-StorePathSet toStorePaths(ref<Store> store, RealiseMode mode,
+StorePathSet toStorePaths(ref<Store> store, Realise mode,
std::vector<std::shared_ptr<Installable>> installables)
{
StorePathSet outPaths;
@@ -679,7 +679,7 @@ StorePathSet toStorePaths(ref<Store> store, RealiseMode mode,
return outPaths;
}
-StorePath toStorePath(ref<Store> store, RealiseMode mode,
+StorePath toStorePath(ref<Store> store, Realise mode,
std::shared_ptr<Installable> installable)
{
auto paths = toStorePaths(store, mode, {installable});
diff --git a/src/nix/make-content-addressable.cc b/src/nix/make-content-addressable.cc
index fb36fc410..b2ded35dd 100644
--- a/src/nix/make-content-addressable.cc
+++ b/src/nix/make-content-addressable.cc
@@ -10,7 +10,7 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
{
CmdMakeContentAddressable()
{
- realiseMode = Build;
+ realiseMode = Realise::Outputs;
}
std::string description() override
diff --git a/src/nix/run.cc b/src/nix/run.cc
index 59a6c7252..a27538085 100644
--- a/src/nix/run.cc
+++ b/src/nix/run.cc
@@ -104,7 +104,7 @@ struct CmdShell : InstallablesCommand, RunCommon, MixEnvironment
void run(ref<Store> store) override
{
- auto outPaths = toStorePaths(store, Build, installables);
+ auto outPaths = toStorePaths(store, Realise::Outputs, installables);
auto accessor = store->getFSAccessor();
diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc
index a208e0081..c39a0435d 100644
--- a/src/nix/why-depends.cc
+++ b/src/nix/why-depends.cc
@@ -73,9 +73,9 @@ struct CmdWhyDepends : SourceExprCommand
void run(ref<Store> store) override
{
auto package = parseInstallable(store, _package);
- auto packagePath = toStorePath(store, Build, package);
+ auto packagePath = toStorePath(store, Realise::Outputs, package);
auto dependency = parseInstallable(store, _dependency);
- auto dependencyPath = toStorePath(store, NoBuild, dependency);
+ auto dependencyPath = toStorePath(store, Realise::Derivation, dependency);
auto dependencyPathHash = dependencyPath.hashPart();
StorePathSet closure;