forked from lix-project/lix
Merge pull request #7755 from obsidiansystems/mix-read-only-mode
Make `--read-only` a separate mixin
This commit is contained in:
commit
c7885ab6f2
|
@ -94,9 +94,8 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions
|
||||||
{
|
{
|
||||||
std::optional<Path> file;
|
std::optional<Path> file;
|
||||||
std::optional<std::string> expr;
|
std::optional<std::string> expr;
|
||||||
bool readOnlyMode = false;
|
|
||||||
|
|
||||||
SourceExprCommand(bool supportReadOnlyMode = false);
|
SourceExprCommand();
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Installable>> parseInstallables(
|
std::vector<std::shared_ptr<Installable>> parseInstallables(
|
||||||
ref<Store> store, std::vector<std::string> ss);
|
ref<Store> store, std::vector<std::string> ss);
|
||||||
|
@ -111,6 +110,11 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions
|
||||||
void completeInstallable(std::string_view prefix);
|
void completeInstallable(std::string_view prefix);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct MixReadOnlyOption : virtual Args
|
||||||
|
{
|
||||||
|
MixReadOnlyOption();
|
||||||
|
};
|
||||||
|
|
||||||
/* A command that operates on a list of "installables", which can be
|
/* A command that operates on a list of "installables", which can be
|
||||||
store paths, attribute paths, Nix expressions, etc. */
|
store paths, attribute paths, Nix expressions, etc. */
|
||||||
struct InstallablesCommand : virtual Args, SourceExprCommand
|
struct InstallablesCommand : virtual Args, SourceExprCommand
|
||||||
|
@ -136,7 +140,7 @@ struct InstallableCommand : virtual Args, SourceExprCommand
|
||||||
{
|
{
|
||||||
std::shared_ptr<Installable> installable;
|
std::shared_ptr<Installable> installable;
|
||||||
|
|
||||||
InstallableCommand(bool supportReadOnlyMode = false);
|
InstallableCommand();
|
||||||
|
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ void MixFlakeOptions::completionHook()
|
||||||
completeFlakeInput(*prefix);
|
completeFlakeInput(*prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceExprCommand::SourceExprCommand(bool supportReadOnlyMode)
|
SourceExprCommand::SourceExprCommand()
|
||||||
{
|
{
|
||||||
addFlag({
|
addFlag({
|
||||||
.longName = "file",
|
.longName = "file",
|
||||||
|
@ -169,18 +169,19 @@ SourceExprCommand::SourceExprCommand(bool supportReadOnlyMode)
|
||||||
.labels = {"expr"},
|
.labels = {"expr"},
|
||||||
.handler = {&expr}
|
.handler = {&expr}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (supportReadOnlyMode) {
|
MixReadOnlyOption::MixReadOnlyOption()
|
||||||
|
{
|
||||||
addFlag({
|
addFlag({
|
||||||
.longName = "read-only",
|
.longName = "read-only",
|
||||||
.description =
|
.description =
|
||||||
"Do not instantiate each evaluated derivation. "
|
"Do not instantiate each evaluated derivation. "
|
||||||
"This improves performance, but can cause errors when accessing "
|
"This improves performance, but can cause errors when accessing "
|
||||||
"store paths of derivations during evaluation.",
|
"store paths of derivations during evaluation.",
|
||||||
.handler = {&readOnlyMode, true},
|
.handler = {&settings.readOnlyMode, true},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Strings SourceExprCommand::getDefaultFlakeAttrPaths()
|
Strings SourceExprCommand::getDefaultFlakeAttrPaths()
|
||||||
{
|
{
|
||||||
|
@ -426,10 +427,6 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<Installable>> result;
|
std::vector<std::shared_ptr<Installable>> result;
|
||||||
|
|
||||||
if (readOnlyMode) {
|
|
||||||
settings.readOnlyMode = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file || expr) {
|
if (file || expr) {
|
||||||
if (file && expr)
|
if (file && expr)
|
||||||
throw UsageError("'--file' and '--expr' are exclusive");
|
throw UsageError("'--file' and '--expr' are exclusive");
|
||||||
|
@ -724,8 +721,8 @@ std::vector<std::string> InstallablesCommand::getFlakesForCompletion()
|
||||||
return _installables;
|
return _installables;
|
||||||
}
|
}
|
||||||
|
|
||||||
InstallableCommand::InstallableCommand(bool supportReadOnlyMode)
|
InstallableCommand::InstallableCommand()
|
||||||
: SourceExprCommand(supportReadOnlyMode)
|
: SourceExprCommand()
|
||||||
{
|
{
|
||||||
expectArgs({
|
expectArgs({
|
||||||
.label = "installable",
|
.label = "installable",
|
||||||
|
|
|
@ -11,13 +11,13 @@
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
struct CmdEval : MixJSON, InstallableCommand
|
struct CmdEval : MixJSON, InstallableCommand, MixReadOnlyOption
|
||||||
{
|
{
|
||||||
bool raw = false;
|
bool raw = false;
|
||||||
std::optional<std::string> apply;
|
std::optional<std::string> apply;
|
||||||
std::optional<Path> writeTo;
|
std::optional<Path> writeTo;
|
||||||
|
|
||||||
CmdEval() : InstallableCommand(true /* supportReadOnlyMode */)
|
CmdEval() : InstallableCommand()
|
||||||
{
|
{
|
||||||
addFlag({
|
addFlag({
|
||||||
.longName = "raw",
|
.longName = "raw",
|
||||||
|
|
Loading…
Reference in a new issue