diff options
author | Ben Burdette <bburdette@protonmail.com> | 2022-04-15 14:49:08 -0600 |
---|---|---|
committer | Ben Burdette <bburdette@protonmail.com> | 2022-04-15 14:49:08 -0600 |
commit | 93b8d315087921b0a024bf87555ac6c3bca6882d (patch) | |
tree | 6d1215c6ed2840a71aee94bae892b1fd219bf17c /src/libcmd | |
parent | 8b197c492e4e2878eb58bb2994fb8d7f8044bf90 (diff) | |
parent | b135de2b5f08aa8b549d69371823235124ef04a1 (diff) |
Merge branch 'master' into debug-exploratory-PR
Diffstat (limited to 'src/libcmd')
-rw-r--r-- | src/libcmd/command.hh | 5 | ||||
-rw-r--r-- | src/libcmd/installables.cc | 23 |
2 files changed, 23 insertions, 5 deletions
diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh index 9247d401e..826531a18 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/command.hh @@ -87,11 +87,12 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions { std::optional<Path> file; std::optional<std::string> expr; + bool readOnlyMode = false; // FIXME: move this; not all commands (e.g. 'nix run') use it. OperateOn operateOn = OperateOn::Output; - SourceExprCommand(); + SourceExprCommand(bool supportReadOnlyMode = false); std::vector<std::shared_ptr<Installable>> parseInstallables( ref<Store> store, std::vector<std::string> ss); @@ -130,7 +131,7 @@ struct InstallableCommand : virtual Args, SourceExprCommand { std::shared_ptr<Installable> installable; - InstallableCommand(); + InstallableCommand(bool supportReadOnlyMode = false); void prepare() override; diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 955bbe6fb..4e7262432 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"); @@ -954,7 +970,7 @@ InstallablesCommand::InstallablesCommand() void InstallablesCommand::prepare() { if (_installables.empty() && useDefaultInstallables()) - // FIXME: commands like "nix install" should not have a + // FIXME: commands like "nix profile install" should not have a // default, probably. _installables.push_back("."); installables = parseInstallables(getStore(), _installables); @@ -970,7 +986,8 @@ std::optional<FlakeRef> InstallablesCommand::getFlakeRefForCompletion() return parseFlakeRef(_installables.front(), absPath(".")); } -InstallableCommand::InstallableCommand() +InstallableCommand::InstallableCommand(bool supportReadOnlyMode) + : SourceExprCommand(supportReadOnlyMode) { expectArgs({ .label = "installable", |