about summary refs log tree commit diff
path: root/src/nix-env
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-04-05T22·27+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-04-05T22·27+0000
commit59b94ee18ac0cba5c7b261ee72550a4d3db0acb5 (patch)
tree9dbe6721699439cda3ce68ac86acbe38e9839e66 /src/nix-env
parenta520b1cbc3327dfb8e3c6f503dfd0bd41e0a6d55 (diff)
* When something goes wrong in the evaluation of a Nix expression,
  print a nice backtrace of the stack, rather than vomiting a gigantic
  (and useless) aterm on the screen.  Example:

    error: while evaluating file `.../pkgs/system/test.nix':
    while evaluating attribute `subversion' at `.../pkgs/system/all-packages-generic.nix', line 533:
    while evaluating function at `.../pkgs/applications/version-management/subversion/default.nix', line 1:
    assertion failed at `.../pkgs/applications/version-management/subversion/default.nix', line 13

  Since the Nix expression language is lazy, the trace may be
  misleading.  The purpose is to provide a hint as to the location of
  the problem.    
  

Diffstat (limited to 'src/nix-env')
-rw-r--r--src/nix-env/main.cc39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc
index 07a49a122c97..51bf7ffc3bb0 100644
--- a/src/nix-env/main.cc
+++ b/src/nix-env/main.cc
@@ -108,7 +108,7 @@ void loadDerivations(EvalState & state, Path nePath, DrvInfos & drvs)
 {
     Expr e = parseExprFromFile(state, absPath(nePath));
     if (!parseDerivations(state, e, drvs))
-        throw badTerm("expected set of derivations", e);
+        throw Error("set of derivations expected");
 }
 
 
@@ -126,6 +126,21 @@ static Path getDefNixExprPath()
 }
 
 
+struct AddPos : TermFun
+{
+    ATerm operator () (ATerm e)
+    {
+        ATMatcher m;
+        ATerm x, y, z;
+        if (atMatch(m, e) >> "Bind" >> x >> y >> z)
+            return e;
+        if (atMatch(m, e) >> "Bind" >> x >> y)
+            return ATmake("Bind(<term>, <term>, NoPos)", x, y);
+        return e;
+    }
+};
+
+
 void queryInstalled(EvalState & state, DrvInfos & drvs,
     const Path & userEnv)
 {
@@ -136,8 +151,12 @@ void queryInstalled(EvalState & state, DrvInfos & drvs,
     Expr e = ATreadFromNamedFile(path.c_str());
     if (!e) throw Error(format("cannot read Nix expression from `%1%'") % path);
 
+    /* Compatibility: Bind(x, y) -> Bind(x, y, NoPos). */
+    AddPos addPos;
+    e = bottomupRewrite(addPos, e);
+
     if (!parseDerivations(state, e, drvs))
-        throw badTerm(format("expected set of derivations in `%1%'") % path, e);
+        throw badTerm(format("set of derivations expected in `%1%'") % path, e);
 }
 
 
@@ -155,11 +174,11 @@ void createUserEnv(EvalState & state, const DrvInfos & drvs,
     {
         ATerm t = ATmake(
             "Attrs(["
-            "Bind(\"type\", Str(\"derivation\")), "
-            "Bind(\"name\", Str(<str>)), "
-            "Bind(\"drvPath\", Path(<str>)), "
-            "Bind(\"drvHash\", Str(<str>)), "
-            "Bind(\"outPath\", Path(<str>))"
+            "Bind(\"type\", Str(\"derivation\"), NoPos), "
+            "Bind(\"name\", Str(<str>), NoPos), "
+            "Bind(\"drvPath\", Path(<str>), NoPos), "
+            "Bind(\"drvHash\", Str(<str>), NoPos), "
+            "Bind(\"outPath\", Path(<str>), NoPos)"
             "])",
             i->second.name.c_str(),
             i->second.drvPath.c_str(),
@@ -176,9 +195,9 @@ void createUserEnv(EvalState & state, const DrvInfos & drvs,
 
     Expr topLevel = ATmake(
         "Call(<term>, Attrs(["
-        "Bind(\"system\", Str(<str>)), "
-        "Bind(\"derivations\", <term>), " // !!! redundant
-        "Bind(\"manifest\", Path(<str>))"
+        "Bind(\"system\", Str(<str>), NoPos), "
+        "Bind(\"derivations\", <term>, NoPos), " // !!! redundant
+        "Bind(\"manifest\", Path(<str>), NoPos)"
         "]))",
         envBuilder, thisSystem.c_str(), inputs2, inputsFile.c_str());