aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/flake.cc11
-rw-r--r--src/nix/installables.cc47
2 files changed, 33 insertions, 25 deletions
diff --git a/src/nix/flake.cc b/src/nix/flake.cc
index c09ba3610..c47d51fe4 100644
--- a/src/nix/flake.cc
+++ b/src/nix/flake.cc
@@ -551,17 +551,18 @@ struct CmdFlakeInit : virtual Args, Command
{
Path flakeDir = absPath(".");
- if (!pathExists(flakeDir + "/.git"))
- throw Error("the directory '%s' is not a Git repository", flakeDir);
-
Path flakePath = flakeDir + "/flake.nix";
if (pathExists(flakePath))
throw Error("file '%s' already exists", flakePath);
writeFile(flakePath,
-#include "flake-template.nix.gen.hh"
- );
+ #include "flake-template.nix.gen.hh"
+ );
+
+ if (pathExists(flakeDir + "/.git"))
+ runProgram("git", true,
+ { "-C", flakeDir, "add", "--intent-to-add", "flake.nix" });
}
};
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 3871536e1..6b9e2ee96 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -438,14 +438,6 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
} else {
- auto follow = [&](const std::string & s) -> std::optional<StorePath> {
- try {
- return store->followLinksToStorePath(s);
- } catch (NotInStore &) {
- return {};
- }
- };
-
for (auto & s : ss) {
if (hasPrefix(s, "nixpkgs.")) {
bool static warned;
@@ -456,23 +448,38 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
}
else {
- auto res = maybeParseFlakeRefWithFragment(s, absPath("."));
- if (res) {
- auto &[flakeRef, fragment] = *res;
+ std::exception_ptr ex;
+
+ try {
+ auto [flakeRef, fragment] = parseFlakeRefWithFragment(s, absPath("."));
result.push_back(std::make_shared<InstallableFlake>(
*this, std::move(flakeRef),
fragment == "" ? getDefaultFlakeAttrPaths() : Strings{fragment},
getDefaultFlakeAttrPathPrefixes()));
- } else {
- std::optional<StorePath> storePath;
- if (s.find('/') != std::string::npos && (storePath = follow(s)))
- result.push_back(std::make_shared<InstallableStorePath>(store, store->printStorePath(*storePath)));
- else
- throw Error(
- pathExists(s)
- ? "path '%s' is not a flake or a store path"
- : "don't know how to handle argument '%s'", s);
+ continue;
+ } catch (...) {
+ ex = std::current_exception();
}
+
+ if (s.find('/') != std::string::npos) {
+ try {
+ result.push_back(std::make_shared<InstallableStorePath>(store, store->printStorePath(store->followLinksToStorePath(s))));
+ continue;
+ } catch (NotInStore &) {
+ } catch (...) {
+ if (!ex)
+ ex = std::current_exception();
+ }
+ }
+
+ std::rethrow_exception(ex);
+
+ /*
+ throw Error(
+ pathExists(s)
+ ? "path '%s' is not a flake or a store path"
+ : "don't know how to handle argument '%s'", s);
+ */
}
}
}