aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd/installables.cc
diff options
context:
space:
mode:
authorErik Arvstedt <erik.arvstedt@gmail.com>2022-03-26 11:32:38 +0100
committerErik Arvstedt <erik.arvstedt@gmail.com>2022-03-26 11:32:38 +0100
commit16860a0328094c04c3e877089119a56f9ddfbcd6 (patch)
tree1f3999b4263604737d27ed0b612ea2201d40696f /src/libcmd/installables.cc
parent679b3b32c952eed3c3be6c450c8189948e5645cd (diff)
nix eval: Add option `read-only`
Diffstat (limited to 'src/libcmd/installables.cc')
-rw-r--r--src/libcmd/installables.cc21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
index 2dc6c3ff8..e5d69ae14 100644
--- a/src/libcmd/installables.cc
+++ b/src/libcmd/installables.cc
@@ -1,3 +1,4 @@
+#include "globals.hh"
#include "installables.hh"
#include "command.hh"
#include "attr-path.hh"
@@ -129,7 +130,7 @@ MixFlakeOptions::MixFlakeOptions()
});
}
-SourceExprCommand::SourceExprCommand()
+SourceExprCommand::SourceExprCommand(bool supportReadOnlyMode)
{
addFlag({
.longName = "file",
@@ -157,6 +158,17 @@ SourceExprCommand::SourceExprCommand()
.category = installablesCategory,
.handler = {&operateOn, OperateOn::Derivation},
});
+
+ if (supportReadOnlyMode) {
+ addFlag({
+ .longName = "read-only",
+ .description =
+ "Do not instantiate each evaluated derivation. "
+ "This improves performance, but can cause errors when accessing "
+ "store paths of derivations during evaluation.",
+ .handler = {&readOnlyMode, true},
+ });
+ }
}
Strings SourceExprCommand::getDefaultFlakeAttrPaths()
@@ -687,6 +699,10 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
{
std::vector<std::shared_ptr<Installable>> result;
+ if (readOnlyMode) {
+ settings.readOnlyMode = true;
+ }
+
if (file || expr) {
if (file && expr)
throw UsageError("'--file' and '--expr' are exclusive");
@@ -951,7 +967,8 @@ std::optional<FlakeRef> InstallablesCommand::getFlakeRefForCompletion()
return parseFlakeRef(_installables.front(), absPath("."));
}
-InstallableCommand::InstallableCommand()
+InstallableCommand::InstallableCommand(bool supportReadOnlyMode)
+ : SourceExprCommand(supportReadOnlyMode)
{
expectArgs({
.label = "installable",