aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd/repl.cc
diff options
context:
space:
mode:
authorGoldstein <root@goldstein.rs>2024-08-05 16:26:39 +0300
committerGoldstein <root@goldstein.rs>2024-08-07 15:58:44 +0300
commit9adfd9b8ad48f631c935d5a146bbf98a3cf603cb (patch)
treed60c104ed8e0a7c1e6fd338af61c341670587352 /src/libcmd/repl.cc
parent66469fc281fc4abb3284574f77a8051fee8116b9 (diff)
src/libcmd/repl.cc: allow :log /path/to/store.drv
This adds a second form to the `:log` command: it now can accept a derivation path in addition to a derivation expression. As derivation store paths start with `/nix/store`, this is not ambiguous. Resolves: https://git.lix.systems/lix-project/lix/issues/51 Change-Id: Iebc7b011537e7012fae8faed4024ea1b8fdc81c3
Diffstat (limited to 'src/libcmd/repl.cc')
-rw-r--r--src/libcmd/repl.cc74
1 files changed, 44 insertions, 30 deletions
diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc
index 5086e9999..b8bfc25eb 100644
--- a/src/libcmd/repl.cc
+++ b/src/libcmd/repl.cc
@@ -536,7 +536,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
<< " :t <expr> Describe result of evaluation\n"
<< " :u <expr> Build derivation, then start nix-shell\n"
<< " :doc <expr> Show documentation for the provided function (experimental lambda support)\n"
- << " :log <expr> Show logs for a derivation\n"
+ << " :log <expr | .drv path> Show logs for a derivation\n"
<< " :te, :trace-enable [bool] Enable, disable or toggle showing traces for\n"
<< " errors\n"
<< " :?, :help Brings up this help menu\n"
@@ -676,7 +676,49 @@ ProcessLineResult NixRepl::processLine(std::string line)
runNix("nix-shell", {state->store->printStorePath(drvPath)});
}
- else if (command == ":b" || command == ":bl" || command == ":i" || command == ":sh" || command == ":log") {
+ else if (command == ":log") {
+ StorePath drvPath = ([&] {
+ auto maybeDrvPath = state->store->maybeParseStorePath(arg);
+ if (maybeDrvPath && maybeDrvPath->isDerivation()) {
+ return std::move(*maybeDrvPath);
+ } else {
+ Value v;
+ evalString(arg, v);
+ return getDerivationPath(v);
+ }
+ })();
+ Path drvPathRaw = state->store->printStorePath(drvPath);
+
+ settings.readOnlyMode = true;
+ Finally roModeReset([&]() {
+ settings.readOnlyMode = false;
+ });
+ auto subs = getDefaultSubstituters();
+
+ subs.push_front(state->store);
+
+ bool foundLog = false;
+ RunPager pager;
+ for (auto & sub : subs) {
+ auto * logSubP = dynamic_cast<LogStore *>(&*sub);
+ if (!logSubP) {
+ printInfo("Skipped '%s' which does not support retrieving build logs", sub->getUri());
+ continue;
+ }
+ auto & logSub = *logSubP;
+
+ auto log = logSub.getBuildLog(drvPath);
+ if (log) {
+ printInfo("got build log for '%s' from '%s'", drvPathRaw, logSub.getUri());
+ logger->writeToStdout(*log);
+ foundLog = true;
+ break;
+ }
+ }
+ if (!foundLog) throw Error("build log of '%s' is not available", drvPathRaw);
+ }
+
+ else if (command == ":b" || command == ":bl" || command == ":i" || command == ":sh") {
Value v;
evalString(arg, v);
StorePath drvPath = getDerivationPath(v);
@@ -712,34 +754,6 @@ ProcessLineResult NixRepl::processLine(std::string line)
}
} else if (command == ":i") {
runNix("nix-env", {"-i", drvPathRaw});
- } else if (command == ":log") {
- settings.readOnlyMode = true;
- Finally roModeReset([&]() {
- settings.readOnlyMode = false;
- });
- auto subs = getDefaultSubstituters();
-
- subs.push_front(state->store);
-
- bool foundLog = false;
- RunPager pager;
- for (auto & sub : subs) {
- auto * logSubP = dynamic_cast<LogStore *>(&*sub);
- if (!logSubP) {
- printInfo("Skipped '%s' which does not support retrieving build logs", sub->getUri());
- continue;
- }
- auto & logSub = *logSubP;
-
- auto log = logSub.getBuildLog(drvPath);
- if (log) {
- printInfo("got build log for '%s' from '%s'", drvPathRaw, logSub.getUri());
- logger->writeToStdout(*log);
- foundLog = true;
- break;
- }
- }
- if (!foundLog) throw Error("build log of '%s' is not available", drvPathRaw);
} else {
runNix("nix-shell", {drvPathRaw});
}