aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-06-17 16:58:59 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-06-17 16:58:59 +0200
commit2467c9837500b26aab5c1dcd3cac12cda44898ca (patch)
treeae23c6c4489121e1333f12710403b7c0a8c75dbf /src
parentd6c4fe55db57c46aa113dc2f88e60b4a5e55ccf9 (diff)
nix app: Search for installable in the 'apps' output
I.e. you can write $ nix app blender-bin:blender_2_80 which is equivalent to $ nix app blender-bin:apps.blender_2_80
Diffstat (limited to 'src')
-rw-r--r--src/nix/command.hh12
-rw-r--r--src/nix/installables.cc27
-rw-r--r--src/nix/run.cc5
3 files changed, 30 insertions, 14 deletions
diff --git a/src/nix/command.hh b/src/nix/command.hh
index 659b724c3..3dad64947 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -102,6 +102,18 @@ struct SourceExprCommand : virtual Args, EvalCommand, MixFlakeOptions
{
return {"defaultPackage"};
}
+
+ virtual Strings getDefaultFlakeAttrPathPrefixes()
+ {
+ return {
+ // As a convenience, look for the attribute in
+ // 'outputs.packages'.
+ "packages.",
+ // As a temporary hack until Nixpkgs is properly converted
+ // to provide a clean 'packages' set, look in 'legacyPackages'.
+ "legacyPackages."
+ };
+ }
};
enum RealiseMode { Build, NoBuild, DryRun };
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 1c7debf4e..d7dd95606 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -257,14 +257,16 @@ struct InstallableFlake : InstallableValue
{
FlakeRef flakeRef;
Strings attrPaths;
- bool searchPackages = false;
+ Strings prefixes;
InstallableFlake(SourceExprCommand & cmd, FlakeRef && flakeRef, Strings attrPaths)
: InstallableValue(cmd), flakeRef(flakeRef), attrPaths(std::move(attrPaths))
{ }
- InstallableFlake(SourceExprCommand & cmd, FlakeRef && flakeRef, std::string attrPath)
- : InstallableValue(cmd), flakeRef(flakeRef), attrPaths{attrPath}, searchPackages(true)
+ InstallableFlake(SourceExprCommand & cmd, FlakeRef && flakeRef,
+ std::string attrPath, Strings && prefixes)
+ : InstallableValue(cmd), flakeRef(flakeRef), attrPaths{attrPath},
+ prefixes(prefixes)
{ }
std::string what() override { return flakeRef.to_string() + ":" + *attrPaths.begin(); }
@@ -273,15 +275,8 @@ struct InstallableFlake : InstallableValue
{
std::vector<std::string> res;
- if (searchPackages) {
- // As a convenience, look for the attribute in
- // 'outputs.packages'.
- res.push_back("packages." + *attrPaths.begin());
-
- // As a temporary hack until Nixpkgs is properly converted
- // to provide a clean 'packages' set, look in 'legacyPackages'.
- res.push_back("legacyPackages." + *attrPaths.begin());
- }
+ for (auto & prefix : prefixes)
+ res.push_back(prefix + *attrPaths.begin());
for (auto & s : attrPaths)
res.push_back(s);
@@ -421,7 +416,11 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
else if ((colon = s.rfind(':')) != std::string::npos) {
auto flakeRef = std::string(s, 0, colon);
auto attrPath = std::string(s, colon + 1);
- result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef(flakeRef, true), attrPath));
+ result.push_back(std::make_shared<InstallableFlake>(
+ *this,
+ FlakeRef(flakeRef, true),
+ attrPath,
+ getDefaultFlakeAttrPathPrefixes()));
}
else if (s.find('/') != std::string::npos || s == ".") {
@@ -437,7 +436,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
}
else
- result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef("nixpkgs"), s));
+ throw Error("unsupported argument '%s'", s);
}
}
diff --git a/src/nix/run.cc b/src/nix/run.cc
index 00a682832..62aae12f6 100644
--- a/src/nix/run.cc
+++ b/src/nix/run.cc
@@ -225,6 +225,11 @@ struct CmdApp : InstallableCommand, RunCommon
return {"defaultApp"};
}
+ Strings getDefaultFlakeAttrPathPrefixes() override
+ {
+ return {"apps."};
+ }
+
void run(ref<Store> store) override
{
auto state = getEvalState();