about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-19T16·38+0100
committerVincent Ambo <tazjin@google.com>2020-05-19T16·38+0100
commitb490742a511dd03afc43f5143d6d61edaeeb8091 (patch)
tree727370e8e7607a3078c2ce1cd6d717105c7d9c44 /third_party/nix/src/libexpr
parentc758de9d22506eb279c5abe61f621e5c8f61af95 (diff)
style(3p/nix): Enforce braces around loops and conditionals r/767
This change was generated with:

  fd -e cc -e hh | xargs -I{} clang-tidy {} -p ~/projects/nix-build/ \
    --checks='-*,readability-braces-around-statements' --fix \
    -fix-errors

Some manual fixes were applied because some convoluted unbraced
statements couldn't be untangled by clang-tidy.

This commit still includes invalid files, but I decided to clean them
up in a subsequent commit so that it becomes more obvious where
clang-tidy failed. Maybe this will allow for a bug-report to
clang-tidy.
Diffstat (limited to 'third_party/nix/src/libexpr')
-rw-r--r--third_party/nix/src/libexpr/eval-inline.hh18
-rw-r--r--third_party/nix/src/libexpr/eval.cc154
-rw-r--r--third_party/nix/src/libexpr/get-drvs.cc112
-rw-r--r--third_party/nix/src/libexpr/json-to-value.cc18
-rw-r--r--third_party/nix/src/libexpr/names.cc14
-rw-r--r--third_party/nix/src/libexpr/nixexpr.cc17
-rw-r--r--third_party/nix/src/libexpr/nixexpr.hh24
-rw-r--r--third_party/nix/src/libexpr/primops.cc98
-rw-r--r--third_party/nix/src/libexpr/primops/fetchGit.cc6
-rw-r--r--third_party/nix/src/libexpr/primops/fetchMercurial.cc6
-rw-r--r--third_party/nix/src/libexpr/value-to-json.cc4
-rw-r--r--third_party/nix/src/libexpr/value-to-xml.cc22
12 files changed, 339 insertions, 154 deletions
diff --git a/third_party/nix/src/libexpr/eval-inline.hh b/third_party/nix/src/libexpr/eval-inline.hh
index 37105e7e398d..d92614ca7ca6 100644
--- a/third_party/nix/src/libexpr/eval-inline.hh
+++ b/third_party/nix/src/libexpr/eval-inline.hh
@@ -38,33 +38,39 @@ void EvalState::forceValue(Value& v, const Pos& pos) {
       v.thunk.expr = expr;
       throw;
     }
-  } else if (v.type == tApp)
+  } else if (v.type == tApp) {
     callFunction(*v.app.left, *v.app.right, v, noPos);
-  else if (v.type == tBlackhole)
+  } else if (v.type == tBlackhole) {
     throwEvalError("infinite recursion encountered, at %1%", pos);
+  }
 }
 
 inline void EvalState::forceAttrs(Value& v) {
   forceValue(v);
-  if (v.type != tAttrs)
+  if (v.type != tAttrs) {
     throwTypeError("value is %1% while a set was expected", v);
+  }
 }
 
 inline void EvalState::forceAttrs(Value& v, const Pos& pos) {
   forceValue(v);
-  if (v.type != tAttrs)
+  if (v.type != tAttrs) {
     throwTypeError("value is %1% while a set was expected, at %2%", v, pos);
+  }
 }
 
 inline void EvalState::forceList(Value& v) {
   forceValue(v);
-  if (!v.isList()) throwTypeError("value is %1% while a list was expected", v);
+  if (!v.isList()) {
+    throwTypeError("value is %1% while a list was expected", v);
+  }
 }
 
 inline void EvalState::forceList(Value& v, const Pos& pos) {
   forceValue(v);
-  if (!v.isList())
+  if (!v.isList()) {
     throwTypeError("value is %1% while a list was expected, at %2%", v, pos);
+  }
 }
 
 /* Note: Various places expect the allocated memory to be zeroed. */
diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc
index 2a9e18db2802..19f6a46ed655 100644
--- a/third_party/nix/src/libexpr/eval.cc
+++ b/third_party/nix/src/libexpr/eval.cc
@@ -545,14 +545,19 @@ Value& mkString(Value& v, const string& s, const PathSet& context) {
 void mkPath(Value& v, const char* s) { mkPathNoCopy(v, dupString(s)); }
 
 inline Value* EvalState::lookupVar(Env* env, const ExprVar& var, bool noEval) {
-  for (size_t l = var.level; l; --l, env = env->up)
+  for (size_t l = var.level; l; --l, env = env->up) {
     ;
+  }
 
-  if (!var.fromWith) return env->values[var.displ];
+  if (!var.fromWith) {
+    return env->values[var.displ];
+  }
 
   while (1) {
     if (env->type == Env::HasWithExpr) {
-      if (noEval) return 0;
+      if (noEval) {
+        return 0;
+      }
       Value* v = allocValue();
       evalAttrs(*env->up, (Expr*)env->values[0], *v);
       env->values[0] = v;
@@ -566,8 +571,9 @@ inline Value* EvalState::lookupVar(Env* env, const ExprVar& var, bool noEval) {
     if (!env->prevWith)
       throwUndefinedVarError("undefined variable '%1%' at %2%", var.name,
                              var.pos);
-    for (size_t l = env->prevWith; l; --l, env = env->up)
+    for (size_t l = env->prevWith; l; --l, env = env->up) {
       ;
+    }
   }
 }
 
@@ -601,11 +607,11 @@ Env& EvalState::allocEnv(size_t size) {
 
 void EvalState::mkList(Value& v, size_t size) {
   clearValue(v);
-  if (size == 1)
+  if (size == 1) {
     v.type = tList1;
-  else if (size == 2)
+  } else if (size == 2) {
     v.type = tList2;
-  else {
+  } else {
     v.type = tListN;
     v.bigList.size = size;
     v.bigList.elems = size ? (Value**)allocBytes(size * sizeof(Value*)) : 0;
@@ -699,7 +705,9 @@ void EvalState::evalFile(const Path& path_, Value& v) {
   auto j = fileParseCache.find(path2);
   if (j != fileParseCache.end()) e = j->second;
 
-  if (!e) e = parseExprFromFile(checkSourcePath(path2));
+  if (!e) {
+    e = parseExprFromFile(checkSourcePath(path2));
+  }
 
   fileParseCache[path2] = e;
 
@@ -724,23 +732,26 @@ void EvalState::eval(Expr* e, Value& v) { e->eval(*this, baseEnv, v); }
 inline bool EvalState::evalBool(Env& env, Expr* e) {
   Value v;
   e->eval(*this, env, v);
-  if (v.type != tBool)
+  if (v.type != tBool) {
     throwTypeError("value is %1% while a Boolean was expected", v);
+  }
   return v.boolean;
 }
 
 inline bool EvalState::evalBool(Env& env, Expr* e, const Pos& pos) {
   Value v;
   e->eval(*this, env, v);
-  if (v.type != tBool)
+  if (v.type != tBool) {
     throwTypeError("value is %1% while a Boolean was expected, at %2%", v, pos);
+  }
   return v.boolean;
 }
 
 inline void EvalState::evalAttrs(Env& env, Expr* e, Value& v) {
   e->eval(*this, env, v);
-  if (v.type != tAttrs)
+  if (v.type != tAttrs) {
     throwTypeError("value is %1% while a set was expected", v);
+  }
 }
 
 void Expr::eval(EvalState& state, Env& env, Value& v) { abort(); }
@@ -795,7 +806,9 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& v) {
       state.forceAttrs(*vOverrides);
       Bindings* newBnds =
           state.allocBindings(v.attrs->capacity() + vOverrides->attrs->size());
-      for (auto& i : *v.attrs) newBnds->push_back(i);
+      for (auto& i : *v.attrs) {
+        newBnds->push_back(i);
+      }
       for (auto& i : *vOverrides->attrs) {
         AttrDefs::iterator j = attrs.find(i.name);
         if (j != attrs.end()) {
@@ -809,10 +822,12 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& v) {
     }
   }
 
-  else
-    for (auto& i : attrs)
-      v.attrs->push_back(
-          Attr(i.first, i.second.e->maybeThunk(state, env), &i.second.pos));
+  else {
+    for
+  }
+  (auto& i
+   : attrs) v.attrs->push_back(Attr(i.first, i.second.e->maybeThunk(state, env),
+                                    &i.second.pos));
 
   /* Dynamic attrs apply *after* rec and __overrides. */
   for (auto& i : dynamicAttrs) {
@@ -980,8 +995,10 @@ void EvalState::callPrimOp(Value& fun, Value& arg, Value& v, const Pos& pos) {
     Value* vArgs[arity];
     auto n = arity - 1;
     vArgs[n--] = &arg;
-    for (Value* arg = &fun; arg->type == tPrimOpApp; arg = arg->primOpApp.left)
+    for (Value* arg = &fun; arg->type == tPrimOpApp;
+         arg = arg->primOpApp.left) {
       vArgs[n--] = arg->primOpApp.right;
+    }
 
     /* And call the primop. */
     nrPrimOpCalls++;
@@ -1024,10 +1041,11 @@ void EvalState::callFunction(Value& fun, Value& arg, Value& v, const Pos& pos) {
     }
   }
 
-  if (fun.type != tLambda)
+  if (fun.type != tLambda) {
     throwTypeError(
         "attempt to call something which is not a function but %1%, at %2%",
         fun, pos);
+  }
 
   ExprLambda& lambda(*fun.lambda.fun);
 
@@ -1038,10 +1056,10 @@ void EvalState::callFunction(Value& fun, Value& arg, Value& v, const Pos& pos) {
 
   size_t displ = 0;
 
-  if (!lambda.matchAttrs)
+  if (!lambda.matchAttrs) {
     env2.values[displ++] = &arg;
 
-  else {
+  } else {
     forceAttrs(arg, pos);
 
     if (!lambda.arg.empty()) env2.values[displ++] = &arg;
@@ -1078,7 +1096,9 @@ void EvalState::callFunction(Value& fun, Value& arg, Value& v, const Pos& pos) {
   }
 
   nrFunctionCalls++;
-  if (countCalls) incrFunctionCall(&lambda);
+  if (countCalls) {
+    incrFunctionCall(&lambda);
+  }
 
   /* Evaluate the body.  This is conditional on showTrace, because
      catching exceptions makes this function not tail-recursive. */
@@ -1223,8 +1243,12 @@ void ExprOpUpdate::eval(EvalState& state, Env& env, Value& v) {
       v.attrs->push_back(*j++);
   }
 
-  while (i != v1.attrs->end()) v.attrs->push_back(*i++);
-  while (j != v2.attrs->end()) v.attrs->push_back(*j++);
+  while (i != v1.attrs->end()) {
+    v.attrs->push_back(*i++);
+  }
+  while (j != v2.attrs->end()) {
+    v.attrs->push_back(*j++);
+  }
 
   state.nrOpUpdateValuesCopied += v.attrs->size();
 }
@@ -1248,7 +1272,9 @@ void EvalState::concatLists(Value& v, size_t nrLists, Value** lists,
     forceList(*lists[n], pos);
     auto l = lists[n]->listSize();
     len += l;
-    if (l) nonEmpty = lists[n];
+    if (l) {
+      nonEmpty = lists[n];
+    }
   }
 
   if (nonEmpty && len == nonEmpty->listSize()) {
@@ -1311,11 +1337,11 @@ void ExprConcatStrings::eval(EvalState& state, Env& env, Value& v) {
                                 firstType == tString);
   }
 
-  if (firstType == tInt)
+  if (firstType == tInt) {
     mkInt(v, n);
-  else if (firstType == tFloat)
+  } else if (firstType == tFloat) {
     mkFloat(v, nf);
-  else if (firstType == tPath) {
+  } else if (firstType == tPath) {
     if (!context.empty())
       throwEvalError(
           "a string that refers to a store path cannot be appended to a path, "
@@ -1323,8 +1349,10 @@ void ExprConcatStrings::eval(EvalState& state, Env& env, Value& v) {
           pos);
     auto path = canonPath(s.str());
     mkPath(v, path.c_str());
-  } else
-    mkString(v, s.str(), context);
+  } else {
+    mkString
+  }
+  (v, s.str(), context);
 }
 
 void ExprPos::eval(EvalState& state, Env& env, Value& v) {
@@ -1362,25 +1390,28 @@ void EvalState::forceValueDeep(Value& v) {
 
 NixInt EvalState::forceInt(Value& v, const Pos& pos) {
   forceValue(v, pos);
-  if (v.type != tInt)
+  if (v.type != tInt) {
     throwTypeError("value is %1% while an integer was expected, at %2%", v,
                    pos);
+  }
   return v.integer;
 }
 
 NixFloat EvalState::forceFloat(Value& v, const Pos& pos) {
   forceValue(v, pos);
-  if (v.type == tInt)
+  if (v.type == tInt) {
     return v.integer;
-  else if (v.type != tFloat)
+  } else if (v.type != tFloat) {
     throwTypeError("value is %1% while a float was expected, at %2%", v, pos);
+  }
   return v.fpoint;
 }
 
 bool EvalState::forceBool(Value& v, const Pos& pos) {
   forceValue(v);
-  if (v.type != tBool)
+  if (v.type != tBool) {
     throwTypeError("value is %1% while a Boolean was expected, at %2%", v, pos);
+  }
   return v.boolean;
 }
 
@@ -1391,19 +1422,21 @@ bool EvalState::isFunctor(Value& fun) {
 void EvalState::forceFunction(Value& v, const Pos& pos) {
   forceValue(v);
   if (v.type != tLambda && v.type != tPrimOp && v.type != tPrimOpApp &&
-      !isFunctor(v))
+      !isFunctor(v)) {
     throwTypeError("value is %1% while a function was expected, at %2%", v,
                    pos);
+  }
 }
 
 string EvalState::forceString(Value& v, const Pos& pos) {
   forceValue(v, pos);
   if (v.type != tString) {
-    if (pos)
+    if (pos) {
       throwTypeError("value is %1% while a string was expected, at %2%", v,
                      pos);
-    else
+    } else {
       throwTypeError("value is %1% while a string was expected", v);
+    }
   }
   return string(v.string.s);
 }
@@ -1437,11 +1470,17 @@ string EvalState::forceStringNoCtx(Value& v, const Pos& pos) {
 }
 
 bool EvalState::isDerivation(Value& v) {
-  if (v.type != tAttrs) return false;
+  if (v.type != tAttrs) {
+    return false;
+  }
   Bindings::iterator i = v.attrs->find(sType);
-  if (i == v.attrs->end()) return false;
+  if (i == v.attrs->end()) {
+    return false;
+  }
   forceValue(*i->value);
-  if (i->value->type != tString) return false;
+  if (i->value->type != tString) {
+    return false;
+  }
   return strcmp(i->value->string.s, "derivation") == 0;
 }
 
@@ -1556,14 +1595,22 @@ bool EvalState::eqValues(Value& v1, Value& v2) {
   /* !!! Hack to support some old broken code that relies on pointer
      equality tests between sets.  (Specifically, builderDefs calls
      uniqList on a list of sets.)  Will remove this eventually. */
-  if (&v1 == &v2) return true;
+  if (&v1 == &v2) {
+    return true;
+  }
 
   // Special case type-compatibility between float and int
-  if (v1.type == tInt && v2.type == tFloat) return v1.integer == v2.fpoint;
-  if (v1.type == tFloat && v2.type == tInt) return v1.fpoint == v2.integer;
+  if (v1.type == tInt && v2.type == tFloat) {
+    return v1.integer == v2.fpoint;
+  }
+  if (v1.type == tFloat && v2.type == tInt) {
+    return v1.fpoint == v2.integer;
+  }
 
   // All other types are not compatible with each other.
-  if (v1.type != v2.type) return false;
+  if (v1.type != v2.type) {
+    return false;
+  }
 
   switch (v1.type) {
     case tInt:
@@ -1584,9 +1631,14 @@ bool EvalState::eqValues(Value& v1, Value& v2) {
     case tList1:
     case tList2:
     case tListN:
-      if (v1.listSize() != v2.listSize()) return false;
-      for (size_t n = 0; n < v1.listSize(); ++n)
-        if (!eqValues(*v1.listElems()[n], *v2.listElems()[n])) return false;
+      if (v1.listSize() != v2.listSize()) {
+        return false;
+      }
+      for (size_t n = 0; n < v1.listSize(); ++n) {
+        if (!eqValues(*v1.listElems()[n], *v2.listElems()[n])) {
+          return false;
+        }
+      }
       return true;
 
     case tAttrs: {
@@ -1595,17 +1647,21 @@ bool EvalState::eqValues(Value& v1, Value& v2) {
       if (isDerivation(v1) && isDerivation(v2)) {
         Bindings::iterator i = v1.attrs->find(sOutPath);
         Bindings::iterator j = v2.attrs->find(sOutPath);
-        if (i != v1.attrs->end() && j != v2.attrs->end())
+        if (i != v1.attrs->end() && j != v2.attrs->end()) {
           return eqValues(*i->value, *j->value);
+        }
       }
 
-      if (v1.attrs->size() != v2.attrs->size()) return false;
+      if (v1.attrs->size() != v2.attrs->size()) {
+        return false;
+      }
 
       /* Otherwise, compare the attributes one by one. */
       Bindings::iterator i, j;
       for (i = v1.attrs->begin(), j = v2.attrs->begin(); i != v1.attrs->end();
-           ++i, ++j)
+           ++i, ++j) {
         if (i->name != j->name || !eqValues(*i->value, *j->value)) return false;
+      }
 
       return true;
     }
diff --git a/third_party/nix/src/libexpr/get-drvs.cc b/third_party/nix/src/libexpr/get-drvs.cc
index 77b6ee2014e9..16bb03f1d16f 100644
--- a/third_party/nix/src/libexpr/get-drvs.cc
+++ b/third_party/nix/src/libexpr/get-drvs.cc
@@ -94,13 +94,16 @@ DrvInfo::Outputs DrvInfo::queryOutputs(bool onlyOutputsToInstall) {
         string name =
             state->forceStringNoCtx(*i->value->listElems()[j], *i->pos);
         Bindings::iterator out = attrs->find(state->symbols.create(name));
-        if (out == attrs->end()) continue;  // FIXME: throw error?
+        if (out == attrs->end()) {
+          continue;  // FIXME: throw error?
+        }
         state->forceAttrs(*out->value);
 
         /* And evaluate its ‘outPath’ attribute. */
         Bindings::iterator outPath = out->value->attrs->find(state->sOutPath);
-        if (outPath == out->value->attrs->end())
+        if (outPath == out->value->attrs->end()) {
           continue;  // FIXME: throw error?
+        }
         PathSet context;
         outputs[name] =
             state->coerceToPath(*outPath->pos, *outPath->value, context);
@@ -108,11 +111,15 @@ DrvInfo::Outputs DrvInfo::queryOutputs(bool onlyOutputsToInstall) {
     } else
       outputs["out"] = queryOutPath();
   }
-  if (!onlyOutputsToInstall || !attrs) return outputs;
+  if (!onlyOutputsToInstall || !attrs) {
+    return outputs;
+  }
 
   /* Check for `meta.outputsToInstall` and return `outputs` reduced to that. */
   const Value* outTI = queryMeta("outputsToInstall");
-  if (!outTI) return outputs;
+  if (!outTI) {
+    return outputs;
+  }
   const auto errMsg = Error("this derivation has bad 'meta.outputsToInstall'");
   /* ^ this shows during `nix-env -i` right under the bad derivation */
   if (!outTI->isList()) throw errMsg;
@@ -136,10 +143,16 @@ string DrvInfo::queryOutputName() const {
 }
 
 Bindings* DrvInfo::getMeta() {
-  if (meta) return meta;
-  if (!attrs) return 0;
+  if (meta) {
+    return meta;
+  }
+  if (!attrs) {
+    return 0;
+  }
   Bindings::iterator a = attrs->find(state->sMeta);
-  if (a == attrs->end()) return 0;
+  if (a == attrs->end()) {
+    return 0;
+  }
   state->forceAttrs(*a->value, *a->pos);
   meta = a->value->attrs;
   return meta;
@@ -147,7 +160,9 @@ Bindings* DrvInfo::getMeta() {
 
 StringSet DrvInfo::queryMetaNames() {
   StringSet res;
-  if (!getMeta()) return res;
+  if (!getMeta()) {
+    return res;
+  }
   for (auto& i : *meta) res.insert(i.name);
   return res;
 }
@@ -155,24 +170,37 @@ StringSet DrvInfo::queryMetaNames() {
 bool DrvInfo::checkMeta(Value& v) {
   state->forceValue(v);
   if (v.isList()) {
-    for (unsigned int n = 0; n < v.listSize(); ++n)
-      if (!checkMeta(*v.listElems()[n])) return false;
+    for (unsigned int n = 0; n < v.listSize(); ++n) {
+      if (!checkMeta(*v.listElems()[n])) {
+        return false;
+      }
+    }
     return true;
   } else if (v.type == tAttrs) {
     Bindings::iterator i = v.attrs->find(state->sOutPath);
-    if (i != v.attrs->end()) return false;
-    for (auto& i : *v.attrs)
-      if (!checkMeta(*i.value)) return false;
+    if (i != v.attrs->end()) {
+      return false;
+    }
+    for (auto& i : *v.attrs) {
+      if (!checkMeta(*i.value)) {
+        return false;
+      }
+    }
     return true;
-  } else
+  } else {
     return v.type == tInt || v.type == tBool || v.type == tString ||
            v.type == tFloat;
+  }
 }
 
 Value* DrvInfo::queryMeta(const string& name) {
-  if (!getMeta()) return 0;
+  if (!getMeta()) {
+    return 0;
+  }
   Bindings::iterator a = meta->find(state->symbols.create(name));
-  if (a == meta->end() || !checkMeta(*a->value)) return 0;
+  if (a == meta->end() || !checkMeta(*a->value)) {
+    return 0;
+  }
   return a->value;
 }
 
@@ -184,8 +212,12 @@ string DrvInfo::queryMetaString(const string& name) {
 
 NixInt DrvInfo::queryMetaInt(const string& name, NixInt def) {
   Value* v = queryMeta(name);
-  if (!v) return def;
-  if (v->type == tInt) return v->integer;
+  if (!v) {
+    return def;
+  }
+  if (v->type == tInt) {
+    return v->integer;
+  }
   if (v->type == tString) {
     /* Backwards compatibility with before we had support for
        integer meta fields. */
@@ -197,8 +229,12 @@ NixInt DrvInfo::queryMetaInt(const string& name, NixInt def) {
 
 NixFloat DrvInfo::queryMetaFloat(const string& name, NixFloat def) {
   Value* v = queryMeta(name);
-  if (!v) return def;
-  if (v->type == tFloat) return v->fpoint;
+  if (!v) {
+    return def;
+  }
+  if (v->type == tFloat) {
+    return v->fpoint;
+  }
   if (v->type == tString) {
     /* Backwards compatibility with before we had support for
        float meta fields. */
@@ -210,8 +246,12 @@ NixFloat DrvInfo::queryMetaFloat(const string& name, NixFloat def) {
 
 bool DrvInfo::queryMetaBool(const string& name, bool def) {
   Value* v = queryMeta(name);
-  if (!v) return def;
-  if (v->type == tBool) return v->boolean;
+  if (!v) {
+    return def;
+  }
+  if (v->type == tBool) {
+    return v->boolean;
+  }
   if (v->type == tString) {
     /* Backwards compatibility with before we had support for
        Boolean meta fields. */
@@ -226,10 +266,14 @@ void DrvInfo::setMeta(const string& name, Value* v) {
   Bindings* old = meta;
   meta = state->allocBindings(1 + (old ? old->size() : 0));
   Symbol sym = state->symbols.create(name);
-  if (old)
-    for (auto i : *old)
+  if (old) {
+    for (auto i : *old) {
       if (i.name != sym) meta->push_back(i);
-  if (v) meta->push_back(Attr(sym, v));
+    }
+  }
+  if (v) {
+    meta->push_back(Attr(sym, v));
+  }
   meta->sort();
 }
 
@@ -245,7 +289,9 @@ static bool getDerivation(EvalState& state, Value& v, const string& attrPath,
                           bool ignoreAssertionFailures) {
   try {
     state.forceValue(v);
-    if (!state.isDerivation(v)) return true;
+    if (!state.isDerivation(v)) {
+      return true;
+    }
 
     /* Remove spurious duplicates (e.g., a set like `rec { x =
        derivation {...}; y = x;}'. */
@@ -261,7 +307,9 @@ static bool getDerivation(EvalState& state, Value& v, const string& attrPath,
     return false;
 
   } catch (AssertionError& e) {
-    if (ignoreAssertionFailures) return false;
+    if (ignoreAssertionFailures) {
+      return false;
+    }
     throw;
   }
 }
@@ -338,10 +386,12 @@ static void getDerivations(EvalState& state, Value& vIn,
     }
   }
 
-  else
-    throw TypeError(
-        "expression does not evaluate to a derivation (or a set or list of "
-        "those)");
+  else {
+    throw
+  }
+  TypeError(
+      "expression does not evaluate to a derivation (or a set or list of "
+      "those)");
 }
 
 void getDerivations(EvalState& state, Value& v, const string& pathPrefix,
diff --git a/third_party/nix/src/libexpr/json-to-value.cc b/third_party/nix/src/libexpr/json-to-value.cc
index a6c12fd8244c..e7c7794d1181 100644
--- a/third_party/nix/src/libexpr/json-to-value.cc
+++ b/third_party/nix/src/libexpr/json-to-value.cc
@@ -5,7 +5,9 @@
 namespace nix {
 
 static void skipWhitespace(const char*& s) {
-  while (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r') s++;
+  while (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r') {
+    s++;
+  }
 }
 
 static string parseJSONString(const char*& s) {
@@ -39,8 +41,10 @@ static string parseJSONString(const char*& s) {
       else
         throw JSONParseError("invalid escaped character in JSON string");
       s++;
-    } else
-      res += *s++;
+    } else {
+      res
+    }
+    += *s++;
   }
   s++;
   return res;
@@ -62,7 +66,9 @@ static void parseJSON(EvalState& state, const char*& s, Value& v) {
       parseJSON(state, s, *v2);
       values.push_back(v2);
       skipWhitespace(s);
-      if (*s == ']') break;
+      if (*s == ']') {
+        break;
+      }
       if (*s != ',')
         throw JSONParseError("expected ',' or ']' after JSON array element");
       s++;
@@ -86,7 +92,9 @@ static void parseJSON(EvalState& state, const char*& s, Value& v) {
       parseJSON(state, s, *v2);
       attrs[state.symbols.create(name)] = v2;
       skipWhitespace(s);
-      if (*s == '}') break;
+      if (*s == '}') {
+        break;
+      }
       if (*s != ',')
         throw JSONParseError("expected ',' or '}' after JSON member");
       s++;
diff --git a/third_party/nix/src/libexpr/names.cc b/third_party/nix/src/libexpr/names.cc
index 8e198f0925ca..66a918de5dc2 100644
--- a/third_party/nix/src/libexpr/names.cc
+++ b/third_party/nix/src/libexpr/names.cc
@@ -57,21 +57,23 @@ static bool componentsLT(const string& c1, const string& c2) {
   int n1, n2;
   bool c1Num = string2Int(c1, n1), c2Num = string2Int(c2, n2);
 
-  if (c1Num && c2Num)
+  if (c1Num && c2Num) {
     return n1 < n2;
-  else if (c1 == "" && c2Num)
+  } else if (c1 == "" && c2Num)
     return true;
   else if (c1 == "pre" && c2 != "pre")
     return true;
   else if (c2 == "pre")
     return false;
   /* Assume that `2.3a' < `2.3.1'. */
-  else if (c2Num)
+  else if (c2Num) {
     return true;
-  else if (c1Num)
+  } else if (c1Num) {
     return false;
-  else
-    return c1 < c2;
+  } else {
+    return
+  }
+  c1 < c2;
 }
 
 int compareVersions(const string& v1, const string& v2) {
diff --git a/third_party/nix/src/libexpr/nixexpr.cc b/third_party/nix/src/libexpr/nixexpr.cc
index 8f1dbbb6db05..85e80361e3ab 100644
--- a/third_party/nix/src/libexpr/nixexpr.cc
+++ b/third_party/nix/src/libexpr/nixexpr.cc
@@ -208,7 +208,9 @@ void ExprVar::bindVars(const StaticEnv& env) {
   int withLevel = -1;
   for (curEnv = &env, level = 0; curEnv; curEnv = curEnv->up, level++) {
     if (curEnv->isWith) {
-      if (withLevel == -1) withLevel = level;
+      if (withLevel == -1) {
+        withLevel = level;
+      }
     } else {
       StaticEnv::Vars::const_iterator i = curEnv->vars.find(name);
       if (i != curEnv->vars.end()) {
@@ -233,7 +235,9 @@ void ExprVar::bindVars(const StaticEnv& env) {
 
 void ExprSelect::bindVars(const StaticEnv& env) {
   e->bindVars(env);
-  if (def) def->bindVars(env);
+  if (def) {
+    def->bindVars(env);
+  }
   for (auto& i : attrPath)
     if (!i.symbol.set()) i.expr->bindVars(env);
 }
@@ -258,8 +262,10 @@ void ExprAttrs::bindVars(const StaticEnv& env) {
       i.second.e->bindVars(i.second.inherited ? env : newEnv);
   }
 
-  else
-    for (auto& i : attrs) i.second.e->bindVars(env);
+  else {
+    for
+  }
+  (auto& i : attrs) i.second.e->bindVars(env);
 
   for (auto& i : dynamicAttrs) {
     i.nameExpr->bindVars(*dynamicEnv);
@@ -307,11 +313,12 @@ void ExprWith::bindVars(const StaticEnv& env) {
   const StaticEnv* curEnv;
   unsigned int level;
   prevWith = 0;
-  for (curEnv = &env, level = 1; curEnv; curEnv = curEnv->up, level++)
+  for (curEnv = &env, level = 1; curEnv; curEnv = curEnv->up, level++) {
     if (curEnv->isWith) {
       prevWith = level;
       break;
     }
+  }
 
   attrs->bindVars(env);
   StaticEnv newEnv(true, &env);
diff --git a/third_party/nix/src/libexpr/nixexpr.hh b/third_party/nix/src/libexpr/nixexpr.hh
index 349e633ede73..8817e745b199 100644
--- a/third_party/nix/src/libexpr/nixexpr.hh
+++ b/third_party/nix/src/libexpr/nixexpr.hh
@@ -23,13 +23,25 @@ MakeError(EvalError, Error) MakeError(ParseError, Error)
       : file(file), line(line), column(column){};
   operator bool() const { return line != 0; }
   bool operator<(const Pos& p2) const {
-    if (!line) return p2.line;
-    if (!p2.line) return false;
+    if (!line) {
+      return p2.line;
+    }
+    if (!p2.line) {
+      return false;
+    }
     int d = ((string)file).compare((string)p2.file);
-    if (d < 0) return true;
-    if (d > 0) return false;
-    if (line < p2.line) return true;
-    if (line > p2.line) return false;
+    if (d < 0) {
+      return true;
+    }
+    if (d > 0) {
+      return false;
+    }
+    if (line < p2.line) {
+      return true;
+    }
+    if (line > p2.line) {
+      return false;
+    }
     return column < p2.column;
   }
 };
diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc
index e7778ed32a1c..98a6f56dfdf3 100644
--- a/third_party/nix/src/libexpr/primops.cc
+++ b/third_party/nix/src/libexpr/primops.cc
@@ -129,9 +129,9 @@ static void prim_scopedImport(EvalState& state, const Pos& pos, Value** args,
     state.forceAttrs(v, pos);
   } else {
     state.forceAttrs(*args[0]);
-    if (args[0]->attrs->empty())
+    if (args[0]->attrs->empty()) {
       state.evalFile(realPath, v);
-    else {
+    } else {
       Env* env = &state.allocEnv(args[0]->attrs->size());
       env->up = &state.baseEnv;
 
@@ -346,8 +346,12 @@ static void prim_isPath(EvalState& state, const Pos& pos, Value** args,
 
 struct CompareValues {
   bool operator()(const Value* v1, const Value* v2) const {
-    if (v1->type == tFloat && v2->type == tInt) return v1->fpoint < v2->integer;
-    if (v1->type == tInt && v2->type == tFloat) return v1->integer < v2->fpoint;
+    if (v1->type == tFloat && v2->type == tInt) {
+      return v1->fpoint < v2->integer;
+    }
+    if (v1->type == tInt && v2->type == tFloat) {
+      return v1->integer < v2->fpoint;
+    }
     if (v1->type != v2->type)
       throw EvalError(format("cannot compare %1% with %2%") % showType(*v1) %
                       showType(*v2));
@@ -562,8 +566,9 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
   /* Check whether null attributes should be ignored. */
   bool ignoreNulls = false;
   attr = args[0]->attrs->find(state.sIgnoreNulls);
-  if (attr != args[0]->attrs->end())
+  if (attr != args[0]->attrs->end()) {
     ignoreNulls = state.forceBool(*attr->value, pos);
+  }
 
   /* Build the derivation expression by processing the attributes. */
   Derivation drv;
@@ -890,10 +895,11 @@ static void prim_dirOf(EvalState& state, const Pos& pos, Value** args,
                        Value& v) {
   PathSet context;
   Path dir = dirOf(state.coerceToString(pos, *args[0], context, false, false));
-  if (args[0]->type == tPath)
+  if (args[0]->type == tPath) {
     mkPath(v, dir.c_str());
-  else
+  } else {
     mkString(v, dir, context);
+  }
 }
 
 /* Return the contents of a file as a string. */
@@ -1208,14 +1214,17 @@ static void prim_attrValues(EvalState& state, const Pos& pos, Value** args,
   state.mkList(v, args[0]->attrs->size());
 
   unsigned int n = 0;
-  for (auto& i : *args[0]->attrs) v.listElems()[n++] = (Value*)&i;
+  for (auto& i : *args[0]->attrs) {
+    v.listElems()[n++] = (Value*)&i;
+  }
 
   std::sort(v.listElems(), v.listElems() + n, [](Value* v1, Value* v2) {
     return (string)((Attr*)v1)->name < (string)((Attr*)v2)->name;
   });
 
-  for (unsigned int i = 0; i < n; ++i)
+  for (unsigned int i = 0; i < n; ++i) {
     v.listElems()[i] = ((Attr*)v.listElems()[i])->value;
+  }
 }
 
 /* Dynamic version of the `.' operator. */
@@ -1238,10 +1247,11 @@ void prim_unsafeGetAttrPos(EvalState& state, const Pos& pos, Value** args,
   string attr = state.forceStringNoCtx(*args[0], pos);
   state.forceAttrs(*args[1], pos);
   Bindings::iterator i = args[1]->attrs->find(state.symbols.create(attr));
-  if (i == args[1]->attrs->end())
+  if (i == args[1]->attrs->end()) {
     mkNull(v);
-  else
+  } else {
     state.mkPos(v, i->pos);
+  }
 }
 
 /* Dynamic version of the `?' operator. */
@@ -1335,7 +1345,9 @@ static void prim_intersectAttrs(EvalState& state, const Pos& pos, Value** args,
 
   for (auto& i : *args[0]->attrs) {
     Bindings::iterator j = args[1]->attrs->find(i.name);
-    if (j != args[1]->attrs->end()) v.attrs->push_back(*j);
+    if (j != args[1]->attrs->end()) {
+      v.attrs->push_back(*j);
+    }
   }
 }
 
@@ -1358,11 +1370,15 @@ static void prim_catAttrs(EvalState& state, const Pos& pos, Value** args,
     Value& v2(*args[1]->listElems()[n]);
     state.forceAttrs(v2, pos);
     Bindings::iterator i = v2.attrs->find(attrName);
-    if (i != v2.attrs->end()) res[found++] = i->value;
+    if (i != v2.attrs->end()) {
+      res[found++] = i->value;
+    }
   }
 
   state.mkList(v, found);
-  for (unsigned int n = 0; n < found; ++n) v.listElems()[n] = res[n];
+  for (unsigned int n = 0; n < found; ++n) {
+    v.listElems()[n] = res[n];
+  }
 }
 
 /* Return a set containing the names of the formal arguments expected
@@ -1454,8 +1470,9 @@ static void prim_tail(EvalState& state, const Pos& pos, Value** args,
   if (args[0]->listSize() == 0)
     throw Error(format("'tail' called on an empty list, at %1%") % pos);
   state.mkList(v, args[0]->listSize() - 1);
-  for (unsigned int n = 0; n < v.listSize(); ++n)
+  for (unsigned int n = 0; n < v.listSize(); ++n) {
     v.listElems()[n] = args[0]->listElems()[n + 1];
+  }
 }
 
 /* Apply a function to every element of a list. */
@@ -1464,9 +1481,10 @@ static void prim_map(EvalState& state, const Pos& pos, Value** args, Value& v) {
 
   state.mkList(v, args[1]->listSize());
 
-  for (unsigned int n = 0; n < v.listSize(); ++n)
+  for (unsigned int n = 0; n < v.listSize(); ++n) {
     mkApp(*(v.listElems()[n] = state.allocValue()), *args[0],
           *args[1]->listElems()[n]);
+  }
 }
 
 /* Filter a list using a predicate; that is, return a list containing
@@ -1485,17 +1503,20 @@ static void prim_filter(EvalState& state, const Pos& pos, Value** args,
   for (unsigned int n = 0; n < args[1]->listSize(); ++n) {
     Value res;
     state.callFunction(*args[0], *args[1]->listElems()[n], res, noPos);
-    if (state.forceBool(res, pos))
+    if (state.forceBool(res, pos)) {
       vs[k++] = args[1]->listElems()[n];
-    else
+    } else {
       same = false;
+    }
   }
 
-  if (same)
+  if (same) {
     v = *args[1];
-  else {
+  } else {
     state.mkList(v, k);
-    for (unsigned int n = 0; n < k; ++n) v.listElems()[n] = vs[n];
+    for (unsigned int n = 0; n < k; ++n) {
+      v.listElems()[n] = vs[n];
+    }
   }
 }
 
@@ -1504,11 +1525,12 @@ static void prim_elem(EvalState& state, const Pos& pos, Value** args,
                       Value& v) {
   bool res = false;
   state.forceList(*args[1], pos);
-  for (unsigned int n = 0; n < args[1]->listSize(); ++n)
+  for (unsigned int n = 0; n < args[1]->listSize(); ++n) {
     if (state.eqValues(*args[0], *args[1]->listElems()[n])) {
       res = true;
       break;
     }
+  }
   mkBool(v, res);
 }
 
@@ -1610,8 +1632,9 @@ static void prim_sort(EvalState& state, const Pos& pos, Value** args,
   auto comparator = [&](Value* a, Value* b) {
     /* Optimization: if the comparator is lessThan, bypass
        callFunction. */
-    if (args[0]->type == tPrimOp && args[0]->primOp->fun == prim_lessThan)
+    if (args[0]->type == tPrimOp && args[0]->primOp->fun == prim_lessThan) {
       return CompareValues()(a, b);
+    }
 
     Value vTmp1, vTmp2;
     state.callFunction(*args[0], *a, vTmp1, pos);
@@ -1694,31 +1717,34 @@ static void prim_concatMap(EvalState& state, const Pos& pos, Value** args,
 static void prim_add(EvalState& state, const Pos& pos, Value** args, Value& v) {
   state.forceValue(*args[0], pos);
   state.forceValue(*args[1], pos);
-  if (args[0]->type == tFloat || args[1]->type == tFloat)
+  if (args[0]->type == tFloat || args[1]->type == tFloat) {
     mkFloat(v,
             state.forceFloat(*args[0], pos) + state.forceFloat(*args[1], pos));
-  else
+  } else {
     mkInt(v, state.forceInt(*args[0], pos) + state.forceInt(*args[1], pos));
+  }
 }
 
 static void prim_sub(EvalState& state, const Pos& pos, Value** args, Value& v) {
   state.forceValue(*args[0], pos);
   state.forceValue(*args[1], pos);
-  if (args[0]->type == tFloat || args[1]->type == tFloat)
+  if (args[0]->type == tFloat || args[1]->type == tFloat) {
     mkFloat(v,
             state.forceFloat(*args[0], pos) - state.forceFloat(*args[1], pos));
-  else
+  } else {
     mkInt(v, state.forceInt(*args[0], pos) - state.forceInt(*args[1], pos));
+  }
 }
 
 static void prim_mul(EvalState& state, const Pos& pos, Value** args, Value& v) {
   state.forceValue(*args[0], pos);
   state.forceValue(*args[1], pos);
-  if (args[0]->type == tFloat || args[1]->type == tFloat)
+  if (args[0]->type == tFloat || args[1]->type == tFloat) {
     mkFloat(v,
             state.forceFloat(*args[0], pos) * state.forceFloat(*args[1], pos));
-  else
+  } else {
     mkInt(v, state.forceInt(*args[0], pos) * state.forceInt(*args[1], pos));
+  }
 }
 
 static void prim_div(EvalState& state, const Pos& pos, Value** args, Value& v) {
@@ -1937,10 +1963,12 @@ static void prim_concatStringSep(EvalState& state, const Pos& pos, Value** args,
   bool first = true;
 
   for (unsigned int n = 0; n < args[1]->listSize(); ++n) {
-    if (first)
+    if (first) {
       first = false;
-    else
-      res += sep;
+    } else {
+      res
+    }
+    += sep;
     res += state.coerceToString(pos, *args[1]->listElems()[n], context);
   }
 
@@ -2074,8 +2102,10 @@ void fetch(EvalState& state, const Pos& pos, Value** args, Value& v,
     if (request.uri.empty())
       throw EvalError(format("'url' argument required, at %1%") % pos);
 
-  } else
-    request.uri = state.forceStringNoCtx(*args[0], pos);
+  } else {
+    request
+  }
+  .uri = state.forceStringNoCtx(*args[0], pos);
 
   state.checkURI(request.uri);
 
diff --git a/third_party/nix/src/libexpr/primops/fetchGit.cc b/third_party/nix/src/libexpr/primops/fetchGit.cc
index b707202c9085..af3f89fde77a 100644
--- a/third_party/nix/src/libexpr/primops/fetchGit.cc
+++ b/third_party/nix/src/libexpr/primops/fetchGit.cc
@@ -227,8 +227,10 @@ static void prim_fetchGit(EvalState& state, const Pos& pos, Value** args,
     if (url.empty())
       throw EvalError(format("'url' argument required, at %1%") % pos);
 
-  } else
-    url = state.coerceToString(pos, *args[0], context, false, false);
+  } else {
+    url
+  }
+  = state.coerceToString(pos, *args[0], context, false, false);
 
   // FIXME: git externals probably can be used to bypass the URI
   // whitelist. Ah well.
diff --git a/third_party/nix/src/libexpr/primops/fetchMercurial.cc b/third_party/nix/src/libexpr/primops/fetchMercurial.cc
index dad2d597ecc7..5847f6021f43 100644
--- a/third_party/nix/src/libexpr/primops/fetchMercurial.cc
+++ b/third_party/nix/src/libexpr/primops/fetchMercurial.cc
@@ -203,8 +203,10 @@ static void prim_fetchMercurial(EvalState& state, const Pos& pos, Value** args,
     if (url.empty())
       throw EvalError(format("'url' argument required, at %1%") % pos);
 
-  } else
-    url = state.coerceToString(pos, *args[0], context, false, false);
+  } else {
+    url
+  }
+  = state.coerceToString(pos, *args[0], context, false, false);
 
   // FIXME: git externals probably can be used to bypass the URI
   // whitelist. Ah well.
diff --git a/third_party/nix/src/libexpr/value-to-json.cc b/third_party/nix/src/libexpr/value-to-json.cc
index e9a39b8aaad6..3da47dc2f85a 100644
--- a/third_party/nix/src/libexpr/value-to-json.cc
+++ b/third_party/nix/src/libexpr/value-to-json.cc
@@ -13,7 +13,9 @@ void printValueAsJSON(EvalState& state, bool strict, Value& v,
                       JSONPlaceholder& out, PathSet& context) {
   checkInterrupt();
 
-  if (strict) state.forceValue(v);
+  if (strict) {
+    state.forceValue(v);
+  }
 
   switch (v.type) {
     case tInt:
diff --git a/third_party/nix/src/libexpr/value-to-xml.cc b/third_party/nix/src/libexpr/value-to-xml.cc
index 80c4adb78ff9..5ea1e09824c7 100644
--- a/third_party/nix/src/libexpr/value-to-xml.cc
+++ b/third_party/nix/src/libexpr/value-to-xml.cc
@@ -48,7 +48,9 @@ static void printValueAsXML(EvalState& state, bool strict, bool location,
                             PathSet& drvsSeen) {
   checkInterrupt();
 
-  if (strict) state.forceValue(v);
+  if (strict) {
+    state.forceValue(v);
+  }
 
   switch (v.type) {
     case tInt:
@@ -85,14 +87,18 @@ static void printValueAsXML(EvalState& state, bool strict, bool location,
         Path drvPath;
         a = v.attrs->find(state.sDrvPath);
         if (a != v.attrs->end()) {
-          if (strict) state.forceValue(*a->value);
+          if (strict) {
+            state.forceValue(*a->value);
+          }
           if (a->value->type == tString)
             xmlAttrs["drvPath"] = drvPath = a->value->string.s;
         }
 
         a = v.attrs->find(state.sOutPath);
         if (a != v.attrs->end()) {
-          if (strict) state.forceValue(*a->value);
+          if (strict) {
+            state.forceValue(*a->value);
+          }
           if (a->value->type == tString)
             xmlAttrs["outPath"] = a->value->string.s;
         }
@@ -117,9 +123,10 @@ static void printValueAsXML(EvalState& state, bool strict, bool location,
     case tList2:
     case tListN: {
       XMLOpenElement _(doc, "list");
-      for (unsigned int n = 0; n < v.listSize(); ++n)
+      for (unsigned int n = 0; n < v.listSize(); ++n) {
         printValueAsXML(state, strict, location, *v.listElems()[n], doc,
                         context, drvsSeen);
+      }
       break;
     }
 
@@ -135,9 +142,10 @@ static void printValueAsXML(EvalState& state, bool strict, bool location,
         XMLOpenElement _(doc, "attrspat", attrs);
         for (auto& i : v.lambda.fun->formals->formals)
           doc.writeEmptyElement("attr", singletonAttrs("name", i.name));
-      } else
-        doc.writeEmptyElement("varpat",
-                              singletonAttrs("name", v.lambda.fun->arg));
+      } else {
+        doc
+      }
+      .writeEmptyElement("varpat", singletonAttrs("name", v.lambda.fun->arg));
 
       break;
     }