aboutsummaryrefslogtreecommitdiff
path: root/src/nix/installables.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-11-27 00:05:30 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-11-27 00:05:30 +0100
commitca8caaec5e7581c37b46f79622c81adf52f06314 (patch)
tree0e0693236f221f1d9ac0fba265a01c196396cb6a /src/nix/installables.cc
parent2c6dbcd5e7a16227e0aef008c62c81220f4b3ffc (diff)
nix: Add --expr flag
This replaces the '(...)' installable syntax, which is not very discoverable. The downside is that you can't have multiple expressions or mix expressions and other installables.
Diffstat (limited to 'src/nix/installables.cc')
-rw-r--r--src/nix/installables.cc33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 671cf513a..3e0fe2606 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -51,8 +51,14 @@ SourceExprCommand::SourceExprCommand()
.shortName('f')
.longName("file")
.label("file")
- .description("evaluate a set of attributes from FILE (deprecated)")
+ .description("evaluate attributes from FILE")
.dest(&file);
+
+ mkFlag()
+ .longName("expr")
+ .label("expr")
+ .description("evaluate attributes from EXPR")
+ .dest(&expr);
}
Strings SourceExprCommand::getDefaultFlakeAttrPaths()
@@ -378,19 +384,25 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
{
std::vector<std::shared_ptr<Installable>> result;
- if (file) {
+ if (file || expr) {
+ if (file && expr)
+ throw UsageError("'--file' and '--expr' are exclusive");
+
// FIXME: backward compatibility hack
- evalSettings.pureEval = false;
+ if (file) evalSettings.pureEval = false;
auto state = getEvalState();
auto vFile = state->allocValue();
- state->evalFile(lookupFileArg(*state, *file), *vFile);
- if (ss.empty())
- ss = {""};
+ if (file)
+ state->evalFile(lookupFileArg(*state, *file), *vFile);
+ else {
+ auto e = state->parseExprFromString(*expr, absPath("."));
+ state->eval(e, *vFile);
+ }
for (auto & s : ss)
- result.push_back(std::make_shared<InstallableAttrPath>(*this, vFile, s));
+ result.push_back(std::make_shared<InstallableAttrPath>(*this, vFile, s == "." ? "" : s));
} else {
@@ -407,10 +419,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
size_t hash;
std::optional<Path> storePath;
- if (s.compare(0, 1, "(") == 0)
- result.push_back(std::make_shared<InstallableExpr>(*this, s));
-
- else if (hasPrefix(s, "nixpkgs.")) {
+ if (hasPrefix(s, "nixpkgs.")) {
bool static warned;
warnOnce(warned, "the syntax 'nixpkgs.<attr>' is deprecated; use 'nixpkgs:<attr>' instead");
result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef("nixpkgs"),
@@ -532,7 +541,7 @@ PathSet toDerivations(ref<Store> store,
void InstallablesCommand::prepare()
{
- if (_installables.empty() && !file && useDefaultInstallables())
+ if (_installables.empty() && useDefaultInstallables())
// FIXME: commands like "nix install" should not have a
// default, probably.
_installables.push_back(".");