aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-09-02 17:33:07 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-09-02 17:35:35 +0200
commit61fdb16aacf9ff18c96b72a37e1b46eb14586eb4 (patch)
treee513ef2858e96d2b9d764c5e9b5fe5b3bec2f250 /src/nix
parent5ec2a1ed82d485429aaf6fbad55fd6c1320b2d8c (diff)
Improve error message when a directory is not a flake
So you now get $ nix build error: path '.' is not a flake (because it does not reference a Git repository) rather than $ nix build error: unsupported argument '.'
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/installables.cc52
1 files changed, 35 insertions, 17 deletions
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index dbbf58861..a4726a59e 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -417,25 +417,43 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
Strings{"legacyPackages." + std::string(s, 8)}));
}
- else if (auto flakeRef = parseFlakeRef(s, true))
- result.push_back(std::make_shared<InstallableFlake>(*this, std::move(*flakeRef),
- getDefaultFlakeAttrPaths()));
-
- 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,
- getDefaultFlakeAttrPathPrefixes()));
- }
+ else {
+
+ std::exception_ptr flakeEx;
+
+ try {
+ auto flakeRef = FlakeRef(s, true);
+ result.push_back(std::make_shared<InstallableFlake>(
+ *this, std::move(flakeRef), getDefaultFlakeAttrPaths()));
+ continue;
+ } catch (MissingFlake &) {
+ /* 's' could be parsed as a flakeref, but it
+ references a local path that is not a flake. So
+ take note of that. */
+ flakeEx = std::current_exception();
+ } catch (BadFlakeRef &) {
+ }
+
+ 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,
+ getDefaultFlakeAttrPathPrefixes()));
+ }
- else if (s.find('/') != std::string::npos && (storePath = follow(s)))
- result.push_back(std::make_shared<InstallableStorePath>(*storePath));
+ else if (s.find('/') != std::string::npos && (storePath = follow(s)))
+ result.push_back(std::make_shared<InstallableStorePath>(*storePath));
- else
- throw Error("unsupported argument '%s'", s);
+ else {
+ if (flakeEx)
+ std::rethrow_exception(flakeEx);
+ else
+ throw Error("unsupported argument '%s'", s);
+ }
+ }
}
}