about summary refs log tree commit diff
path: root/src/nix-store
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-store')
-rw-r--r--src/nix-store/help.txt1
-rw-r--r--src/nix-store/main.cc41
2 files changed, 39 insertions, 3 deletions
diff --git a/src/nix-store/help.txt b/src/nix-store/help.txt
index 388a7521fb..df84a2a763 100644
--- a/src/nix-store/help.txt
+++ b/src/nix-store/help.txt
@@ -9,6 +9,7 @@ Operations:
   --add / -A: copy a path to the Nix store
   --delete: safely delete paths from the Nix store
   --query / -q: query information
+  --read-log / -l: print build log of given store paths
 
   --register-substitutes: register a substitute expression (dangerous!)
   --clear-substitutes: clear all substitutes
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index b83eb88370..ec35d430da 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -46,6 +46,17 @@ static Path fixPath(Path path)
 }
 
 
+static Path useDeriver(Path path)
+{       
+    if (!isDerivation(path)) {
+        path = queryDeriver(noTxn, path);
+        if (path == "")
+            throw Error(format("deriver of path `%1%' is not known") % path);
+    }
+    return path;
+}
+
+
 /* Realisation the given path.  For a derivation that means build it;
    for other paths it means ensure their validity. */
 static Path realisePath(const Path & path)
@@ -360,12 +371,12 @@ static void opQuery(Strings opFlags, Strings opArgs)
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); ++i)
             {
-                *i = fixPath(*i);
-                Derivation drv = derivationFromPath(*i);
+                Path path = useDeriver(fixPath(*i));
+                Derivation drv = derivationFromPath(path);
                 StringPairs::iterator j = drv.env.find(bindingName);
                 if (j == drv.env.end())
                     throw Error(format("derivation `%1%' has no environment binding named `%2%'")
-                        % *i % bindingName);
+                        % path % bindingName);
                 cout << format("%1%\n") % j->second;
             }
             break;
@@ -404,6 +415,28 @@ static void opQuery(Strings opFlags, Strings opArgs)
 }
 
 
+static void opReadLog(Strings opFlags, Strings opArgs)
+{
+    if (!opFlags.empty()) throw UsageError("unknown flag");
+
+    for (Strings::iterator i = opArgs.begin();
+         i != opArgs.end(); ++i)
+    {
+        Path path = useDeriver(fixPath(*i));
+        
+        Path logPath = (format("%1%/%2%/%3%") %
+            nixLogDir % drvsLogDir % baseNameOf(path)).str();
+
+        if (!pathExists(logPath))
+            throw Error(format("build log of derivation `%1%' is not available") % path);
+
+        /* !!! Make this run in O(1) memory. */
+        string log = readFile(logPath);
+        writeFull(STDOUT_FILENO, (const unsigned char *) log.c_str(), log.size());
+    }
+}
+
+
 static void opRegisterSubstitutes(Strings opFlags, Strings opArgs)
 {
     if (!opFlags.empty()) throw UsageError("unknown flag");
@@ -663,6 +696,8 @@ void run(Strings args)
             op = opDelete;
         else if (arg == "--query" || arg == "-q")
             op = opQuery;
+        else if (arg == "--read-log" || arg == "-l")
+            op = opReadLog;
         else if (arg == "--register-substitutes")
             op = opRegisterSubstitutes;
         else if (arg == "--clear-substitutes")