about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/nix/src/libexpr')
-rw-r--r--third_party/nix/src/libexpr/attr-path.cc12
-rw-r--r--third_party/nix/src/libexpr/attr-set.hh4
-rw-r--r--third_party/nix/src/libexpr/eval-inline.hh4
-rw-r--r--third_party/nix/src/libexpr/eval.cc132
-rw-r--r--third_party/nix/src/libexpr/get-drvs.cc52
-rw-r--r--third_party/nix/src/libexpr/json-to-value.cc28
-rw-r--r--third_party/nix/src/libexpr/lexer.l8
-rw-r--r--third_party/nix/src/libexpr/names.cc12
-rw-r--r--third_party/nix/src/libexpr/nixexpr.cc36
-rw-r--r--third_party/nix/src/libexpr/parser.y20
-rw-r--r--third_party/nix/src/libexpr/primops.cc104
-rw-r--r--third_party/nix/src/libexpr/primops/context.cc12
-rw-r--r--third_party/nix/src/libexpr/primops/fetchGit.cc12
-rw-r--r--third_party/nix/src/libexpr/primops/fetchMercurial.cc8
-rw-r--r--third_party/nix/src/libexpr/value-to-xml.cc8
15 files changed, 332 insertions, 120 deletions
diff --git a/third_party/nix/src/libexpr/attr-path.cc b/third_party/nix/src/libexpr/attr-path.cc
index 584f49d124ef..edab0b6df97f 100644
--- a/third_party/nix/src/libexpr/attr-path.cc
+++ b/third_party/nix/src/libexpr/attr-path.cc
@@ -19,14 +19,18 @@ static Strings parseAttrPath(const string& s) {
         if (i == s.end())
           throw Error(format("missing closing quote in selection path '%1%'") %
                       s);
-        if (*i == '"') break;
+        if (*i == '"') {
+          break;
+        }
         cur.push_back(*i++);
       }
     } else
       cur.push_back(*i);
     ++i;
   }
-  if (!cur.empty()) res.push_back(cur);
+  if (!cur.empty()) {
+    res.push_back(cur);
+  }
   return res;
 }
 
@@ -44,7 +48,9 @@ Value* findAlongAttrPath(EvalState& state, const string& attrPath,
     /* Is i an index (integer) or a normal attribute name? */
     enum { apAttr, apIndex } apType = apAttr;
     unsigned int attrIndex;
-    if (string2Int(attr, attrIndex)) apType = apIndex;
+    if (string2Int(attr, attrIndex)) {
+      apType = apIndex;
+    }
 
     /* Evaluate the expression. */
     Value* vNew = state.allocValue();
diff --git a/third_party/nix/src/libexpr/attr-set.hh b/third_party/nix/src/libexpr/attr-set.hh
index e5a888d7e981..74a41a7e5d94 100644
--- a/third_party/nix/src/libexpr/attr-set.hh
+++ b/third_party/nix/src/libexpr/attr-set.hh
@@ -51,7 +51,9 @@ class Bindings {
   iterator find(const Symbol& name) {
     Attr key(name, 0);
     iterator i = std::lower_bound(begin(), end(), key);
-    if (i != end() && i->name == name) return i;
+    if (i != end() && i->name == name) {
+      return i;
+    }
     return end();
   }
 
diff --git a/third_party/nix/src/libexpr/eval-inline.hh b/third_party/nix/src/libexpr/eval-inline.hh
index d92614ca7ca6..ca0cf2a3607a 100644
--- a/third_party/nix/src/libexpr/eval-inline.hh
+++ b/third_party/nix/src/libexpr/eval-inline.hh
@@ -81,7 +81,9 @@ inline void* allocBytes(size_t n) {
 #else
   p = calloc(n, 1);
 #endif
-  if (!p) throw std::bad_alloc();
+  if (!p) {
+    throw std::bad_alloc();
+  }
   return p;
 }
 
diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc
index 5d6f30c07d0c..a1965e08052b 100644
--- a/third_party/nix/src/libexpr/eval.cc
+++ b/third_party/nix/src/libexpr/eval.cc
@@ -37,7 +37,9 @@ static char* dupString(const char* s) {
 #else
   t = strdup(s);
 #endif
-  if (!t) throw std::bad_alloc();
+  if (!t) {
+    throw std::bad_alloc();
+  }
   return t;
 }
 
@@ -201,7 +203,9 @@ static Symbol getName(const AttrName& name, EvalState& state, Env& env) {
 static bool gcInitialised = false;
 
 void initGC() {
-  if (gcInitialised) return;
+  if (gcInitialised) {
+    return;
+  }
 
 #if HAVE_BOEHMGC
   /* Initialise the Boehm garbage collector. */
@@ -233,8 +237,12 @@ void initGC() {
     size_t maxSize = 384 * 1024 * 1024;
     long pageSize = sysconf(_SC_PAGESIZE);
     long pages = sysconf(_SC_PHYS_PAGES);
-    if (pageSize != -1) size = (pageSize * pages) / 4;  // 25% of RAM
-    if (size > maxSize) size = maxSize;
+    if (pageSize != -1) {
+      size = (pageSize * pages) / 4;
+    }  // 25% of RAM
+    if (size > maxSize) {
+      size = maxSize;
+    }
 #endif
     DLOG(INFO) << "setting initial heap size to " << size << " bytes";
     GC_expand_hp(size);
@@ -257,12 +265,16 @@ static Strings parseNixPath(const string& s) {
     auto start2 = p;
 
     while (p != s.end() && *p != ':') {
-      if (*p == '=') start2 = p + 1;
+      if (*p == '=') {
+        start2 = p + 1;
+      }
       ++p;
     }
 
     if (p == s.end()) {
-      if (p != start) res.push_back(std::string(start, p));
+      if (p != start) {
+        res.push_back(std::string(start, p));
+      }
       break;
     }
 
@@ -272,7 +284,9 @@ static Strings parseNixPath(const string& s) {
         while (p != s.end() && *p != ':') ++p;
       }
       res.push_back(std::string(start, p));
-      if (p == s.end()) break;
+      if (p == s.end()) {
+        break;
+      }
     }
 
     ++p;
@@ -331,7 +345,9 @@ EvalState::EvalState(const Strings& _searchPath, ref<Store> store)
 
     for (auto& i : searchPath) {
       auto r = resolveSearchPathElem(i);
-      if (!r.first) continue;
+      if (!r.first) {
+        continue;
+      }
 
       auto path = r.second;
 
@@ -354,10 +370,14 @@ EvalState::EvalState(const Strings& _searchPath, ref<Store> store)
 EvalState::~EvalState() {}
 
 Path EvalState::checkSourcePath(const Path& path_) {
-  if (!allowedPaths) return path_;
+  if (!allowedPaths) {
+    return path_;
+  }
 
   auto i = resolvedPaths.find(path_);
-  if (i != resolvedPaths.end()) return i->second;
+  if (i != resolvedPaths.end()) {
+    return i->second;
+  }
 
   bool found = false;
 
@@ -394,7 +414,9 @@ Path EvalState::checkSourcePath(const Path& path_) {
 }
 
 void EvalState::checkURI(const std::string& uri) {
-  if (!evalSettings.restrictEval) return;
+  if (!evalSettings.restrictEval) {
+    return;
+  }
 
   /* 'uri' should be equal to a prefix, or in a subdirectory of a
      prefix. Thus, the prefix https://github.co does not permit
@@ -565,7 +587,9 @@ inline Value* EvalState::lookupVar(Env* env, const ExprVar& var, bool noEval) {
     }
     Bindings::iterator j = env->values[0]->attrs->find(var.name);
     if (j != env->values[0]->attrs->end()) {
-      if (countCalls && j->pos) attrSelects[*j->pos]++;
+      if (countCalls && j->pos) {
+        attrSelects[*j->pos]++;
+      }
       return j->value;
     }
     if (!env->prevWith)
@@ -703,7 +727,9 @@ void EvalState::evalFile(const Path& path_, Value& v) {
   Expr* e = nullptr;
 
   auto j = fileParseCache.find(path2);
-  if (j != fileParseCache.end()) e = j->second;
+  if (j != fileParseCache.end()) {
+    e = j->second;
+  }
 
   if (!e) {
     e = parseExprFromFile(checkSourcePath(path2));
@@ -719,7 +745,9 @@ void EvalState::evalFile(const Path& path_, Value& v) {
   }
 
   fileEvalCache[path2] = v;
-  if (path != path2) fileEvalCache[path] = v;
+  if (path != path2) {
+    fileEvalCache[path] = v;
+  }
 }
 
 void EvalState::resetFileCache() {
@@ -831,7 +859,9 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& v) {
     Value nameVal;
     i.nameExpr->eval(state, *dynamicEnv, nameVal);
     state.forceValue(nameVal, i.pos);
-    if (nameVal.type == tNull) continue;
+    if (nameVal.type == tNull) {
+      continue;
+    }
     state.forceStringNoCtx(nameVal);
     Symbol nameSym = state.symbols.create(nameVal.string.s);
     Bindings::iterator j = v.attrs->find(nameSym);
@@ -923,7 +953,9 @@ void ExprSelect::eval(EvalState& state, Env& env, Value& v) {
       }
       vAttrs = j->value;
       pos2 = j->pos;
-      if (state.countCalls && pos2) state.attrSelects[*pos2]++;
+      if (state.countCalls && pos2) {
+        state.attrSelects[*pos2]++;
+      }
     }
 
     state.forceValue(*vAttrs, (pos2 != NULL ? *pos2 : this->pos));
@@ -999,7 +1031,9 @@ void EvalState::callPrimOp(Value& fun, Value& arg, Value& v, const Pos& pos) {
 
     /* And call the primop. */
     nrPrimOpCalls++;
-    if (countCalls) primOpCalls[primOp->primOp->name]++;
+    if (countCalls) {
+      primOpCalls[primOp->primOp->name]++;
+    }
     primOp->primOp->fun(*this, pos, vArgs, v);
   } else {
     Value* fun2 = allocValue();
@@ -1059,7 +1093,9 @@ void EvalState::callFunction(Value& fun, Value& arg, Value& v, const Pos& pos) {
   } else {
     forceAttrs(arg, pos);
 
-    if (!lambda.arg.empty()) env2.values[displ++] = &arg;
+    if (!lambda.arg.empty()) {
+      env2.values[displ++] = &arg;
+    }
 
     /* For each formal argument, get the actual argument.  If
        there is no matching actual argument but the formal
@@ -1283,7 +1319,9 @@ void EvalState::concatLists(Value& v, size_t nrLists, Value** lists,
   auto out = v.listElems();
   for (size_t n = 0, pos = 0; n < nrLists; ++n) {
     auto l = lists[n]->listSize();
-    if (l) memcpy(out + pos, lists[n]->listElems(), l * sizeof(Value*));
+    if (l) {
+      memcpy(out + pos, lists[n]->listElems(), l * sizeof(Value*));
+    }
     pos += l;
   }
 }
@@ -1361,7 +1399,9 @@ void EvalState::forceValueDeep(Value& v) {
   std::function<void(Value & v)> recurse;
 
   recurse = [&](Value& v) {
-    if (seen.find(&v) != seen.end()) return;
+    if (seen.find(&v) != seen.end()) {
+      return;
+    }
     seen.insert(&v);
 
     forceValue(v);
@@ -1526,11 +1566,21 @@ string EvalState::coerceToString(const Pos& pos, Value& v, PathSet& context,
   if (coerceMore) {
     /* Note that `false' is represented as an empty string for
        shell scripting convenience, just like `null'. */
-    if (v.type == tBool && v.boolean) return "1";
-    if (v.type == tBool && !v.boolean) return "";
-    if (v.type == tInt) return std::to_string(v.integer);
-    if (v.type == tFloat) return std::to_string(v.fpoint);
-    if (v.type == tNull) return "";
+    if (v.type == tBool && v.boolean) {
+      return "1";
+    }
+    if (v.type == tBool && !v.boolean) {
+      return "";
+    }
+    if (v.type == tInt) {
+      return std::to_string(v.integer);
+    }
+    if (v.type == tFloat) {
+      return std::to_string(v.fpoint);
+    }
+    if (v.type == tNull) {
+      return "";
+    }
 
     if (v.isList()) {
       string result;
@@ -1654,7 +1704,9 @@ bool EvalState::eqValues(Value& v1, Value& v2) {
       Bindings::iterator i, j;
       for (i = v1.attrs->begin(), j = v2.attrs->begin(); i != v1.attrs->end();
            ++i, ++j) {
-        if (i->name != j->name || !eqValues(*i->value, *j->value)) return false;
+        if (i->name != j->name || !eqValues(*i->value, *j->value)) {
+          return false;
+        }
       }
 
       return true;
@@ -1697,7 +1749,9 @@ void EvalState::printStats() {
   if (showStats) {
     auto outPath = getEnv("NIX_SHOW_STATS_PATH", "-");
     std::fstream fs;
-    if (outPath != "-") fs.open(outPath, std::fstream::out);
+    if (outPath != "-") {
+      fs.open(outPath, std::fstream::out);
+    }
     JSONObject topObj(outPath == "-" ? std::cerr : fs, true);
     topObj.attr("cpuTime", cpuTime);
     {
@@ -1796,7 +1850,9 @@ size_t valueSize(Value& v) {
   std::set<const void*> seen;
 
   auto doString = [&](const char* s) -> size_t {
-    if (seen.find(s) != seen.end()) return 0;
+    if (seen.find(s) != seen.end()) {
+      return 0;
+    }
     seen.insert(s);
     return strlen(s) + 1;
   };
@@ -1805,7 +1861,9 @@ size_t valueSize(Value& v) {
   std::function<size_t(Env & v)> doEnv;
 
   doValue = [&](Value& v) -> size_t {
-    if (seen.find(&v) != seen.end()) return 0;
+    if (seen.find(&v) != seen.end()) {
+      return 0;
+    }
     seen.insert(&v);
 
     size_t sz = sizeof(Value);
@@ -1851,7 +1909,9 @@ size_t valueSize(Value& v) {
         sz += doValue(*v.primOpApp.right);
         break;
       case tExternal:
-        if (seen.find(v.external) != seen.end()) break;
+        if (seen.find(v.external) != seen.end()) {
+          break;
+        }
         seen.insert(v.external);
         sz += v.external->valueSize(seen);
         break;
@@ -1862,16 +1922,22 @@ size_t valueSize(Value& v) {
   };
 
   doEnv = [&](Env& env) -> size_t {
-    if (seen.find(&env) != seen.end()) return 0;
+    if (seen.find(&env) != seen.end()) {
+      return 0;
+    }
     seen.insert(&env);
 
     size_t sz = sizeof(Env) + sizeof(Value*) * env.size;
 
     if (env.type != Env::HasWithExpr)
       for (size_t i = 0; i < env.size; ++i)
-        if (env.values[i]) sz += doValue(*env.values[i]);
+        if (env.values[i]) {
+          sz += doValue(*env.values[i]);
+        }
 
-    if (env.up) sz += doEnv(*env.up);
+    if (env.up) {
+      sz += doEnv(*env.up);
+    }
 
     return sz;
   };
diff --git a/third_party/nix/src/libexpr/get-drvs.cc b/third_party/nix/src/libexpr/get-drvs.cc
index ad7211eaea5b..ccbb09951f81 100644
--- a/third_party/nix/src/libexpr/get-drvs.cc
+++ b/third_party/nix/src/libexpr/get-drvs.cc
@@ -44,7 +44,9 @@ DrvInfo::DrvInfo(EvalState& state, ref<Store> store,
 string DrvInfo::queryName() const {
   if (name == "" && attrs) {
     auto i = attrs->find(state->sName);
-    if (i == attrs->end()) throw TypeError("derivation name missing");
+    if (i == attrs->end()) {
+      throw TypeError("derivation name missing");
+    }
     name = state->forceStringNoCtx(*i->value);
   }
   return name;
@@ -122,13 +124,19 @@ DrvInfo::Outputs DrvInfo::queryOutputs(bool onlyOutputsToInstall) {
   }
   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;
+  if (!outTI->isList()) {
+    throw errMsg;
+  }
   Outputs result;
   for (auto i = outTI->listElems(); i != outTI->listElems() + outTI->listSize();
        ++i) {
-    if ((*i)->type != tString) throw errMsg;
+    if ((*i)->type != tString) {
+      throw errMsg;
+    }
     auto out = outputs.find((*i)->string.s);
-    if (out == outputs.end()) throw errMsg;
+    if (out == outputs.end()) {
+      throw errMsg;
+    }
     result.insert(*out);
   }
   return result;
@@ -206,7 +214,9 @@ Value* DrvInfo::queryMeta(const string& name) {
 
 string DrvInfo::queryMetaString(const string& name) {
   Value* v = queryMeta(name);
-  if (!v || v->type != tString) return "";
+  if (!v || v->type != tString) {
+    return "";
+  }
   return v->string.s;
 }
 
@@ -222,7 +232,9 @@ NixInt DrvInfo::queryMetaInt(const string& name, NixInt def) {
     /* Backwards compatibility with before we had support for
        integer meta fields. */
     NixInt n;
-    if (string2Int(v->string.s, n)) return n;
+    if (string2Int(v->string.s, n)) {
+      return n;
+    }
   }
   return def;
 }
@@ -239,7 +251,9 @@ NixFloat DrvInfo::queryMetaFloat(const string& name, NixFloat def) {
     /* Backwards compatibility with before we had support for
        float meta fields. */
     NixFloat n;
-    if (string2Float(v->string.s, n)) return n;
+    if (string2Float(v->string.s, n)) {
+      return n;
+    }
   }
   return def;
 }
@@ -255,8 +269,12 @@ bool DrvInfo::queryMetaBool(const string& name, bool def) {
   if (v->type == tString) {
     /* Backwards compatibility with before we had support for
        Boolean meta fields. */
-    if (strcmp(v->string.s, "true") == 0) return true;
-    if (strcmp(v->string.s, "false") == 0) return false;
+    if (strcmp(v->string.s, "true") == 0) {
+      return true;
+    }
+    if (strcmp(v->string.s, "false") == 0) {
+      return false;
+    }
   }
   return def;
 }
@@ -268,7 +286,9 @@ void DrvInfo::setMeta(const string& name, Value* v) {
   Symbol sym = state->symbols.create(name);
   if (old) {
     for (auto i : *old) {
-      if (i.name != sym) meta->push_back(i);
+      if (i.name != sym) {
+        meta->push_back(i);
+      }
     }
   }
   if (v) {
@@ -295,7 +315,9 @@ static bool getDerivation(EvalState& state, Value& v, const string& attrPath,
 
     /* Remove spurious duplicates (e.g., a set like `rec { x =
        derivation {...}; y = x;}'. */
-    if (done.find(v.attrs) != done.end()) return false;
+    if (done.find(v.attrs) != done.end()) {
+      return false;
+    }
     done.insert(v.attrs);
 
     DrvInfo drv(state, attrPath, v.attrs);
@@ -319,7 +341,9 @@ std::optional<DrvInfo> getDerivation(EvalState& state, Value& v,
   Done done;
   DrvInfos drvs;
   getDerivation(state, v, "", drvs, done, ignoreAssertionFailures);
-  if (drvs.size() != 1) return {};
+  if (drvs.size() != 1) {
+    return {};
+  }
   return std::move(drvs.front());
 }
 
@@ -354,7 +378,9 @@ static void getDerivations(EvalState& state, Value& vIn,
        precedence). */
     for (auto& i : v.attrs->lexicographicOrder()) {
       DLOG(INFO) << "evaluating attribute '" << i->name << "'";
-      if (!std::regex_match(std::string(i->name), attrRegex)) continue;
+      if (!std::regex_match(std::string(i->name), attrRegex)) {
+        continue;
+      }
       string pathPrefix2 = addToPath(pathPrefix, i->name);
       if (combineChannels)
         getDerivations(state, *i->value, pathPrefix2, autoArgs, drvs, done,
diff --git a/third_party/nix/src/libexpr/json-to-value.cc b/third_party/nix/src/libexpr/json-to-value.cc
index 8d84a5ac6901..a7d9c4904c8e 100644
--- a/third_party/nix/src/libexpr/json-to-value.cc
+++ b/third_party/nix/src/libexpr/json-to-value.cc
@@ -12,9 +12,13 @@ static void skipWhitespace(const char*& s) {
 
 static string parseJSONString(const char*& s) {
   string res;
-  if (*s++ != '"') throw JSONParseError("expected JSON string");
+  if (*s++ != '"') {
+    throw JSONParseError("expected JSON string");
+  }
   while (*s != '"') {
-    if (!*s) throw JSONParseError("got end-of-string in JSON string");
+    if (!*s) {
+      throw JSONParseError("got end-of-string in JSON string");
+    }
     if (*s == '\\') {
       s++;
       if (*s == '"')
@@ -52,7 +56,9 @@ static string parseJSONString(const char*& s) {
 static void parseJSON(EvalState& state, const char*& s, Value& v) {
   skipWhitespace(s);
 
-  if (!*s) throw JSONParseError("expected JSON value");
+  if (!*s) {
+    throw JSONParseError("expected JSON value");
+  }
 
   if (*s == '[') {
     s++;
@@ -60,7 +66,9 @@ static void parseJSON(EvalState& state, const char*& s, Value& v) {
     values.reserve(128);
     skipWhitespace(s);
     while (1) {
-      if (values.empty() && *s == ']') break;
+      if (values.empty() && *s == ']') {
+        break;
+      }
       Value* v2 = state.allocValue();
       parseJSON(state, s, *v2);
       values.push_back(v2);
@@ -82,10 +90,14 @@ static void parseJSON(EvalState& state, const char*& s, Value& v) {
     ValueMap attrs;
     while (1) {
       skipWhitespace(s);
-      if (attrs.empty() && *s == '}') break;
+      if (attrs.empty() && *s == '}') {
+        break;
+      }
       string name = parseJSONString(s);
       skipWhitespace(s);
-      if (*s != ':') throw JSONParseError("expected ':' in JSON object");
+      if (*s != ':') {
+        throw JSONParseError("expected ':' in JSON object");
+      }
       s++;
       Value* v2 = state.allocValue();
       parseJSON(state, s, *v2);
@@ -114,7 +126,9 @@ static void parseJSON(EvalState& state, const char*& s, Value& v) {
     ValueType number_type = tInt;
 
     while (isdigit(*s) || *s == '-' || *s == '.' || *s == 'e' || *s == 'E') {
-      if (*s == '.' || *s == 'e' || *s == 'E') number_type = tFloat;
+      if (*s == '.' || *s == 'e' || *s == 'E') {
+        number_type = tFloat;
+      }
       tmp_number += *s++;
     }
 
diff --git a/third_party/nix/src/libexpr/lexer.l b/third_party/nix/src/libexpr/lexer.l
index c34e5c383923..a0d6bd7e163c 100644
--- a/third_party/nix/src/libexpr/lexer.l
+++ b/third_party/nix/src/libexpr/lexer.l
@@ -60,15 +60,15 @@ static Expr * unescapeStr(SymbolTable & symbols, const char * s, size_t length)
         if (c == '\\') {
             assert(*s);
             c = *s++;
-            if (c == 'n') t += '\n';
-            else if (c == 'r') t += '\r';
-            else if (c == 't') t += '\t';
+            if (c == 'n') { t += '\n'; }
+            else if (c == 'r') { t += '\r'; }
+            else if (c == 't') { t += '\t'; }
             else t += c;
         }
         else if (c == '\r') {
             /* Normalise CR and CR/LF into LF. */
             t += '\n';
-            if (*s == '\n') s++; /* cr/lf */
+            if (*s == '\n') { s++; } /* cr/lf */
         }
         else t += c;
     }
diff --git a/third_party/nix/src/libexpr/names.cc b/third_party/nix/src/libexpr/names.cc
index f7752f2bf804..92bd06308c69 100644
--- a/third_party/nix/src/libexpr/names.cc
+++ b/third_party/nix/src/libexpr/names.cc
@@ -28,9 +28,13 @@ bool DrvName::matches(DrvName& n) {
     if (!regex)
       regex = std::unique_ptr<std::regex>(
           new std::regex(name, std::regex::extended));
-    if (!std::regex_match(n.name, *regex)) return false;
+    if (!std::regex_match(n.name, *regex)) {
+      return false;
+    }
+  }
+  if (version != "" && version != n.version) {
+    return false;
   }
-  if (version != "" && version != n.version) return false;
   return true;
 }
 
@@ -39,7 +43,9 @@ string nextComponent(string::const_iterator& p,
   /* Skip any dots and dashes (component separators). */
   while (p != end && (*p == '.' || *p == '-')) ++p;
 
-  if (p == end) return "";
+  if (p == end) {
+    return "";
+  }
 
   /* If the first character is a digit, consume the longest sequence
      of digits.  Otherwise, consume the longest sequence of
diff --git a/third_party/nix/src/libexpr/nixexpr.cc b/third_party/nix/src/libexpr/nixexpr.cc
index 9c25530efdba..4c0536f35cc1 100644
--- a/third_party/nix/src/libexpr/nixexpr.cc
+++ b/third_party/nix/src/libexpr/nixexpr.cc
@@ -70,7 +70,9 @@ void ExprVar::show(std::ostream& str) const { str << name; }
 
 void ExprSelect::show(std::ostream& str) const {
   str << "(" << *e << ")." << showAttrPath(attrPath);
-  if (def) str << " or (" << *def << ")";
+  if (def) {
+    str << " or (" << *def << ")";
+  }
 }
 
 void ExprOpHasAttr::show(std::ostream& str) const {
@@ -78,7 +80,9 @@ void ExprOpHasAttr::show(std::ostream& str) const {
 }
 
 void ExprAttrs::show(std::ostream& str) const {
-  if (recursive) str << "rec ";
+  if (recursive) {
+    str << "rec ";
+  }
   str << "{ ";
   for (auto& i : attrs)
     if (i.second.inherited)
@@ -108,16 +112,24 @@ void ExprLambda::show(std::ostream& str) const {
       else
         str << ", ";
       str << i.name;
-      if (i.def) str << " ? " << *i.def;
+      if (i.def) {
+        str << " ? " << *i.def;
+      }
     }
     if (formals->ellipsis) {
-      if (!first) str << ", ";
+      if (!first) {
+        str << ", ";
+      }
       str << "...";
     }
     str << " }";
-    if (!arg.empty()) str << " @ ";
+    if (!arg.empty()) {
+      str << " @ ";
+    }
+  }
+  if (!arg.empty()) {
+    str << arg;
   }
-  if (!arg.empty()) str << arg;
   str << ": " << *body << ")";
 }
 
@@ -239,13 +251,17 @@ void ExprSelect::bindVars(const StaticEnv& env) {
     def->bindVars(env);
   }
   for (auto& i : attrPath)
-    if (!i.symbol.set()) i.expr->bindVars(env);
+    if (!i.symbol.set()) {
+      i.expr->bindVars(env);
+    }
 }
 
 void ExprOpHasAttr::bindVars(const StaticEnv& env) {
   e->bindVars(env);
   for (auto& i : attrPath)
-    if (!i.symbol.set()) i.expr->bindVars(env);
+    if (!i.symbol.set()) {
+      i.expr->bindVars(env);
+    }
 }
 
 void ExprAttrs::bindVars(const StaticEnv& env) {
@@ -296,7 +312,9 @@ void ExprLambda::bindVars(const StaticEnv& env) {
     }
 
     for (auto& i : formals->formals)
-      if (i.def) i.def->bindVars(newEnv);
+      if (i.def) {
+        i.def->bindVars(newEnv);
+      }
   }
 
   body->bindVars(newEnv);
diff --git a/third_party/nix/src/libexpr/parser.y b/third_party/nix/src/libexpr/parser.y
index ddcd1a4dae74..5aa38bf2b82c 100644
--- a/third_party/nix/src/libexpr/parser.y
+++ b/third_party/nix/src/libexpr/parser.y
@@ -89,7 +89,7 @@ static void addAttr(ExprAttrs * attrs, AttrPath & attrPath,
             if (j != attrs->attrs.end()) {
                 if (!j->second.inherited) {
                     ExprAttrs * attrs2 = dynamic_cast<ExprAttrs *>(j->second.e);
-                    if (!attrs2) dupAttr(attrPath, pos, j->second.pos);
+                    if (!attrs2) { dupAttr(attrPath, pos, j->second.pos); }
                     attrs = attrs2;
                 } else
                     dupAttr(attrPath, pos, j->second.pos);
@@ -148,7 +148,7 @@ static void addFormal(const Pos & pos, Formals * formals, const Formal & formal)
 
 static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Expr *> & es)
 {
-    if (es.empty()) return new ExprString(symbols.create(""));
+    if (es.empty()) { return new ExprString(symbols.create("")); }
 
     /* Figure out the minimum indentation.  Note that by design
        whitespace-only final lines are not taken into account.  (So
@@ -162,7 +162,7 @@ static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Ex
             /* Anti-quotations end the current start-of-line whitespace. */
             if (atStartOfLine) {
                 atStartOfLine = false;
-                if (curIndent < minIndent) minIndent = curIndent;
+                if (curIndent < minIndent) { minIndent = curIndent; }
             }
             continue;
         }
@@ -176,7 +176,7 @@ static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Ex
                     curIndent = 0;
                 } else {
                     atStartOfLine = false;
-                    if (curIndent < minIndent) minIndent = curIndent;
+                    if (curIndent < minIndent) { minIndent = curIndent; }
                 }
             } else if (e->s[j] == '\n') {
                 atStartOfLine = true;
@@ -216,7 +216,7 @@ static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Ex
                 }
             } else {
                 s2 += e->s[j];
-                if (e->s[j] == '\n') atStartOfLine = true;
+                if (e->s[j] == '\n') { atStartOfLine = true; }
             }
         }
 
@@ -559,7 +559,7 @@ Expr * EvalState::parse(const char * text,
     int res = yyparse(scanner, &data);
     yylex_destroy(scanner);
 
-    if (res) throw ParseError(data.error);
+    if (res) { throw ParseError(data.error); }
 
     data.result->bindVars(staticEnv);
 
@@ -577,7 +577,7 @@ Path resolveExprPath(Path path)
     while (true) {
         if (lstat(path.c_str(), &st))
             throw SysError(format("getting status of '%1%'") % path);
-        if (!S_ISLNK(st.st_mode)) break;
+        if (!S_ISLNK(st.st_mode)) { break; }
         path = absPath(readLink(path), dirOf(path));
     }
 
@@ -656,9 +656,9 @@ Path EvalState::findFile(SearchPath & searchPath, const string & path, const Pos
             suffix = path.size() == s ? "" : "/" + string(path, s);
         }
         auto r = resolveSearchPathElem(i);
-        if (!r.first) continue;
+        if (!r.first) { continue; }
         Path res = r.second + suffix;
-        if (pathExists(res)) return canonPath(res);
+        if (pathExists(res)) { return canonPath(res); }
     }
     format f = format(
         "file '%1%' was not found in the Nix search path (add it using $NIX_PATH or -I)"
@@ -671,7 +671,7 @@ Path EvalState::findFile(SearchPath & searchPath, const string & path, const Pos
 std::pair<bool, std::string> EvalState::resolveSearchPathElem(const SearchPathElem & elem)
 {
     auto i = searchPathResolved.find(elem.second);
-    if (i != searchPathResolved.end()) return i->second;
+    if (i != searchPathResolved.end()) { return i->second; }
 
     std::pair<bool, std::string> res;
 
diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc
index 3e11d6589f6a..dfcfdeae431c 100644
--- a/third_party/nix/src/libexpr/primops.cc
+++ b/third_party/nix/src/libexpr/primops.cc
@@ -51,7 +51,9 @@ void EvalState::realiseContext(const PathSet& context) {
     std::pair<string, string> decoded = decodeContext(i);
     Path ctx = decoded.first;
     assert(store->isStorePath(ctx));
-    if (!store->isValidPath(ctx)) throw InvalidPathError(ctx);
+    if (!store->isValidPath(ctx)) {
+      throw InvalidPathError(ctx);
+    }
     if (!decoded.second.empty() && nix::isDerivation(ctx)) {
       drvs.insert(decoded.first + "!" + decoded.second);
 
@@ -68,7 +70,9 @@ void EvalState::realiseContext(const PathSet& context) {
     }
   }
 
-  if (drvs.empty()) return;
+  if (drvs.empty()) {
+    return;
+  }
 
   if (!evalSettings.enableImportFromDerivation)
     throw EvalError(format("attempted to realize '%1%' during evaluation but "
@@ -417,7 +421,9 @@ static void prim_genericClosure(EvalState& state, const Pos& pos, Value** args,
       throw EvalError(format("attribute 'key' required, at %1%") % pos);
     state.forceValue(*key->value);
 
-    if (doneKeys.find(key->value) != doneKeys.end()) continue;
+    if (doneKeys.find(key->value) != doneKeys.end()) {
+      continue;
+    }
     doneKeys.insert(key->value);
     res.push_back(e);
 
@@ -583,7 +589,9 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
   outputs.insert("out");
 
   for (auto& i : args[0]->attrs->lexicographicOrder()) {
-    if (i->name == state.sIgnoreNulls) continue;
+    if (i->name == state.sIgnoreNulls) {
+      continue;
+    }
     const string& key = i->name;
 
     auto handleHashMode = [&](const std::string& s) {
@@ -623,7 +631,9 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
     try {
       if (ignoreNulls) {
         state.forceValue(*i->value);
-        if (i->value->type == tNull) continue;
+        if (i->value->type == tNull) {
+          continue;
+        }
       }
 
       /* The `args' attribute is special: it supplies the
@@ -641,7 +651,9 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
          the environment. */
       else {
         if (jsonObject) {
-          if (i->name == state.sStructuredAttrs) continue;
+          if (i->name == state.sStructuredAttrs) {
+            continue;
+          }
 
           auto placeholder(jsonObject->placeholder(key));
           printValueAsJSON(state, true, *i->value, placeholder, context);
@@ -758,7 +770,9 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
 
     Path outPath =
         state.store->makeFixedOutputPath(outputHashRecursive, h, drvName);
-    if (!jsonObject) drv.env["out"] = outPath;
+    if (!jsonObject) {
+      drv.env["out"] = outPath;
+    }
     drv.outputs["out"] = DerivationOutput(
         outPath, (outputHashRecursive ? "r:" : "") + printHashType(h.type),
         h.to_string(Base16, false));
@@ -771,7 +785,9 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
        an empty value.  This ensures that changes in the set of
        output names do get reflected in the hash. */
     for (auto& i : outputs) {
-      if (!jsonObject) drv.env[i] = "";
+      if (!jsonObject) {
+        drv.env[i] = "";
+      }
       drv.outputs[i] = DerivationOutput("", "", "");
     }
 
@@ -782,7 +798,9 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
     for (auto& i : drv.outputs)
       if (i.second.path == "") {
         Path outPath = state.store->makeOutputPath(i.first, h, drvName);
-        if (!jsonObject) drv.env[i.first] = outPath;
+        if (!jsonObject) {
+          drv.env[i.first] = outPath;
+        }
         i.second.path = outPath;
       }
   }
@@ -845,12 +863,16 @@ static void prim_storePath(EvalState& state, const Pos& pos, Value** args,
   /* Resolve symlinks in ‘path’, unless ‘path’ itself is a symlink
      directly in the store.  The latter condition is necessary so
      e.g. nix-push does the right thing. */
-  if (!state.store->isStorePath(path)) path = canonPath(path, true);
+  if (!state.store->isStorePath(path)) {
+    path = canonPath(path, true);
+  }
   if (!state.store->isInStore(path))
     throw EvalError(format("path '%1%' is not in the Nix store, at %2%") %
                     path % pos);
   Path path2 = state.store->toStorePath(path);
-  if (!settings.readOnlyMode) state.store->ensurePath(path2);
+  if (!settings.readOnlyMode) {
+    state.store->ensurePath(path2);
+  }
   context.insert(path2);
   mkString(v, path, context);
 }
@@ -936,7 +958,9 @@ static void prim_findFile(EvalState& state, const Pos& pos, Value** args,
 
     string prefix;
     Bindings::iterator i = v2.attrs->find(state.symbols.create("prefix"));
-    if (i != v2.attrs->end()) prefix = state.forceStringNoCtx(*i->value, pos);
+    if (i != v2.attrs->end()) {
+      prefix = state.forceStringNoCtx(*i->value, pos);
+    }
 
     i = v2.attrs->find(state.symbols.create("path"));
     if (i == v2.attrs->end())
@@ -995,7 +1019,9 @@ static void prim_readDir(EvalState& state, const Pos& pos, Value** args,
 
   for (auto& ent : entries) {
     Value* ent_val = state.allocAttr(v, state.symbols.create(ent.name));
-    if (ent.type == DT_UNKNOWN) ent.type = getFileType(path + "/" + ent.name);
+    if (ent.type == DT_UNKNOWN) {
+      ent.type = getFileType(path + "/" + ent.name);
+    }
     mkStringNoCopy(*ent_val,
                    ent.type == DT_REG
                        ? "regular"
@@ -1178,8 +1204,12 @@ static void prim_path(EvalState& state, const Pos& pos, Value** args,
           format("unsupported argument '%1%' to 'addPath', at %2%") %
           attr.name % *attr.pos);
   }
-  if (path.empty()) throw EvalError(format("'path' required, at %1%") % pos);
-  if (name.empty()) name = baseNameOf(path);
+  if (path.empty()) {
+    throw EvalError(format("'path' required, at %1%") % pos);
+  }
+  if (name.empty()) {
+    name = baseNameOf(path);
+  }
 
   addPath(state, pos, name, path, filterFun, recursive, expectedHash, v);
 }
@@ -1236,7 +1266,9 @@ void prim_getAttr(EvalState& state, const Pos& pos, Value** args, Value& v) {
   if (i == args[1]->attrs->end())
     throw EvalError(format("attribute '%1%' missing, at %2%") % attr % pos);
   // !!! add to stack trace?
-  if (state.countCalls && i->pos) state.attrSelects[*i->pos]++;
+  if (state.countCalls && i->pos) {
+    state.attrSelects[*i->pos]++;
+  }
   state.forceValue(*i->value);
   v = *i->value;
 }
@@ -1287,7 +1319,9 @@ static void prim_removeAttrs(EvalState& state, const Pos& pos, Value** args,
      vector. */
   state.mkAttrs(v, args[0]->attrs->size());
   for (auto& i : *args[0]->attrs) {
-    if (names.find(i.name) == names.end()) v.attrs->push_back(i);
+    if (names.find(i.name) == names.end()) {
+      v.attrs->push_back(i);
+    }
   }
 }
 
@@ -1673,12 +1707,16 @@ static void prim_partition(EvalState& state, const Pos& pos, Value** args,
   Value* vRight = state.allocAttr(v, state.sRight);
   auto rsize = right.size();
   state.mkList(*vRight, rsize);
-  if (rsize) memcpy(vRight->listElems(), right.data(), sizeof(Value*) * rsize);
+  if (rsize) {
+    memcpy(vRight->listElems(), right.data(), sizeof(Value*) * rsize);
+  }
 
   Value* vWrong = state.allocAttr(v, state.sWrong);
   auto wsize = wrong.size();
   state.mkList(*vWrong, wsize);
-  if (wsize) memcpy(vWrong->listElems(), wrong.data(), sizeof(Value*) * wsize);
+  if (wsize) {
+    memcpy(vWrong->listElems(), wrong.data(), sizeof(Value*) * wsize);
+  }
 
   v.attrs->sort();
 }
@@ -1705,7 +1743,9 @@ static void prim_concatMap(EvalState& state, const Pos& pos, Value** args,
   auto out = v.listElems();
   for (unsigned int n = 0, pos = 0; n < nrLists; ++n) {
     auto l = lists[n].listSize();
-    if (l) memcpy(out + pos, lists[n].listElems(), l * sizeof(Value*));
+    if (l) {
+      memcpy(out + pos, lists[n].listElems(), l * sizeof(Value*));
+    }
     pos += l;
   }
 }
@@ -1752,7 +1792,9 @@ static void prim_div(EvalState& state, const Pos& pos, Value** args, Value& v) {
   state.forceValue(*args[1], pos);
 
   NixFloat f2 = state.forceFloat(*args[1], pos);
-  if (f2 == 0) throw EvalError(format("division by zero, at %1%") % pos);
+  if (f2 == 0) {
+    throw EvalError(format("division by zero, at %1%") % pos);
+  }
 
   if (args[0]->type == tFloat || args[1]->type == tFloat) {
     mkFloat(v,
@@ -2012,7 +2054,9 @@ static void prim_replaceStrings(EvalState& state, const Pos& pos, Value** args,
         found = true;
         res += j->first;
         if (i->empty()) {
-          if (p < s.size()) res += s[p];
+          if (p < s.size()) {
+            res += s[p];
+          }
           p++;
         } else {
           p += i->size();
@@ -2022,7 +2066,9 @@ static void prim_replaceStrings(EvalState& state, const Pos& pos, Value** args,
         break;
       }
     if (!found) {
-      if (p < s.size()) res += s[p];
+      if (p < s.size()) {
+        res += s[p];
+      }
       p++;
     }
   }
@@ -2059,7 +2105,9 @@ static void prim_splitVersion(EvalState& state, const Pos& pos, Value** args,
   Strings components;
   while (iter != version.cend()) {
     auto component = nextComponent(iter, version.cend());
-    if (component.empty()) break;
+    if (component.empty()) {
+      break;
+    }
     components.emplace_back(std::move(component));
   }
   state.mkList(v, components.size());
@@ -2114,7 +2162,9 @@ void fetch(EvalState& state, const Pos& pos, Value** args, Value& v,
 
   auto res = getDownloader()->downloadCached(state.store, request);
 
-  if (state.allowedPaths) state.allowedPaths->insert(res.path);
+  if (state.allowedPaths) {
+    state.allowedPaths->insert(res.path);
+  }
 
   mkString(v, res.storePath, PathSet({res.storePath}));
 }
@@ -2136,7 +2186,9 @@ static void prim_fetchTarball(EvalState& state, const Pos& pos, Value** args,
 RegisterPrimOp::PrimOps* RegisterPrimOp::primOps;
 
 RegisterPrimOp::RegisterPrimOp(std::string name, size_t arity, PrimOpFun fun) {
-  if (!primOps) primOps = new PrimOps;
+  if (!primOps) {
+    primOps = new PrimOps;
+  }
   primOps->emplace_back(name, arity, fun);
 }
 
diff --git a/third_party/nix/src/libexpr/primops/context.cc b/third_party/nix/src/libexpr/primops/context.cc
index 13faeef8ce9c..1ae3219f2c61 100644
--- a/third_party/nix/src/libexpr/primops/context.cc
+++ b/third_party/nix/src/libexpr/primops/context.cc
@@ -111,7 +111,9 @@ static void prim_getContext(EvalState& state, const Pos& pos, Value** args,
   for (const auto& info : contextInfos) {
     auto& infoVal = *state.allocAttr(v, state.symbols.create(info.first));
     state.mkAttrs(infoVal, 3);
-    if (info.second.path) mkBool(*state.allocAttr(infoVal, sPath), true);
+    if (info.second.path) {
+      mkBool(*state.allocAttr(infoVal, sPath), true);
+    }
     if (info.second.allOutputs)
       mkBool(*state.allocAttr(infoVal, sAllOutputs), true);
     if (!info.second.outputs.empty()) {
@@ -147,11 +149,15 @@ static void prim_appendContext(EvalState& state, const Pos& pos, Value** args,
     if (!state.store->isStorePath(i.name))
       throw EvalError("Context key '%s' is not a store path, at %s", i.name,
                       i.pos);
-    if (!settings.readOnlyMode) state.store->ensurePath(i.name);
+    if (!settings.readOnlyMode) {
+      state.store->ensurePath(i.name);
+    }
     state.forceAttrs(*i.value, *i.pos);
     auto iter = i.value->attrs->find(sPath);
     if (iter != i.value->attrs->end()) {
-      if (state.forceBool(*iter->value, *iter->pos)) context.insert(i.name);
+      if (state.forceBool(*iter->value, *iter->pos)) {
+        context.insert(i.name);
+      }
     }
 
     iter = i.value->attrs->find(sAllOutputs);
diff --git a/third_party/nix/src/libexpr/primops/fetchGit.cc b/third_party/nix/src/libexpr/primops/fetchGit.cc
index 7fbd4dc92cf0..818a475f5ecd 100644
--- a/third_party/nix/src/libexpr/primops/fetchGit.cc
+++ b/third_party/nix/src/libexpr/primops/fetchGit.cc
@@ -37,7 +37,9 @@ GitInfo exportGit(ref<Store> store, const std::string& uri,
       runProgram("git", true,
                  {"-C", uri, "diff-index", "--quiet", "HEAD", "--"});
     } catch (ExecError& e) {
-      if (!WIFEXITED(e.status) || WEXITSTATUS(e.status) != 1) throw;
+      if (!WIFEXITED(e.status) || WEXITSTATUS(e.status) != 1) {
+        throw;
+      }
       clean = false;
     }
 
@@ -78,7 +80,9 @@ GitInfo exportGit(ref<Store> store, const std::string& uri,
     ref = "HEAD"s;
   }
 
-  if (!ref) ref = "HEAD"s;
+  if (!ref) {
+    ref = "HEAD"s;
+  }
 
   if (rev != "" && !std::regex_match(rev, revRegex))
     throw Error("invalid Git revision '%s'", rev);
@@ -166,7 +170,9 @@ GitInfo exportGit(ref<Store> store, const std::string& uri,
     }
 
   } catch (SysError& e) {
-    if (e.errNo != ENOENT) throw;
+    if (e.errNo != ENOENT) {
+      throw;
+    }
   }
 
   // FIXME: should pipe this, or find some better way to extract a
diff --git a/third_party/nix/src/libexpr/primops/fetchMercurial.cc b/third_party/nix/src/libexpr/primops/fetchMercurial.cc
index 3de42fe770dc..392dbcb00837 100644
--- a/third_party/nix/src/libexpr/primops/fetchMercurial.cc
+++ b/third_party/nix/src/libexpr/primops/fetchMercurial.cc
@@ -73,7 +73,9 @@ HgInfo exportMercurial(ref<Store> store, const std::string& uri,
     }
   }
 
-  if (rev == "") rev = "default";
+  if (rev == "") {
+    rev = "default";
+  }
 
   Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(),
                       hashString(htSHA256, uri).to_string(Base32, false));
@@ -149,7 +151,9 @@ HgInfo exportMercurial(ref<Store> store, const std::string& uri,
     }
 
   } catch (SysError& e) {
-    if (e.errNo != ENOENT) throw;
+    if (e.errNo != ENOENT) {
+      throw;
+    }
   }
 
   Path tmpDir = createTempDir();
diff --git a/third_party/nix/src/libexpr/value-to-xml.cc b/third_party/nix/src/libexpr/value-to-xml.cc
index 6247d25b9c34..0e955c4ce267 100644
--- a/third_party/nix/src/libexpr/value-to-xml.cc
+++ b/third_party/nix/src/libexpr/value-to-xml.cc
@@ -36,7 +36,9 @@ static void showAttrs(EvalState& state, bool strict, bool location,
 
     XMLAttrs xmlAttrs;
     xmlAttrs["name"] = i;
-    if (location && a.pos != &noPos) posToXML(xmlAttrs, *a.pos);
+    if (location && a.pos != &noPos) {
+      posToXML(xmlAttrs, *a.pos);
+    }
 
     XMLOpenElement _(doc, "attr", xmlAttrs);
     printValueAsXML(state, strict, location, *a.value, doc, context, drvsSeen);
@@ -132,7 +134,9 @@ static void printValueAsXML(EvalState& state, bool strict, bool location,
 
     case tLambda: {
       XMLAttrs xmlAttrs;
-      if (location) posToXML(xmlAttrs, v.lambda.fun->pos);
+      if (location) {
+        posToXML(xmlAttrs, v.lambda.fun->pos);
+      }
       XMLOpenElement _(doc, "function", xmlAttrs);
 
       if (v.lambda.fun->matchAttrs) {