diff --git a/src/libutil/ansicolor.hh b/src/libutil/ansicolor.hh
new file mode 100644
index 0000000000000000000000000000000000000000..390bd4d17c384ec6cd752c61da5ddf23d7a2d952
--- /dev/null
+++ b/src/libutil/ansicolor.hh
@@ -0,0 +1,13 @@
+#pragma once 
+
+namespace nix 
+{
+  /* Some ANSI escape sequences. */
+  #define ANSI_NORMAL "\e[0m"
+  #define ANSI_BOLD "\e[1m"
+  #define ANSI_FAINT "\e[2m"
+  #define ANSI_RED "\e[31;1m"
+  #define ANSI_GREEN "\e[32;1m"
+  #define ANSI_YELLOW "\e[33;1m"
+  #define ANSI_BLUE "\e[34;1m"
+}
diff --git a/src/libutil/error.cc b/src/libutil/error.cc
index 9194539a5a0fa9b668f842ba1908c352141800a5..c986affccbad21b3ea077880ede2d8574c56b953 100644
--- a/src/libutil/error.cc
+++ b/src/libutil/error.cc
@@ -104,7 +104,7 @@ void printErrorInfo(ErrorInfo &einfo)
       }
     default: 
       {
-        levelString = format("invalid error level: %1%") % einfo.level;  
+        levelString = (format("invalid error level: %1%") % einfo.level).str();  
         break;
       }
   }
diff --git a/src/libutil/error.hh b/src/libutil/error.hh
index f02d7288abefbaaccf19ff4bb6b55a6329189731..88980afb77892fd02932a7ea868c083e8039809b 100644
--- a/src/libutil/error.hh
+++ b/src/libutil/error.hh
@@ -1,11 +1,13 @@
 #pragma once
 
-#include "util.hh"
+#include "ansicolor.hh"
 #include <string>
 #include <optional>
 #include <iostream>
 #include <iomanip>
 
+#include <boost/format.hpp>
+
 using std::string;
 using std::optional;
 using boost::format;
@@ -251,8 +253,14 @@ class AddHint : private T
 // --------------------------------------------------------
 // error types
 
-typedef AddName<AddDescription<AddHint<EIError>>> StandardError;
-typedef AddName<AddDescription<AddHint<EIWarning>>> StandardWarning;
+typedef AddName<
+        AddDescription<
+        AddHint<
+        EIError>>> StandardError;
+typedef AddName<
+        AddDescription<
+        AddHint<
+        EIWarning>>> StandardWarning;
 
 typedef AddName<
         AddDescription<
@@ -260,13 +268,16 @@ typedef AddName<
         AddLineNumber<
         AddColumnRange<
         AddLOC<
-        AddHint<EIError>>>>>>> MkNixError;
+        AddHint<
+        EIError>>>>>>> MkNixError;
 typedef AddName<
         AddDescription<
         AddNixFile<
         AddLineNumber<
         AddColumnRange<
-        AddLOC<EIWarning>>>>>> MkNixWarning;
+        AddLOC<
+        AddHint<
+        EIWarning>>>>>>> MkNixWarning;
 
 
 // --------------------------------------------------------
@@ -274,9 +285,5 @@ typedef AddName<
 
 void printErrorInfo(ErrorInfo &einfo);
 
-string showErrLine(ErrLine &errLine);
-
-void printCodeLines(string &prefix, NixCode &nixCode); 
-
 }
 
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 3bfebcd153a90f40810c49f479ca437301bad776..d69e29158794a77a5b90203f56319aa75c53dc4c 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -2,6 +2,7 @@
 
 #include "types.hh"
 #include "logging.hh"
+#include "ansicolor.hh"
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -423,15 +424,6 @@ std::string shellEscape(const std::string & s);
 void ignoreException();
 
 
-/* Some ANSI escape sequences. */
-#define ANSI_NORMAL "\e[0m"
-#define ANSI_BOLD "\e[1m"
-#define ANSI_FAINT "\e[2m"
-#define ANSI_RED "\e[31;1m"
-#define ANSI_GREEN "\e[32;1m"
-#define ANSI_YELLOW "\e[33;1m"
-#define ANSI_BLUE "\e[34;1m"
-
 
 /* Truncate a string to 'width' printable characters. If 'filterAll'
    is true, all ANSI escape sequences are filtered out. Otherwise,