about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr
diff options
context:
space:
mode:
authorKane York <kanepyork@gmail.com>2020-07-25T04·09-0700
committerkanepyork <rikingcoding@gmail.com>2020-07-27T21·16+0000
commitef54f5da9fa30b5c302f2a49595ee5d041f9706a (patch)
tree8d1da709a2e2d3b135d1e84eda9c402bde467726 /third_party/nix/src/libexpr
parent69f402563a14d4b668980e4228d033d80e3bb05d (diff)
fix(3p/nix): apply all clang-tidy fixes r/1495
Change-Id: I265e763393422ee1881653527c91024458060825
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1432
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'third_party/nix/src/libexpr')
-rw-r--r--third_party/nix/src/libexpr/attr-path.cc2
-rw-r--r--third_party/nix/src/libexpr/eval.cc61
-rw-r--r--third_party/nix/src/libexpr/get-drvs.cc7
-rw-r--r--third_party/nix/src/libexpr/names.cc4
-rw-r--r--third_party/nix/src/libexpr/names.hh2
-rw-r--r--third_party/nix/src/libexpr/nixexpr.cc14
-rw-r--r--third_party/nix/src/libexpr/parser.cc19
-rw-r--r--third_party/nix/src/libexpr/primops.cc45
-rw-r--r--third_party/nix/src/libexpr/primops/context.cc13
-rw-r--r--third_party/nix/src/libexpr/primops/fetchGit.cc32
-rw-r--r--third_party/nix/src/libexpr/primops/fetchMercurial.cc20
-rw-r--r--third_party/nix/src/libexpr/primops/fromTOML.cc26
12 files changed, 137 insertions, 108 deletions
diff --git a/third_party/nix/src/libexpr/attr-path.cc b/third_party/nix/src/libexpr/attr-path.cc
index a267e82b6ebe..07ffebff1ad3 100644
--- a/third_party/nix/src/libexpr/attr-path.cc
+++ b/third_party/nix/src/libexpr/attr-path.cc
@@ -51,7 +51,7 @@ Value* findAlongAttrPath(EvalState& state, const std::string& attrPath,
   for (auto& attr : tokens) {
     /* Is i an index (integer) or a normal attribute name? */
     enum { apAttr, apIndex } apType = apAttr;
-    unsigned int attrIndex;
+    unsigned int attrIndex = 0;
     if (absl::SimpleAtoi(attr, &attrIndex)) {
       apType = apIndex;
     }
diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc
index 5f267f2053fb..a762571fca2d 100644
--- a/third_party/nix/src/libexpr/eval.cc
+++ b/third_party/nix/src/libexpr/eval.cc
@@ -35,7 +35,7 @@
 namespace nix {
 
 static char* dupString(const char* s) {
-  char* t;
+  char* t = nullptr;
   t = GC_STRDUP(s);
   if (t == nullptr) {
     throw std::bad_alloc();
@@ -195,7 +195,7 @@ static Symbol getName(const AttrName& name, EvalState& state, Env& env) {
   return std::visit(
       util::overloaded{[&](const Symbol& name) -> Symbol { return name; },
                        [&](Expr* expr) -> Symbol {
-                         Value nameValue;
+                         Value nameValue{};
                          expr->eval(state, env, nameValue);
                          state.forceStringNoCtx(nameValue);
                          return state.symbols.Create(nameValue.string.s);
@@ -474,7 +474,7 @@ Value* EvalState::addConstant(const std::string& name, Value& v) {
 Value* EvalState::addPrimOp(const std::string& name, size_t arity,
                             PrimOpFun primOp) {
   if (arity == 0) {
-    Value v;
+    Value v{};
     primOp(*this, noPos, nullptr, v);
     return addConstant(name, v);
   }
@@ -572,8 +572,8 @@ Value& mkString(Value& v, const std::string& s, const PathSet& context) {
   mkString(v, s.c_str());
   if (!context.empty()) {
     size_t n = 0;
-    v.string.context =
-        (const char**)allocBytes((context.size() + 1) * sizeof(char*));
+    v.string.context = static_cast<const char**>(
+        allocBytes((context.size() + 1) * sizeof(char*)));
     for (auto& i : context) {
       v.string.context[n++] = dupString(i.c_str());
     }
@@ -599,7 +599,7 @@ inline Value* EvalState::lookupVar(Env* env, const ExprVar& var, bool noEval) {
         return nullptr;
       }
       Value* v = allocValue();
-      evalAttrs(*env->up, (Expr*)env->values[0], *v);
+      evalAttrs(*env->up, reinterpret_cast<Expr*>(env->values[0]), *v);
       env->values[0] = v;
       env->type = Env::HasWithAttrs;
     }
@@ -763,7 +763,7 @@ void EvalState::resetFileCache() {
 void EvalState::eval(Expr* e, Value& v) { e->eval(*this, baseEnv, v); }
 
 inline bool EvalState::evalBool(Env& env, Expr* e) {
-  Value v;
+  Value v{};
   e->eval(*this, env, v);
   if (v.type != tBool) {
     throwTypeError("value is %1% while a Boolean was expected", v);
@@ -772,7 +772,7 @@ inline bool EvalState::evalBool(Env& env, Expr* e) {
 }
 
 inline bool EvalState::evalBool(Env& env, Expr* e, const Pos& pos) {
-  Value v;
+  Value v{};
   e->eval(*this, env, v);
   if (v.type != tBool) {
     throwTypeError("value is %1% while a Boolean was expected, at %2%", v, pos);
@@ -813,7 +813,7 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& value) {
        in the original environment. */
     size_t displ = 0;
     for (auto& attr : attrs) {
-      Value* vAttr;
+      Value* vAttr = nullptr;
       vAttr =
           attr.second.e->maybeThunk(state, attr.second.inherited ? env : env2);
       env2.values[displ++] = vAttr;
@@ -829,7 +829,7 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& value) {
 
   /* Dynamic attrs apply *after* rec. */
   for (auto& i : dynamicAttrs) {
-    Value nameVal;
+    Value nameVal{};
     i.nameExpr->eval(state, *dynamicEnv, nameVal);
     state.forceValue(nameVal, i.pos);
     if (nameVal.type == tNull) {
@@ -897,7 +897,7 @@ static std::string showAttrPath(EvalState& state, Env& env,
 unsigned long nrLookups = 0;
 
 void ExprSelect::eval(EvalState& state, Env& env, Value& v) {
-  Value vTmp;
+  Value vTmp{};
   Pos* pos2 = nullptr;
   Value* vAttrs = &vTmp;
 
@@ -948,7 +948,7 @@ void ExprSelect::eval(EvalState& state, Env& env, Value& v) {
 }
 
 void ExprOpHasAttr::eval(EvalState& state, Env& env, Value& v) {
-  Value vTmp;
+  Value vTmp{};
   Value* vAttrs = &vTmp;
 
   e->eval(state, env, vTmp);
@@ -976,7 +976,7 @@ void ExprLambda::eval(EvalState& state, Env& env, Value& v) {
 
 void ExprApp::eval(EvalState& state, Env& env, Value& v) {
   /* FIXME: vFun prevents GCC from doing tail call optimisation. */
-  Value vFun;
+  Value vFun{};
   e1->eval(state, env, vFun);
   state.callFunction(vFun, *(e2->maybeThunk(state, env)), v, pos);
 }
@@ -1044,7 +1044,7 @@ void EvalState::callFunction(Value& fun, Value& arg, Value& v, const Pos& pos) {
       auto& fun2 = *allocValue();
       fun2 = fun;
       /* !!! Should we use the attr pos here? */
-      Value v2;
+      Value v2{};
       // functors are called with the element itself as the first
       // parameter, which is partially applied here
       callFunction(*found->second.value, fun2, v2, pos);
@@ -1176,7 +1176,9 @@ void ExprWith::eval(EvalState& state, Env& env, Value& v) {
   env2.up = &env;
   env2.prevWith = prevWith;
   env2.type = Env::HasWithExpr;
-  env2.values[0] = (Value*)attrs;
+  // TODO(kanepyork): Figure out what's going on here. `Expr* attrs` is not
+  // layout-compatible with Value*.
+  env2.values[0] = reinterpret_cast<Value*>(attrs);
 
   body->eval(state, env2, v);
 }
@@ -1199,17 +1201,17 @@ void ExprOpNot::eval(EvalState& state, Env& env, Value& v) {
 }
 
 void ExprOpEq::eval(EvalState& state, Env& env, Value& v) {
-  Value v1;
+  Value v1{};
   e1->eval(state, env, v1);
-  Value v2;
+  Value v2{};
   e2->eval(state, env, v2);
   mkBool(v, state.eqValues(v1, v2));
 }
 
 void ExprOpNEq::eval(EvalState& state, Env& env, Value& v) {
-  Value v1;
+  Value v1{};
   e1->eval(state, env, v1);
-  Value v2;
+  Value v2{};
   e2->eval(state, env, v2);
   mkBool(v, !state.eqValues(v1, v2));
 }
@@ -1227,8 +1229,8 @@ void ExprOpImpl::eval(EvalState& state, Env& env, Value& v) {
 }
 
 void ExprOpUpdate::eval(EvalState& state, Env& env, Value& dest) {
-  Value v1;
-  Value v2;
+  Value v1{};
+  Value v2{};
   state.evalAttrs(env, e1, v1);
   state.evalAttrs(env, e2, v2);
 
@@ -1240,9 +1242,9 @@ void ExprOpUpdate::eval(EvalState& state, Env& env, Value& dest) {
 }
 
 void ExprOpConcatLists::eval(EvalState& state, Env& env, Value& v) {
-  Value v1;
+  Value v1{};
   e1->eval(state, env, v1);
-  Value v2;
+  Value v2{};
   e2->eval(state, env, v2);
   state.concatLists(v, {&v1, &v2}, pos);
 }
@@ -1270,7 +1272,7 @@ void ExprConcatStrings::eval(EvalState& state, Env& env, Value& v) {
   ValueType firstType = tString;
 
   for (auto& i : *es) {
-    Value vTmp;
+    Value vTmp{};
     i->eval(state, env, vTmp);
 
     /* If the first element is a path, then the result will also
@@ -1471,7 +1473,7 @@ std::optional<std::string> EvalState::tryAttrsToString(const Pos& pos, Value& v,
                                                        bool copyToStore) {
   auto i = v.attrs->find(sToString);
   if (i != v.attrs->end()) {
-    Value v1;
+    Value v1{};
     callFunction(*i->second.value, v, v1, pos);
     return coerceToString(pos, v1, context, coerceMore, copyToStore);
   }
@@ -1691,9 +1693,10 @@ bool EvalState::eqValues(Value& v1, Value& v2) {
 void EvalState::printStats() {
   bool showStats = getEnv("NIX_SHOW_STATS", "0") != "0";
 
-  struct rusage buf;
+  struct rusage buf {};
   getrusage(RUSAGE_SELF, &buf);
-  float cpuTime = buf.ru_utime.tv_sec + ((float)buf.ru_utime.tv_usec / 1000000);
+  float cpuTime = buf.ru_utime.tv_sec +
+                  (static_cast<float>(buf.ru_utime.tv_usec) / 1000000);
 
   uint64_t bEnvs = nrEnvs * sizeof(Env) + nrValuesInEnvs * sizeof(Value*);
   uint64_t bLists = nrListElems * sizeof(Value*);
@@ -1702,8 +1705,8 @@ void EvalState::printStats() {
       nrAttrsets * sizeof(Bindings) + nrAttrsInAttrsets * sizeof(Attr);
 
 #if HAVE_BOEHMGC
-  GC_word heapSize;
-  GC_word totalBytes;
+  GC_word heapSize = 0;
+  GC_word totalBytes = 0;
   GC_get_heap_usage_safe(&heapSize, nullptr, nullptr, nullptr, &totalBytes);
 #endif
   if (showStats) {
diff --git a/third_party/nix/src/libexpr/get-drvs.cc b/third_party/nix/src/libexpr/get-drvs.cc
index 02ddae1f886c..fb5ada54c860 100644
--- a/third_party/nix/src/libexpr/get-drvs.cc
+++ b/third_party/nix/src/libexpr/get-drvs.cc
@@ -6,6 +6,7 @@
 
 #include <absl/strings/numbers.h>
 #include <glog/logging.h>
+#include <math.h>
 
 #include "libexpr/eval-inline.hh"
 #include "libstore/derivations.hh"
@@ -243,7 +244,7 @@ NixInt DrvInfo::queryMetaInt(const std::string& name, NixInt def) {
   if (v->type == tString) {
     /* Backwards compatibility with before we had support for
        integer meta fields. */
-    NixInt n;
+    NixInt n = 0;
     if (absl::SimpleAtoi(v->string.s, &n)) {
       return n;
     }
@@ -262,7 +263,7 @@ NixFloat DrvInfo::queryMetaFloat(const std::string& name, NixFloat def) {
   if (v->type == tString) {
     /* Backwards compatibility with before we had support for
        float meta fields. */
-    NixFloat n;
+    NixFloat n = NAN;
     if (string2Float(v->string.s, n)) {
       return n;
     }
@@ -367,7 +368,7 @@ static void getDerivations(EvalState& state, Value& vIn,
                            const std::string& pathPrefix, Bindings& autoArgs,
                            DrvInfos& drvs, Done& done,
                            bool ignoreAssertionFailures) {
-  Value v;
+  Value v{};
   state.autoCallFunction(autoArgs, vIn, v);
 
   /* Process the expression. */
diff --git a/third_party/nix/src/libexpr/names.cc b/third_party/nix/src/libexpr/names.cc
index 1e9c2f2f4aac..84329d7c02c0 100644
--- a/third_party/nix/src/libexpr/names.cc
+++ b/third_party/nix/src/libexpr/names.cc
@@ -68,8 +68,8 @@ std::string nextComponent(std::string::const_iterator& p,
 }
 
 static bool componentsLT(const std::string& c1, const std::string& c2) {
-  int n1;
-  int n2;
+  int n1 = 0;
+  int n2 = 0;
   bool c1Num = absl::SimpleAtoi(c1, &n1);
   bool c2Num = absl::SimpleAtoi(c2, &n2);
 
diff --git a/third_party/nix/src/libexpr/names.hh b/third_party/nix/src/libexpr/names.hh
index 061388d517cd..e820995b84a6 100644
--- a/third_party/nix/src/libexpr/names.hh
+++ b/third_party/nix/src/libexpr/names.hh
@@ -11,7 +11,7 @@ struct DrvName {
   std::string fullName;
   std::string name;
   std::string version;
-  unsigned int hits;
+  unsigned int hits{};
 
   DrvName();
   DrvName(const std::string& s);
diff --git a/third_party/nix/src/libexpr/nixexpr.cc b/third_party/nix/src/libexpr/nixexpr.cc
index 94e7d335cff0..faf1020f8573 100644
--- a/third_party/nix/src/libexpr/nixexpr.cc
+++ b/third_party/nix/src/libexpr/nixexpr.cc
@@ -18,7 +18,7 @@ std::ostream& operator<<(std::ostream& str, const Expr& e) {
 
 static void showString(std::ostream& str, const std::string& s) {
   str << '"';
-  for (auto c : (std::string)s) {
+  for (auto c : std::string(s)) {
     if (c == '"' || c == '\\' || c == '$') {
       str << "\\" << c;
     } else if (c == '\n') {
@@ -191,7 +191,7 @@ std::ostream& operator<<(std::ostream& str, const Pos& pos) {
     str << "undefined position";
   } else {
     str << (format(ANSI_BOLD "%1%" ANSI_NORMAL ":%2%:%3%") %
-            (std::string)pos.file.value() % pos.line % pos.column)
+            std::string(pos.file.value()) % pos.line % pos.column)
                .str();
   }
   return str;
@@ -232,8 +232,8 @@ void ExprPath::bindVars(const StaticEnv& env) {}
 void ExprVar::bindVars(const StaticEnv& env) {
   /* Check whether the variable appears in the environment.  If so,
      set its level and displacement. */
-  const StaticEnv* curEnv;
-  unsigned int level;
+  const StaticEnv* curEnv = nullptr;
+  unsigned int level = 0;
   int withLevel = -1;
   for (curEnv = &env, level = 0; curEnv != nullptr;
        curEnv = curEnv->up, level++) {
@@ -363,8 +363,8 @@ void ExprWith::bindVars(const StaticEnv& env) {
   /* Does this `with' have an enclosing `with'?  If so, record its
      level so that `lookupVar' can look up variables in the previous
      `with' if this one doesn't contain the desired attribute. */
-  const StaticEnv* curEnv;
-  unsigned int level;
+  const StaticEnv* curEnv = nullptr;
+  unsigned int level = 0;
   prevWith = 0;
   for (curEnv = &env, level = 1; curEnv != nullptr;
        curEnv = curEnv->up, level++) {
@@ -405,7 +405,7 @@ void ExprLambda::setName(Symbol& name) { this->name = name; }
 
 std::string ExprLambda::showNamePos() const {
   return (format("%1% at %2%") %
-          (name.has_value() ? "'" + (std::string)name.value() + "'"
+          (name.has_value() ? "'" + std::string(name.value()) + "'"
                             : "anonymous function") %
           pos)
       .str();
diff --git a/third_party/nix/src/libexpr/parser.cc b/third_party/nix/src/libexpr/parser.cc
index a96d345cc126..7b477f3eae0a 100644
--- a/third_party/nix/src/libexpr/parser.cc
+++ b/third_party/nix/src/libexpr/parser.cc
@@ -85,9 +85,10 @@ void addAttr(ExprAttrs* attrs, AttrPath& attrPath, Expr* e, const Pos& pos) {
 }
 
 void addFormal(const Pos& pos, Formals* formals, const Formal& formal) {
-  if (formals->argNames.find(formal.name) != formals->argNames.end())
+  if (formals->argNames.find(formal.name) != formals->argNames.end()) {
     throw ParseError(format("duplicate formal function argument '%1%' at %2%") %
                      formal.name % pos);
+  }
   formals->formals.push_front(formal);
   formals->argNames.insert(formal.name);
 }
@@ -118,9 +119,9 @@ Expr* stripIndentation(const Pos& pos, SymbolTable& symbols,
     }
     for (size_t j = 0; j < e->s.size(); ++j) {
       if (atStartOfLine) {
-        if (e->s[j] == ' ')
+        if (e->s[j] == ' ') {
           curIndent++;
-        else if (e->s[j] == '\n') {
+        } else if (e->s[j] == '\n') {
           /* Empty line, doesn't influence minimum
              indentation. */
           curIndent = 0;
@@ -196,10 +197,11 @@ Path resolveExprPath(Path path) {
 
   /* If `path' is a symlink, follow it.  This is so that relative
      path references work. */
-  struct stat st;
+  struct stat st {};
   while (true) {
-    if (lstat(path.c_str(), &st))
+    if (lstat(path.c_str(), &st)) {
       throw SysError(format("getting status of '%1%'") % path);
+    }
     if (!S_ISLNK(st.st_mode)) {
       break;
     }
@@ -260,13 +262,14 @@ Path EvalState::findFile(SearchPath& searchPath, const std::string& path,
                          const Pos& pos) {
   for (auto& i : searchPath) {
     std::string suffix;
-    if (i.first.empty())
+    if (i.first.empty()) {
       suffix = "/" + path;
-    else {
+    } else {
       auto s = i.first.size();
       if (path.compare(0, s, i.first) != 0 ||
-          (path.size() > s && path[s] != '/'))
+          (path.size() > s && path[s] != '/')) {
         continue;
+      }
       suffix = path.size() == s ? "" : "/" + std::string(path, s);
     }
     auto r = resolveSearchPathElem(i);
diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc
index 06b9788bdf09..c754f0392b89 100644
--- a/third_party/nix/src/libexpr/primops.cc
+++ b/third_party/nix/src/libexpr/primops.cc
@@ -86,8 +86,8 @@ void EvalState::realiseContext(const PathSet& context) {
   PathSet willBuild;
   PathSet willSubstitute;
   PathSet unknown;
-  unsigned long long downloadSize;
-  unsigned long long narSize;
+  unsigned long long downloadSize = 0;
+  unsigned long long narSize = 0;
   store->queryMissing(drvs, willBuild, willSubstitute, unknown, downloadSize,
                       narSize);
   store->buildPaths(drvs);
@@ -130,7 +130,7 @@ static void prim_scopedImport(EvalState& state, const Pos& pos, Value** args,
       mkString(*((*outputsVal->list)[outputs_index++]), o.first);
     }
 
-    Value fun;
+    Value fun{};
     state.evalFile(
         settings.nixDataDir + "/nix/corepkgs/imported-drv-to-derivation.nix",
         fun);
@@ -216,7 +216,7 @@ static void prim_isNull(EvalState& state, const Pos& pos, Value** args,
 static void prim_isFunction(EvalState& state, const Pos& pos, Value** args,
                             Value& v) {
   state.forceValue(*args[0]);
-  bool res;
+  bool res = 0;
   switch (args[0]->type) {
     case tLambda:
     case tPrimOp:
@@ -350,7 +350,7 @@ static void prim_genericClosure(EvalState& state, const Pos& pos, Value** args,
     res.push_back(e);
 
     /* Call the `operator' function with `e' as argument. */
-    Value call;
+    Value call{};
     mkApp(call, *op->second.value, *e);
     state.forceList(call, pos);
 
@@ -877,7 +877,7 @@ static void prim_readFile(EvalState& state, const Pos& pos, Value** args,
   }
   std::string s =
       readFile(state.checkSourcePath(state.toRealPath(path, context)));
-  if (s.find((char)0) != std::string::npos) {
+  if (s.find('\0') != std::string::npos) {
     throw Error(format("the contents of the file '%1%' cannot be represented "
                        "as a Nix string") %
                 path);
@@ -1050,13 +1050,13 @@ static void addPath(EvalState& state, const Pos& pos, const std::string& name,
 
     /* Call the filter function.  The first argument is the path,
        the second is a string indicating the type of the file. */
-    Value arg1;
+    Value arg1{};
     mkString(arg1, path);
 
-    Value fun2;
+    Value fun2{};
     state.callFunction(*filterFun, arg1, fun2, noPos);
 
-    Value arg2;
+    Value arg2{};
     mkString(arg2, S_ISREG(st.st_mode)
                        ? "regular"
                        : S_ISDIR(st.st_mode)
@@ -1065,7 +1065,7 @@ static void addPath(EvalState& state, const Pos& pos, const std::string& name,
                                    ? "symlink"
                                    : "unknown" /* not supported, will fail! */);
 
-    Value res;
+    Value res{};
     state.callFunction(fun2, arg2, res, noPos);
 
     return state.forceBool(res, pos);
@@ -1421,7 +1421,7 @@ static void prim_isList(EvalState& state, const Pos& pos, Value** args,
 static void elemAt(EvalState& state, const Pos& pos, Value& list, int n,
                    Value& v) {
   state.forceList(list, pos);
-  if (n < 0 || (unsigned int)n >= list.listSize()) {
+  if (n < 0 || static_cast<unsigned int>(n) >= list.listSize()) {
     throw Error(format("list index %1% is out of bounds, at %2%") % n % pos);
   }
   state.forceValue(*(*list.list)[n]);
@@ -1480,7 +1480,7 @@ static void prim_filter(EvalState& state, const Pos& pos, Value** args,
 
   bool same = true;
   for (unsigned int n = 0; n < args[1]->listSize(); ++n) {
-    Value res;
+    Value res{};
     state.callFunction(*args[0], *(*args[1]->list)[n], res, noPos);
     if (state.forceBool(res, pos)) {
       vs[k++] = (*args[1]->list)[n];
@@ -1538,7 +1538,7 @@ static void prim_foldlStrict(EvalState& state, const Pos& pos, Value** args,
     Value* vCur = args[1];
 
     for (unsigned int n = 0; n < args[2]->listSize(); ++n) {
-      Value vTmp;
+      Value vTmp{};
       state.callFunction(*args[0], *vCur, vTmp, pos);
       vCur = n == args[2]->listSize() - 1 ? &v : state.allocValue();
       state.callFunction(vTmp, *(*args[2]->list)[n], *vCur, pos);
@@ -1555,7 +1555,7 @@ static void anyOrAll(bool any, EvalState& state, const Pos& pos, Value** args,
   state.forceFunction(*args[0], pos);
   state.forceList(*args[1], pos);
 
-  Value vTmp;
+  Value vTmp{};
   for (unsigned int n = 0; n < args[1]->listSize(); ++n) {
     state.callFunction(*args[0], *(*args[1]->list)[n], vTmp, pos);
     bool res = state.forceBool(vTmp, pos);
@@ -1587,7 +1587,7 @@ static void prim_genList(EvalState& state, const Pos& pos, Value** args,
 
   state.mkList(v, len);
 
-  for (unsigned int n = 0; n < (unsigned int)len; ++n) {
+  for (unsigned int n = 0; n < static_cast<unsigned int>(len); ++n) {
     Value* arg = state.allocValue();
     mkInt(*arg, n);
     mkApp(*((*v.list)[n] = state.allocValue()), *args[0], *arg);
@@ -1615,8 +1615,8 @@ static void prim_sort(EvalState& state, const Pos& pos, Value** args,
       return CompareValues()(a, b);
     }
 
-    Value vTmp1;
-    Value vTmp2;
+    Value vTmp1{};
+    Value vTmp2{};
     state.callFunction(*args[0], *a, vTmp1, pos);
     state.callFunction(vTmp1, *b, vTmp2, pos);
     return state.forceBool(vTmp2, pos);
@@ -1639,7 +1639,7 @@ static void prim_partition(EvalState& state, const Pos& pos, Value** args,
   for (Value* elem : *args[1]->list) {
     state.forceValue(*elem, pos);
 
-    Value res;
+    Value res{};
     state.callFunction(*args[0], *elem, res, pos);
     if (state.forceBool(res, pos)) {
       right->push_back(elem);
@@ -1790,7 +1790,10 @@ static void prim_substring(EvalState& state, const Pos& pos, Value** args,
                     pos);
   }
 
-  mkString(v, (unsigned int)start >= s.size() ? "" : std::string(s, start, len),
+  mkString(v,
+           static_cast<unsigned int>(start) >= s.size()
+               ? ""
+               : std::string(s, start, len),
            context);
 }
 
@@ -1875,7 +1878,7 @@ static void prim_split(EvalState& state, const Pos& pos, Value** args,
     const size_t len = std::distance(begin, end);
     state.mkList(v, 2 * len + 1);
     size_t idx = 0;
-    Value* elem;
+    Value* elem = nullptr;
 
     if (len == 0) {
       (*v.list)[idx++] = args[1];
@@ -2138,7 +2141,7 @@ void EvalState::createBaseEnv() {
   baseEnv.up = nullptr;
 
   /* Add global constants such as `true' to the base environment. */
-  Value v;
+  Value v{};
 
   /* `builtins' must be first! */
   mkAttrs(v, 128);
diff --git a/third_party/nix/src/libexpr/primops/context.cc b/third_party/nix/src/libexpr/primops/context.cc
index 841a45c61c03..fb8879ead16d 100644
--- a/third_party/nix/src/libexpr/primops/context.cc
+++ b/third_party/nix/src/libexpr/primops/context.cc
@@ -97,12 +97,13 @@ static void prim_getContext(EvalState& state, const Pos& pos, Value** args,
           ContextInfo{isPath, isAllOutputs,
                       output.empty() ? Strings{} : Strings{std::move(output)}});
     } else {
-      if (isPath)
+      if (isPath) {
         iter->second.path = true;
-      else if (isAllOutputs)
+      } else if (isAllOutputs) {
         iter->second.allOutputs = true;
-      else
+      } else {
         iter->second.outputs.emplace_back(std::move(output));
+      }
     }
   }
 
@@ -116,8 +117,9 @@ static void prim_getContext(EvalState& state, const Pos& pos, Value** args,
     if (info.second.path) {
       mkBool(*state.allocAttr(infoVal, sPath), true);
     }
-    if (info.second.allOutputs)
+    if (info.second.allOutputs) {
       mkBool(*state.allocAttr(infoVal, sAllOutputs), true);
+    }
     if (!info.second.outputs.empty()) {
       auto& outputsVal = *state.allocAttr(infoVal, state.sOutputs);
       state.mkList(outputsVal, info.second.outputs.size());
@@ -147,9 +149,10 @@ static void prim_appendContext(EvalState& state, const Pos& pos, Value** args,
   auto sAllOutputs = state.symbols.Create("allOutputs");
   for (const auto& attr_iter : *args[1]->attrs) {
     const Attr* i = &attr_iter.second;  // TODO(tazjin): get rid of this
-    if (!state.store->isStorePath(i->name))
+    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);
     }
diff --git a/third_party/nix/src/libexpr/primops/fetchGit.cc b/third_party/nix/src/libexpr/primops/fetchGit.cc
index 7262a291559f..839094b72b53 100644
--- a/third_party/nix/src/libexpr/primops/fetchGit.cc
+++ b/third_party/nix/src/libexpr/primops/fetchGit.cc
@@ -30,8 +30,9 @@ std::regex revRegex("^[0-9a-fA-F]{40}$");
 GitInfo exportGit(ref<Store> store, const std::string& uri,
                   std::optional<std::string> ref, std::string rev,
                   const std::string& name) {
-  if (evalSettings.pureEval && rev == "")
+  if (evalSettings.pureEval && rev == "") {
     throw Error("in pure evaluation mode, 'fetchGit' requires a Git revision");
+  }
 
   if (!ref && rev == "" && absl::StartsWith(uri, "/") &&
       pathExists(uri + "/.git")) {
@@ -90,8 +91,9 @@ GitInfo exportGit(ref<Store> store, const std::string& uri,
     ref = "HEAD"s;
   }
 
-  if (rev != "" && !std::regex_match(rev, revRegex))
+  if (rev != "" && !std::regex_match(rev, revRegex)) {
     throw Error("invalid Git revision '%s'", rev);
+  }
 
   deletePath(getCacheDir() + "/nix/git");
 
@@ -104,12 +106,13 @@ GitInfo exportGit(ref<Store> store, const std::string& uri,
   }
 
   Path localRefFile;
-  if (ref->compare(0, 5, "refs/") == 0)
+  if (ref->compare(0, 5, "refs/") == 0) {
     localRefFile = cacheDir + "/" + *ref;
-  else
+  } else {
     localRefFile = cacheDir + "/refs/heads/" + *ref;
+  }
 
-  bool doFetch;
+  bool doFetch = 0;
   time_t now = time(0);
   /* If a rev was specified, we need to fetch if it's not in the
      repo. */
@@ -127,9 +130,10 @@ GitInfo exportGit(ref<Store> store, const std::string& uri,
   } else {
     /* If the local ref is older than ‘tarball-ttl’ seconds, do a
        git fetch to update the local ref to the remote ref. */
-    struct stat st;
+    struct stat st {};
     doFetch = stat(localRefFile.c_str(), &st) != 0 ||
-              (uint64_t)st.st_mtime + settings.tarballTtl <= (uint64_t)now;
+              static_cast<uint64_t>(st.st_mtime) + settings.tarballTtl <=
+                  static_cast<uint64_t>(now);
   }
   if (doFetch) {
     DLOG(INFO) << "fetching Git repository '" << uri << "'";
@@ -225,22 +229,24 @@ static void prim_fetchGit(EvalState& state, const Pos& pos, Value** args,
     for (auto& attr_iter : *args[0]->attrs) {
       auto& attr = attr_iter.second;
       std::string n(attr.name);
-      if (n == "url")
+      if (n == "url") {
         url =
             state.coerceToString(*attr.pos, *attr.value, context, false, false);
-      else if (n == "ref")
+      } else if (n == "ref") {
         ref = state.forceStringNoCtx(*attr.value, *attr.pos);
-      else if (n == "rev")
+      } else if (n == "rev") {
         rev = state.forceStringNoCtx(*attr.value, *attr.pos);
-      else if (n == "name")
+      } else if (n == "name") {
         name = state.forceStringNoCtx(*attr.value, *attr.pos);
-      else
+      } else {
         throw EvalError("unsupported argument '%s' to 'fetchGit', at %s",
                         attr.name, *attr.pos);
+      }
     }
 
-    if (url.empty())
+    if (url.empty()) {
       throw EvalError(format("'url' argument required, at %1%") % pos);
+    }
 
   } else {
     url = state.coerceToString(pos, *args[0], context, false, false);
diff --git a/third_party/nix/src/libexpr/primops/fetchMercurial.cc b/third_party/nix/src/libexpr/primops/fetchMercurial.cc
index 3ece094e6a8d..05a3d66ae7ca 100644
--- a/third_party/nix/src/libexpr/primops/fetchMercurial.cc
+++ b/third_party/nix/src/libexpr/primops/fetchMercurial.cc
@@ -28,10 +28,11 @@ std::regex commitHashRegex("^[0-9a-fA-F]{40}$");
 
 HgInfo exportMercurial(ref<Store> store, const std::string& uri,
                        std::string rev, const std::string& name) {
-  if (evalSettings.pureEval && rev == "")
+  if (evalSettings.pureEval && rev == "") {
     throw Error(
         "in pure evaluation mode, 'fetchMercurial' requires a Mercurial "
         "revision");
+  }
 
   if (rev == "" && absl::StartsWith(uri, "/") && pathExists(uri + "/.hg")) {
     bool clean = runProgram("hg", true,
@@ -90,9 +91,10 @@ HgInfo exportMercurial(ref<Store> store, const std::string& uri,
   /* If we haven't pulled this repo less than ‘tarball-ttl’ seconds,
      do so now. */
   time_t now = time(0);
-  struct stat st;
+  struct stat st {};
   if (stat(stampFile.c_str(), &st) != 0 ||
-      (uint64_t)st.st_mtime + settings.tarballTtl <= (uint64_t)now) {
+      static_cast<uint64_t>(st.st_mtime) + settings.tarballTtl <=
+          static_cast<uint64_t>(now)) {
     /* Except that if this is a commit hash that we already have,
        we don't have to pull again. */
     if (!(std::regex_match(rev, commitHashRegex) && pathExists(cacheDir) &&
@@ -198,20 +200,22 @@ static void prim_fetchMercurial(EvalState& state, const Pos& pos, Value** args,
     for (auto& attr_iter : *args[0]->attrs) {
       auto& attr = attr_iter.second;
       std::string n(attr.name);
-      if (n == "url")
+      if (n == "url") {
         url =
             state.coerceToString(*attr.pos, *attr.value, context, false, false);
-      else if (n == "rev")
+      } else if (n == "rev") {
         rev = state.forceStringNoCtx(*attr.value, *attr.pos);
-      else if (n == "name")
+      } else if (n == "name") {
         name = state.forceStringNoCtx(*attr.value, *attr.pos);
-      else
+      } else {
         throw EvalError("unsupported argument '%s' to 'fetchMercurial', at %s",
                         attr.name, *attr.pos);
+      }
     }
 
-    if (url.empty())
+    if (url.empty()) {
       throw EvalError(format("'url' argument required, at %1%") % pos);
+    }
 
   } else {
     url = state.coerceToString(pos, *args[0], context, false, false);
diff --git a/third_party/nix/src/libexpr/primops/fromTOML.cc b/third_party/nix/src/libexpr/primops/fromTOML.cc
index 389ac080677a..e3d2a4940769 100644
--- a/third_party/nix/src/libexpr/primops/fromTOML.cc
+++ b/third_party/nix/src/libexpr/primops/fromTOML.cc
@@ -30,10 +30,12 @@ static void prim_fromTOML(EvalState& state, const Pos& pos, Value** args,
         if (auto i2 = i.second->as_table_array()) {
           size_t size2 = i2->get().size();
           state.mkList(v2, size2);
-          for (size_t j = 0; j < size2; ++j)
+          for (size_t j = 0; j < size2; ++j) {
             visit(*((*v2.list)[j] = state.allocValue()), i2->get()[j]);
-        } else
+          }
+        } else {
           visit(v2, i.second);
+        }
       }
     }
 
@@ -42,8 +44,9 @@ static void prim_fromTOML(EvalState& state, const Pos& pos, Value** args,
 
       state.mkList(v, size);
 
-      for (size_t i = 0; i < size; ++i)
+      for (size_t i = 0; i < size; ++i) {
         visit(*((*v.list)[i] = state.allocValue()), t2->get()[i]);
+      }
     }
 
     // Handle cases like 'a = [[{ a = true }]]', which IMHO should be
@@ -55,25 +58,28 @@ static void prim_fromTOML(EvalState& state, const Pos& pos, Value** args,
 
       state.mkList(v, size);
 
-      for (size_t j = 0; j < size; ++j)
+      for (size_t j = 0; j < size; ++j) {
         visit(*((*v.list)[j] = state.allocValue()), t2->get()[j]);
+      }
     }
 
     else if (t->is_value()) {
-      if (auto val = t->as<int64_t>())
+      if (auto val = t->as<int64_t>()) {
         mkInt(v, val->get());
-      else if (auto val = t->as<NixFloat>())
+      } else if (auto val = t->as<NixFloat>()) {
         mkFloat(v, val->get());
-      else if (auto val = t->as<bool>())
+      } else if (auto val = t->as<bool>()) {
         mkBool(v, val->get());
-      else if (auto val = t->as<std::string>())
+      } else if (auto val = t->as<std::string>()) {
         mkString(v, val->get());
-      else
+      } else {
         throw EvalError("unsupported value type in TOML");
+      }
     }
 
-    else
+    else {
       abort();
+    }
   };
 
   try {