diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2021-12-07 21:33:32 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2021-12-07 21:33:32 +0100 |
commit | 8b5088b62fe8f97643d77a024edffabf9ef4aa3d (patch) | |
tree | 5f40f05b5a2f5d10a98095474f94e8d7e1ac5d8a /src | |
parent | a5e9b5428f9a6c7b50752d4e5cb7431625db624a (diff) | |
parent | 33926ed1e75c06cbf70a920e462841cc9daa0520 (diff) |
Merge branch 'balsoft/nix-repl-log' of https://github.com/tweag/nix
Diffstat (limited to 'src')
-rw-r--r-- | src/libmain/shared.cc | 4 | ||||
-rw-r--r-- | src/libmain/shared.hh | 1 | ||||
-rw-r--r-- | src/nix/repl.cc | 26 | ||||
-rw-r--r-- | src/nix/repl.md | 7 |
4 files changed, 32 insertions, 6 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index b6bfea8cb..4404e0195 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -427,7 +427,7 @@ RunPager::RunPager() }); pid.setKillSignal(SIGINT); - + stdout = fcntl(STDOUT_FILENO, F_DUPFD_CLOEXEC, 0); if (dup2(toPager.writeSide.get(), STDOUT_FILENO) == -1) throw SysError("dupping stdout"); } @@ -438,7 +438,7 @@ RunPager::~RunPager() try { if (pid != -1) { std::cout.flush(); - close(STDOUT_FILENO); + dup2(stdout, STDOUT_FILENO); pid.wait(); } } catch (...) { diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh index 05277d90a..ed012959b 100644 --- a/src/libmain/shared.hh +++ b/src/libmain/shared.hh @@ -88,6 +88,7 @@ public: private: Pid pid; + int stdout; }; extern volatile ::sig_atomic_t blockInt; diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 2649eb0bd..42143871f 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -430,7 +430,8 @@ bool NixRepl::processLine(string line) << " :s <expr> Build dependencies of derivation, then start nix-shell\n" << " :t <expr> Describe result of evaluation\n" << " :u <expr> Build derivation, then start nix-shell\n" - << " :doc <expr> Show documentation of a builtin function\n"; + << " :doc <expr> Show documentation of a builtin function\n" + << " :log <expr> Show logs for a derivation\n"; } else if (command == ":a" || command == ":add") { @@ -500,7 +501,7 @@ bool NixRepl::processLine(string line) runNix("nix-shell", {state->store->printStorePath(drvPath)}); } - else if (command == ":b" || command == ":i" || command == ":s") { + else if (command == ":b" || command == ":i" || command == ":s" || command == ":log") { Value v; evalString(arg, v); StorePath drvPath = getDerivationPath(v); @@ -514,6 +515,27 @@ bool NixRepl::processLine(string line) logger->cout(" %s -> %s", outputName, state->store->printStorePath(outputPath)); } 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 log = sub->getBuildLog(drvPath); + if (log) { + printInfo("got build log for '%s' from '%s'", drvPathRaw, sub->getUri()); + logger->writeToStdout(*log); + foundLog = true; + break; + } + } + if (!foundLog) throw Error("build log of '%s' is not available", drvPathRaw); } else { runNix("nix-shell", {drvPathRaw}); } diff --git a/src/nix/repl.md b/src/nix/repl.md index bba60f871..9b6f2bee3 100644 --- a/src/nix/repl.md +++ b/src/nix/repl.md @@ -35,14 +35,17 @@ R""( nix-repl> emacs.drvPath "/nix/store/lp0sjrhgg03y2n0l10n70rg0k7hhyz0l-emacs-27.1.drv" - nix-repl> drv = runCommand "hello" { buildInputs = [ hello ]; } "hello > $out" + nix-repl> drv = runCommand "hello" { buildInputs = [ hello ]; } "hello; hello > $out" - nix-repl> :b x + nix-repl> :b drv this derivation produced the following outputs: out -> /nix/store/0njwbgwmkwls0w5dv9mpc1pq5fj39q0l-hello nix-repl> builtins.readFile drv "Hello, world!\n" + + nix-repl> :log drv + Hello, world! ``` # Description |