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) 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) void StorePathCommand::run(ref 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(); }); } -Buildables build(ref store, RealiseMode mode, +Buildables build(ref store, Realise mode, std::vector> installables); -std::set toStorePaths(ref store, RealiseMode mode, +std::set toStorePaths(ref store, Realise mode, std::vector> installables); -StorePath toStorePath(ref store, RealiseMode mode, +StorePath toStorePath(ref store, Realise mode, std::shared_ptr installable); std::set toDerivations(ref 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 SourceExprCommand::parseInstallable( return installables.front(); } -Buildables build(ref store, RealiseMode mode, +Buildables build(ref store, Realise mode, std::vector> installables) { - if (mode != Build) + if (mode == Realise::Nothing) settings.readOnlyMode = true; Buildables buildables; @@ -659,15 +659,15 @@ Buildables build(ref 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, RealiseMode mode, +StorePathSet toStorePaths(ref store, Realise mode, std::vector> installables) { StorePathSet outPaths; @@ -679,7 +679,7 @@ StorePathSet toStorePaths(ref store, RealiseMode mode, return outPaths; } -StorePath toStorePath(ref store, RealiseMode mode, +StorePath toStorePath(ref store, Realise mode, std::shared_ptr 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) 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) 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;