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/common-eval-args.cc3
-rw-r--r--third_party/nix/src/libexpr/eval.cc88
-rw-r--r--third_party/nix/src/libexpr/eval.hh4
-rw-r--r--third_party/nix/src/libexpr/get-drvs.cc42
-rw-r--r--third_party/nix/src/libexpr/json-to-value.cc11
-rw-r--r--third_party/nix/src/libexpr/names.cc25
-rw-r--r--third_party/nix/src/libexpr/nixexpr.cc14
-rw-r--r--third_party/nix/src/libexpr/primops.cc61
-rw-r--r--third_party/nix/src/libexpr/value-to-xml.cc2
9 files changed, 130 insertions, 120 deletions
diff --git a/third_party/nix/src/libexpr/common-eval-args.cc b/third_party/nix/src/libexpr/common-eval-args.cc
index 7af4d6b276..7a87841c9b 100644
--- a/third_party/nix/src/libexpr/common-eval-args.cc
+++ b/third_party/nix/src/libexpr/common-eval-args.cc
@@ -53,7 +53,8 @@ Path lookupFileArg(EvalState& state, string s) {
     CachedDownloadRequest request(s);
     request.unpack = true;
     return getDownloader()->downloadCached(state.store, request).path;
-  } else if (s.size() > 2 && s.at(0) == '<' && s.at(s.size() - 1) == '>') {
+  }
+  if (s.size() > 2 && s.at(0) == '<' && s.at(s.size() - 1) == '>') {
     Path p = s.substr(1, s.size() - 2);
     return state.findFile(p);
   } else {
diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc
index 44f55dd687..4be301167b 100644
--- a/third_party/nix/src/libexpr/eval.cc
+++ b/third_party/nix/src/libexpr/eval.cc
@@ -37,7 +37,7 @@ static char* dupString(const char* s) {
 #else
   t = strdup(s);
 #endif
-  if (!t) {
+  if (t == nullptr) {
     throw std::bad_alloc();
   }
   return t;
@@ -62,7 +62,7 @@ static void printValue(std::ostream& str, std::set<const Value*>& active,
       break;
     case tString:
       str << "\"";
-      for (const char* i = v.string.s; *i; i++) {
+      for (const char* i = v.string.s; *i != 0; i++) {
         if (*i == '\"' || *i == '\\') {
           str << "\\" << *i;
         } else if (*i == '\n') {
@@ -151,7 +151,7 @@ string showType(const Value& v) {
     case tBool:
       return "a boolean";
     case tString:
-      return v.string.context ? "a string with context" : "a string";
+      return v.string.context != nullptr ? "a string with context" : "a string";
     case tPath:
       return "a path";
     case tNull:
@@ -194,12 +194,11 @@ static void* oomHandler(size_t requested) {
 static Symbol getName(const AttrName& name, EvalState& state, Env& env) {
   if (name.symbol.set()) {
     return name.symbol;
-  } else {
-    Value nameValue;
-    name.expr->eval(state, env, nameValue);
-    state.forceStringNoCtx(nameValue);
-    return state.symbols.create(nameValue.string.s);
   }
+  Value nameValue;
+  name.expr->eval(state, env, nameValue);
+  state.forceStringNoCtx(nameValue);
+  return state.symbols.create(nameValue.string.s);
 }
 
 static bool gcInitialised = false;
@@ -233,7 +232,7 @@ void initGC() {
      that GC_expand_hp() causes a lot of virtual, but not physical
      (resident) memory to be allocated.  This might be a problem on
      systems that don't overcommit. */
-  if (!getenv("GC_INITIAL_HEAP_SIZE")) {
+  if (getenv("GC_INITIAL_HEAP_SIZE") == nullptr) {
     size_t size = 32 * 1024 * 1024;
 #if HAVE_SYSCONF && defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES)
     size_t maxSize = 384 * 1024 * 1024;
@@ -436,7 +435,7 @@ void EvalState::checkURI(const std::string& uri) {
      'https://' as prefixes for any http/https URI. */
   for (auto& prefix : evalSettings.allowedUris.get()) {
     if (uri == prefix ||
-        (uri.size() > prefix.size() && prefix.size() > 0 &&
+        (uri.size() > prefix.size() && !prefix.empty() &&
          hasPrefix(uri, prefix) &&
          (prefix[prefix.size() - 1] == '/' || uri[prefix.size()] == '/'))) {
       return;
@@ -583,7 +582,7 @@ 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 != 0u; --l, env = env->up) {
     ;
   }
 
@@ -603,16 +602,16 @@ 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) {
+      if (countCalls && (j->pos != nullptr)) {
         attrSelects[*j->pos]++;
       }
       return j->value;
     }
-    if (!env->prevWith) {
+    if (env->prevWith == 0u) {
       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 != 0u; --l, env = env->up) {
       ;
     }
   }
@@ -657,7 +656,7 @@ void EvalState::mkList(Value& v, size_t size) {
     v.type = tListN;
     v.bigList.size = size;
     v.bigList.elems =
-        size ? (Value**)allocBytes(size * sizeof(Value*)) : nullptr;
+        size != 0u ? (Value**)allocBytes(size * sizeof(Value*)) : nullptr;
   }
   nrListElems += size;
 }
@@ -674,7 +673,7 @@ static inline void mkThunk(Value& v, Env& env, Expr* expr) {
 void EvalState::mkThunk_(Value& v, Expr* expr) { mkThunk(v, baseEnv, expr); }
 
 void EvalState::mkPos(Value& v, Pos* pos) {
-  if (pos && pos->file.set()) {
+  if ((pos != nullptr) && pos->file.set()) {
     mkAttrs(v, 3);
     mkString(*allocAttr(v, sFile), pos->file);
     mkInt(*allocAttr(v, sLine), pos->line);
@@ -701,7 +700,7 @@ Value* ExprVar::maybeThunk(EvalState& state, Env& env) {
   Value* v = state.lookupVar(&env, *this, true);
   /* The value might not be initialised in the environment yet.
      In that case, ignore it. */
-  if (v) {
+  if (v != nullptr) {
     nrAvoided++;
     return v;
   }
@@ -751,7 +750,7 @@ void EvalState::evalFile(const Path& path_, Value& v) {
     e = j->second;
   }
 
-  if (!e) {
+  if (e == nullptr) {
     e = parseExprFromFile(checkSourcePath(path2));
   }
 
@@ -966,7 +965,7 @@ void ExprSelect::eval(EvalState& state, Env& env, Value& v) {
       nrLookups++;
       Bindings::iterator j;
       Symbol name = getName(i, state, env);
-      if (def) {
+      if (def != nullptr) {
         state.forceValue(*vAttrs, pos);
         if (vAttrs->type != tAttrs ||
             (j = vAttrs->attrs->find(name)) == vAttrs->attrs->end()) {
@@ -981,7 +980,7 @@ void ExprSelect::eval(EvalState& state, Env& env, Value& v) {
       }
       vAttrs = j->value;
       pos2 = j->pos;
-      if (state.countCalls && pos2) {
+      if (state.countCalls && (pos2 != nullptr)) {
         state.attrSelects[*pos2]++;
       }
     }
@@ -989,7 +988,7 @@ void ExprSelect::eval(EvalState& state, Env& env, Value& v) {
     state.forceValue(*vAttrs, (pos2 != nullptr ? *pos2 : this->pos));
 
   } catch (Error& e) {
-    if (pos2 && pos2->file != state.sDerivationNix) {
+    if ((pos2 != nullptr) && pos2->file != state.sDerivationNix) {
       addErrorPrefix(e, "while evaluating the attribute '%1%' at %2%:\n",
                      showAttrPath(state, env, attrPath), *pos2);
     }
@@ -1013,9 +1012,8 @@ void ExprOpHasAttr::eval(EvalState& state, Env& env, Value& v) {
         (j = vAttrs->attrs->find(name)) == vAttrs->attrs->end()) {
       mkBool(v, false);
       return;
-    } else {
-      vAttrs = j->value;
     }
+    vAttrs = j->value;
   }
 
   mkBool(v, true);
@@ -1133,7 +1131,7 @@ void EvalState::callFunction(Value& fun, Value& arg, Value& v, const Pos& pos) {
     for (auto& i : lambda.formals->formals) {
       Bindings::iterator j = arg.attrs->find(i.name);
       if (j == arg.attrs->end()) {
-        if (!i.def) {
+        if (i.def == nullptr) {
           throwTypeError("%1% called without required argument '%2%', at %3%",
                          lambda, i.name, pos);
         }
@@ -1209,7 +1207,7 @@ void EvalState::autoCallFunction(Bindings& args, Value& fun, Value& res) {
     Bindings::iterator j = args.find(i.name);
     if (j != args.end()) {
       actualArgs->attrs->push_back(*j);
-    } else if (!i.def) {
+    } else if (i.def == nullptr) {
       throwTypeError(
           "cannot auto-call a function that has an argument without a default "
           "value ('%1%')",
@@ -1278,17 +1276,18 @@ void ExprOpImpl::eval(EvalState& state, Env& env, Value& v) {
 }
 
 void ExprOpUpdate::eval(EvalState& state, Env& env, Value& v) {
-  Value v1, v2;
+  Value v1;
+  Value v2;
   state.evalAttrs(env, e1, v1);
   state.evalAttrs(env, e2, v2);
 
   state.nrOpUpdates++;
 
-  if (v1.attrs->size() == 0) {
+  if (v1.attrs->empty()) {
     v = v2;
     return;
   }
-  if (v2.attrs->size() == 0) {
+  if (v2.attrs->empty()) {
     v = v1;
     return;
   }
@@ -1341,12 +1340,12 @@ void EvalState::concatLists(Value& v, size_t nrLists, Value** lists,
     forceList(*lists[n], pos);
     auto l = lists[n]->listSize();
     len += l;
-    if (l) {
+    if (l != 0u) {
       nonEmpty = lists[n];
     }
   }
 
-  if (nonEmpty && len == nonEmpty->listSize()) {
+  if ((nonEmpty != nullptr) && len == nonEmpty->listSize()) {
     v = *nonEmpty;
     return;
   }
@@ -1355,7 +1354,7 @@ 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) {
+    if (l != 0u) {
       memcpy(out + pos, lists[n]->listElems(), l * sizeof(Value*));
     }
     pos += l;
@@ -1479,7 +1478,8 @@ NixFloat EvalState::forceFloat(Value& v, const Pos& pos) {
   forceValue(v, pos);
   if (v.type == tInt) {
     return v.integer;
-  } else if (v.type != tFloat) {
+  }
+  if (v.type != tFloat) {
     throwTypeError("value is %1% while a float was expected, at %2%", v, pos);
   }
   return v.fpoint;
@@ -1520,8 +1520,8 @@ string EvalState::forceString(Value& v, const Pos& pos) {
 }
 
 void copyContext(const Value& v, PathSet& context) {
-  if (v.string.context) {
-    for (const char** p = v.string.context; *p; ++p) {
+  if (v.string.context != nullptr) {
+    for (const char** p = v.string.context; *p != nullptr; ++p) {
       context.insert(*p);
     }
   }
@@ -1535,7 +1535,7 @@ string EvalState::forceString(Value& v, PathSet& context, const Pos& pos) {
 
 string EvalState::forceStringNoCtx(Value& v, const Pos& pos) {
   string s = forceString(v, pos);
-  if (v.string.context) {
+  if (v.string.context != nullptr) {
     if (pos) {
       throwEvalError(
           "the string '%1%' is not allowed to refer to a store path (such as "
@@ -1657,7 +1657,7 @@ string EvalState::copyPathToStore(PathSet& context, const Path& path) {
   }
 
   Path dstPath;
-  if (srcToStore[path] != "") {
+  if (!srcToStore[path].empty()) {
     dstPath = srcToStore[path];
   } else {
     dstPath =
@@ -1678,7 +1678,7 @@ string EvalState::copyPathToStore(PathSet& context, const Path& path) {
 
 Path EvalState::coerceToPath(const Pos& pos, Value& v, PathSet& context) {
   string path = coerceToString(pos, v, context, false, false);
-  if (path == "" || path[0] != '/') {
+  if (path.empty() || path[0] != '/') {
     throwEvalError("string '%1%' doesn't represent an absolute path, at %2%",
                    path, pos);
   }
@@ -1754,7 +1754,8 @@ bool EvalState::eqValues(Value& v1, Value& v2) {
       }
 
       /* Otherwise, compare the attributes one by one. */
-      Bindings::iterator i, j;
+      Bindings::iterator i;
+      Bindings::iterator 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)) {
@@ -1796,7 +1797,8 @@ void EvalState::printStats() {
       nrAttrsets * sizeof(Bindings) + nrAttrsInAttrsets * sizeof(Attr);
 
 #if HAVE_BOEHMGC
-  GC_word heapSize, totalBytes;
+  GC_word heapSize;
+  GC_word totalBytes;
   GC_get_heap_usage_safe(&heapSize, nullptr, nullptr, nullptr, &totalBytes);
 #endif
   if (showStats) {
@@ -1927,8 +1929,8 @@ size_t valueSize(Value& v) {
     switch (v.type) {
       case tString:
         sz += doString(v.string.s);
-        if (v.string.context) {
-          for (const char** p = v.string.context; *p; ++p) {
+        if (v.string.context != nullptr) {
+          for (const char** p = v.string.context; *p != nullptr; ++p) {
             sz += doString(*p);
           }
         }
@@ -1993,13 +1995,13 @@ size_t valueSize(Value& v) {
 
     if (env.type != Env::HasWithExpr) {
       for (size_t i = 0; i < env.size; ++i) {
-        if (env.values[i]) {
+        if (env.values[i] != nullptr) {
           sz += doValue(*env.values[i]);
         }
       }
     }
 
-    if (env.up) {
+    if (env.up != nullptr) {
       sz += doEnv(*env.up);
     }
 
diff --git a/third_party/nix/src/libexpr/eval.hh b/third_party/nix/src/libexpr/eval.hh
index a74bd2dfd3..48c67b6229 100644
--- a/third_party/nix/src/libexpr/eval.hh
+++ b/third_party/nix/src/libexpr/eval.hh
@@ -257,9 +257,9 @@ class EvalState {
 
   Value* allocAttr(Value& vAttrs, const Symbol& name);
 
-  Bindings* allocBindings(size_t capacity);
+  static Bindings* allocBindings(size_t capacity);
 
-  void mkList(Value& v, size_t length);
+  void mkList(Value& v, size_t size);
   void mkAttrs(Value& v, size_t capacity);
   void mkThunk_(Value& v, Expr* expr);
   void mkPos(Value& v, Pos* pos);
diff --git a/third_party/nix/src/libexpr/get-drvs.cc b/third_party/nix/src/libexpr/get-drvs.cc
index aa73c01fd1..c4afc0fb45 100644
--- a/third_party/nix/src/libexpr/get-drvs.cc
+++ b/third_party/nix/src/libexpr/get-drvs.cc
@@ -45,7 +45,7 @@ DrvInfo::DrvInfo(EvalState& state, ref<Store> store,
 }
 
 string DrvInfo::queryName() const {
-  if (name == "" && attrs) {
+  if (name.empty() && (attrs != nullptr)) {
     auto i = attrs->find(state->sName);
     if (i == attrs->end()) {
       throw TypeError("derivation name missing");
@@ -56,7 +56,7 @@ string DrvInfo::queryName() const {
 }
 
 string DrvInfo::querySystem() const {
-  if (system == "" && attrs) {
+  if (system.empty() && (attrs != nullptr)) {
     auto i = attrs->find(state->sSystem);
     system = i == attrs->end() ? "unknown"
                                : state->forceStringNoCtx(*i->value, *i->pos);
@@ -65,7 +65,7 @@ string DrvInfo::querySystem() const {
 }
 
 string DrvInfo::queryDrvPath() const {
-  if (drvPath == "" && attrs) {
+  if (drvPath.empty() && (attrs != nullptr)) {
     Bindings::iterator i = attrs->find(state->sDrvPath);
     PathSet context;
     drvPath = i != attrs->end()
@@ -76,7 +76,7 @@ string DrvInfo::queryDrvPath() const {
 }
 
 string DrvInfo::queryOutPath() const {
-  if (outPath == "" && attrs) {
+  if (outPath.empty() && (attrs != nullptr)) {
     Bindings::iterator i = attrs->find(state->sOutPath);
     PathSet context;
     outPath = i != attrs->end()
@@ -90,7 +90,8 @@ DrvInfo::Outputs DrvInfo::queryOutputs(bool onlyOutputsToInstall) {
   if (outputs.empty()) {
     /* Get the ‘outputs’ list. */
     Bindings::iterator i;
-    if (attrs && (i = attrs->find(state->sOutputs)) != attrs->end()) {
+    if ((attrs != nullptr) &&
+        (i = attrs->find(state->sOutputs)) != attrs->end()) {
       state->forceList(*i->value, *i->pos);
 
       /* For each output... */
@@ -117,13 +118,13 @@ DrvInfo::Outputs DrvInfo::queryOutputs(bool onlyOutputsToInstall) {
       outputs["out"] = queryOutPath();
     }
   }
-  if (!onlyOutputsToInstall || !attrs) {
+  if (!onlyOutputsToInstall || (attrs == nullptr)) {
     return outputs;
   }
 
   /* Check for `meta.outputsToInstall` and return `outputs` reduced to that. */
   const Value* outTI = queryMeta("outputsToInstall");
-  if (!outTI) {
+  if (outTI == nullptr) {
     return outputs;
   }
   const auto errMsg = Error("this derivation has bad 'meta.outputsToInstall'");
@@ -147,7 +148,7 @@ DrvInfo::Outputs DrvInfo::queryOutputs(bool onlyOutputsToInstall) {
 }
 
 string DrvInfo::queryOutputName() const {
-  if (outputName == "" && attrs) {
+  if (outputName.empty() && (attrs != nullptr)) {
     Bindings::iterator i = attrs->find(state->sOutputName);
     outputName = i != attrs->end() ? state->forceStringNoCtx(*i->value) : "";
   }
@@ -155,10 +156,10 @@ string DrvInfo::queryOutputName() const {
 }
 
 Bindings* DrvInfo::getMeta() {
-  if (meta) {
+  if (meta != nullptr) {
     return meta;
   }
-  if (!attrs) {
+  if (attrs == nullptr) {
     return nullptr;
   }
   Bindings::iterator a = attrs->find(state->sMeta);
@@ -172,7 +173,7 @@ Bindings* DrvInfo::getMeta() {
 
 StringSet DrvInfo::queryMetaNames() {
   StringSet res;
-  if (!getMeta()) {
+  if (getMeta() == nullptr) {
     return res;
   }
   for (auto& i : *meta) {
@@ -190,7 +191,8 @@ bool DrvInfo::checkMeta(Value& v) {
       }
     }
     return true;
-  } else if (v.type == tAttrs) {
+  }
+  if (v.type == tAttrs) {
     Bindings::iterator i = v.attrs->find(state->sOutPath);
     if (i != v.attrs->end()) {
       return false;
@@ -208,7 +210,7 @@ bool DrvInfo::checkMeta(Value& v) {
 }
 
 Value* DrvInfo::queryMeta(const string& name) {
-  if (!getMeta()) {
+  if (getMeta() == nullptr) {
     return nullptr;
   }
   Bindings::iterator a = meta->find(state->symbols.create(name));
@@ -220,7 +222,7 @@ Value* DrvInfo::queryMeta(const string& name) {
 
 string DrvInfo::queryMetaString(const string& name) {
   Value* v = queryMeta(name);
-  if (!v || v->type != tString) {
+  if ((v == nullptr) || v->type != tString) {
     return "";
   }
   return v->string.s;
@@ -228,7 +230,7 @@ string DrvInfo::queryMetaString(const string& name) {
 
 NixInt DrvInfo::queryMetaInt(const string& name, NixInt def) {
   Value* v = queryMeta(name);
-  if (!v) {
+  if (v == nullptr) {
     return def;
   }
   if (v->type == tInt) {
@@ -247,7 +249,7 @@ NixInt DrvInfo::queryMetaInt(const string& name, NixInt def) {
 
 NixFloat DrvInfo::queryMetaFloat(const string& name, NixFloat def) {
   Value* v = queryMeta(name);
-  if (!v) {
+  if (v == nullptr) {
     return def;
   }
   if (v->type == tFloat) {
@@ -266,7 +268,7 @@ NixFloat DrvInfo::queryMetaFloat(const string& name, NixFloat def) {
 
 bool DrvInfo::queryMetaBool(const string& name, bool def) {
   Value* v = queryMeta(name);
-  if (!v) {
+  if (v == nullptr) {
     return def;
   }
   if (v->type == tBool) {
@@ -288,16 +290,16 @@ bool DrvInfo::queryMetaBool(const string& name, bool def) {
 void DrvInfo::setMeta(const string& name, Value* v) {
   getMeta();
   Bindings* old = meta;
-  meta = state->allocBindings(1 + (old ? old->size() : 0));
+  meta = state->allocBindings(1 + (old != nullptr ? old->size() : 0));
   Symbol sym = state->symbols.create(name);
-  if (old) {
+  if (old != nullptr) {
     for (auto i : *old) {
       if (i.name != sym) {
         meta->push_back(i);
       }
     }
   }
-  if (v) {
+  if (v != nullptr) {
     meta->push_back(Attr(sym, v));
   }
   meta->sort();
diff --git a/third_party/nix/src/libexpr/json-to-value.cc b/third_party/nix/src/libexpr/json-to-value.cc
index 122bd2ad31..68f016904e 100644
--- a/third_party/nix/src/libexpr/json-to-value.cc
+++ b/third_party/nix/src/libexpr/json-to-value.cc
@@ -16,7 +16,7 @@ static string parseJSONString(const char*& s) {
     throw JSONParseError("expected JSON string");
   }
   while (*s != '"') {
-    if (!*s) {
+    if (*s == 0) {
       throw JSONParseError("got end-of-string in JSON string");
     }
     if (*s == '\\') {
@@ -57,7 +57,7 @@ static string parseJSONString(const char*& s) {
 static void parseJSON(EvalState& state, const char*& s, Value& v) {
   skipWhitespace(s);
 
-  if (!*s) {
+  if (*s == 0) {
     throw JSONParseError("expected JSON value");
   }
 
@@ -127,12 +127,13 @@ static void parseJSON(EvalState& state, const char*& s, Value& v) {
     mkString(v, parseJSONString(s));
   }
 
-  else if (isdigit(*s) || *s == '-' || *s == '.') {
+  else if ((isdigit(*s) != 0) || *s == '-' || *s == '.') {
     // Buffer into a string first, then use built-in C++ conversions
     std::string tmp_number;
     ValueType number_type = tInt;
 
-    while (isdigit(*s) || *s == '-' || *s == '.' || *s == 'e' || *s == 'E') {
+    while ((isdigit(*s) != 0) || *s == '-' || *s == '.' || *s == 'e' ||
+           *s == 'E') {
       if (*s == '.' || *s == 'e' || *s == 'E') {
         number_type = tFloat;
       }
@@ -176,7 +177,7 @@ void parseJSON(EvalState& state, const string& s_, Value& v) {
   const char* s = s_.c_str();
   parseJSON(state, s, v);
   skipWhitespace(s);
-  if (*s) {
+  if (*s != 0) {
     throw JSONParseError(
         format("expected end-of-string while parsing JSON value: %1%") % s);
   }
diff --git a/third_party/nix/src/libexpr/names.cc b/third_party/nix/src/libexpr/names.cc
index ecad90c960..f559c13a61 100644
--- a/third_party/nix/src/libexpr/names.cc
+++ b/third_party/nix/src/libexpr/names.cc
@@ -17,7 +17,7 @@ DrvName::DrvName(const string& s) : hits(0) {
   name = fullName = s;
   for (unsigned int i = 0; i < s.size(); ++i) {
     /* !!! isalpha/isdigit are affected by the locale. */
-    if (s[i] == '-' && i + 1 < s.size() && !isalpha(s[i + 1])) {
+    if (s[i] == '-' && i + 1 < s.size() && (isalpha(s[i + 1]) == 0)) {
       name = string(s, 0, i);
       version = string(s, i + 1);
       break;
@@ -34,10 +34,7 @@ bool DrvName::matches(DrvName& n) {
       return false;
     }
   }
-  if (version != "" && version != n.version) {
-    return false;
-  }
-  return true;
+  return !(!version.empty() && version != n.version);
 }
 
 string nextComponent(string::const_iterator& p,
@@ -55,12 +52,12 @@ string nextComponent(string::const_iterator& p,
      of digits.  Otherwise, consume the longest sequence of
      non-digit, non-separator characters. */
   string s;
-  if (isdigit(*p)) {
-    while (p != end && isdigit(*p)) {
+  if (isdigit(*p) != 0) {
+    while (p != end && (isdigit(*p) != 0)) {
       s += *p++;
     }
   } else {
-    while (p != end && (!isdigit(*p) && *p != '.' && *p != '-')) {
+    while (p != end && ((isdigit(*p) == 0) && *p != '.' && *p != '-')) {
       s += *p++;
     }
   }
@@ -69,12 +66,15 @@ string nextComponent(string::const_iterator& p,
 }
 
 static bool componentsLT(const string& c1, const string& c2) {
-  int n1, n2;
-  bool c1Num = string2Int(c1, n1), c2Num = string2Int(c2, n2);
+  int n1;
+  int n2;
+  bool c1Num = string2Int(c1, n1);
+  bool c2Num = string2Int(c2, n2);
 
   if (c1Num && c2Num) {
     return n1 < n2;
-  } else if (c1 == "" && c2Num) {
+  }
+  if (c1.empty() && c2Num) {
     return true;
   } else if (c1 == "pre" && c2 != "pre") {
     return true;
@@ -99,7 +99,8 @@ int compareVersions(const string& v1, const string& v2) {
     string c2 = nextComponent(p2, v2.end());
     if (componentsLT(c1, c2)) {
       return -1;
-    } else if (componentsLT(c2, c1)) {
+    }
+    if (componentsLT(c2, c1)) {
       return 1;
     }
   }
diff --git a/third_party/nix/src/libexpr/nixexpr.cc b/third_party/nix/src/libexpr/nixexpr.cc
index 55b9d54577..22be923404 100644
--- a/third_party/nix/src/libexpr/nixexpr.cc
+++ b/third_party/nix/src/libexpr/nixexpr.cc
@@ -73,7 +73,7 @@ void ExprVar::show(std::ostream& str) const { str << name; }
 
 void ExprSelect::show(std::ostream& str) const {
   str << "(" << *e << ")." << showAttrPath(attrPath);
-  if (def) {
+  if (def != nullptr) {
     str << " or (" << *def << ")";
   }
 }
@@ -121,7 +121,7 @@ void ExprLambda::show(std::ostream& str) const {
         str << ", ";
       }
       str << i.name;
-      if (i.def) {
+      if (i.def != nullptr) {
         str << " ? " << *i.def;
       }
     }
@@ -233,7 +233,8 @@ void ExprVar::bindVars(const StaticEnv& env) {
   const StaticEnv* curEnv;
   unsigned int level;
   int withLevel = -1;
-  for (curEnv = &env, level = 0; curEnv; curEnv = curEnv->up, level++) {
+  for (curEnv = &env, level = 0; curEnv != nullptr;
+       curEnv = curEnv->up, level++) {
     if (curEnv->isWith) {
       if (withLevel == -1) {
         withLevel = level;
@@ -263,7 +264,7 @@ void ExprVar::bindVars(const StaticEnv& env) {
 
 void ExprSelect::bindVars(const StaticEnv& env) {
   e->bindVars(env);
-  if (def) {
+  if (def != nullptr) {
     def->bindVars(env);
   }
   for (auto& i : attrPath) {
@@ -332,7 +333,7 @@ void ExprLambda::bindVars(const StaticEnv& env) {
     }
 
     for (auto& i : formals->formals) {
-      if (i.def) {
+      if (i.def != nullptr) {
         i.def->bindVars(newEnv);
       }
     }
@@ -363,7 +364,8 @@ 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 != nullptr;
+       curEnv = curEnv->up, level++) {
     if (curEnv->isWith) {
       prevWith = level;
       break;
diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc
index d576d4b619..7b73bec035 100644
--- a/third_party/nix/src/libexpr/primops.cc
+++ b/third_party/nix/src/libexpr/primops.cc
@@ -37,9 +37,8 @@ std::pair<string, string> decodeContext(const string& s) {
     size_t index = s.find("!", 1);
     return std::pair<string, string>(string(s, index + 1),
                                      string(s, 1, index - 1));
-  } else {
-    return std::pair<string, string>(s.at(0) == '/' ? s : string(s, 1), "");
   }
+  return std::pair<string, string>(s.at(0) == '/' ? s : string(s, 1), "");
 }
 
 InvalidPathError::InvalidPathError(const Path& path)
@@ -83,8 +82,11 @@ void EvalState::realiseContext(const PathSet& context) {
   }
 
   /* For performance, prefetch all substitute info. */
-  PathSet willBuild, willSubstitute, unknown;
-  unsigned long long downloadSize, narSize;
+  PathSet willBuild;
+  PathSet willSubstitute;
+  PathSet unknown;
+  unsigned long long downloadSize;
+  unsigned long long narSize;
   store->queryMissing(drvs, willBuild, willSubstitute, unknown, downloadSize,
                       narSize);
   store->buildPaths(drvs);
@@ -181,22 +183,21 @@ void prim_importNative(EvalState& state, const Pos& pos, Value** args,
   string sym = state.forceStringNoCtx(*args[1], pos);
 
   void* handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL);
-  if (!handle) {
+  if (handle == nullptr) {
     throw EvalError(format("could not open '%1%': %2%") % path % dlerror());
   }
 
   dlerror();
   auto func = (ValueInitializer)dlsym(handle, sym.c_str());
-  if (!func) {
+  if (func == nullptr) {
     char* message = dlerror();
-    if (message) {
+    if (message != nullptr) {
       throw EvalError(format("could not load symbol '%1%' from '%2%': %3%") %
                       sym % path % message);
-    } else {
-      throw EvalError(format("symbol '%1%' from '%2%' resolved to NULL when a "
-                             "function pointer was expected") %
-                      sym % path);
     }
+    throw EvalError(format("symbol '%1%' from '%2%' resolved to NULL when a "
+                           "function pointer was expected") %
+                    sym % path);
   }
 
   (func)(state, v);
@@ -765,11 +766,11 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
   }
 
   /* Do we have all required attributes? */
-  if (drv.builder == "") {
+  if (drv.builder.empty()) {
     throw EvalError(format("required attribute 'builder' missing, at %1%") %
                     posDrvName);
   }
-  if (drv.platform == "") {
+  if (drv.platform.empty()) {
     throw EvalError(format("required attribute 'system' missing, at %1%") %
                     posDrvName);
   }
@@ -822,7 +823,7 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
     Hash h = hashDerivationModulo(*state.store, drv);
 
     for (auto& i : drv.outputs) {
-      if (i.second.path == "") {
+      if (i.second.path.empty()) {
         Path outPath = state.store->makeOutputPath(i.first, h, drvName);
         if (!jsonObject) {
           drv.env[i.first] = outPath;
@@ -1134,7 +1135,7 @@ static void addPath(EvalState& state, const Pos& pos, const string& name,
   const auto path = evalSettings.pureEval && expectedHash
                         ? path_
                         : state.checkSourcePath(path_);
-  PathFilter filter = filterFun ? ([&](const Path& path) {
+  PathFilter filter = filterFun != nullptr ? ([&](const Path& path) {
     auto st = lstat(path);
 
     /* Call the filter function.  The first argument is the path,
@@ -1159,7 +1160,7 @@ static void addPath(EvalState& state, const Pos& pos, const string& name,
 
     return state.forceBool(res, pos);
   })
-                                : defaultPathFilter;
+                                           : defaultPathFilter;
 
   Path expectedStorePath;
   if (expectedHash) {
@@ -1305,7 +1306,7 @@ void prim_getAttr(EvalState& state, const Pos& pos, Value** args, Value& v) {
     throw EvalError(format("attribute '%1%' missing, at %2%") % attr % pos);
   }
   // !!! add to stack trace?
-  if (state.countCalls && i->pos) {
+  if (state.countCalls && (i->pos != nullptr)) {
     state.attrSelects[*i->pos]++;
   }
   state.forceValue(*i->value);
@@ -1485,7 +1486,7 @@ static void prim_functionArgs(EvalState& state, const Pos& pos, Value** args,
   state.mkAttrs(v, args[0]->lambda.fun->formals->formals.size());
   for (auto& i : args[0]->lambda.fun->formals->formals) {
     // !!! should optimise booleans (allocate only once)
-    mkBool(*state.allocAttr(v, i.name), i.def);
+    mkBool(*state.allocAttr(v, i.name), i.def != nullptr);
   }
   v.attrs->sort();
 }
@@ -1634,7 +1635,7 @@ static void prim_foldlStrict(EvalState& state, const Pos& pos, Value** args,
   state.forceFunction(*args[0], pos);
   state.forceList(*args[2], pos);
 
-  if (args[2]->listSize()) {
+  if (args[2]->listSize() != 0u) {
     Value* vCur = args[1];
 
     for (unsigned int n = 0; n < args[2]->listSize(); ++n) {
@@ -1716,7 +1717,8 @@ static void prim_sort(EvalState& state, const Pos& pos, Value** args,
       return CompareValues()(a, b);
     }
 
-    Value vTmp1, vTmp2;
+    Value vTmp1;
+    Value vTmp2;
     state.callFunction(*args[0], *a, vTmp1, pos);
     state.callFunction(vTmp1, *b, vTmp2, pos);
     return state.forceBool(vTmp2, pos);
@@ -1735,7 +1737,8 @@ static void prim_partition(EvalState& state, const Pos& pos, Value** args,
 
   auto len = args[1]->listSize();
 
-  ValueVector right, wrong;
+  ValueVector right;
+  ValueVector wrong;
 
   for (unsigned int n = 0; n < len; ++n) {
     auto vElem = args[1]->listElems()[n];
@@ -1754,14 +1757,14 @@ 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) {
+  if (rsize != 0u) {
     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) {
+  if (wsize != 0u) {
     memcpy(vWrong->listElems(), wrong.data(), sizeof(Value*) * wsize);
   }
 
@@ -1790,7 +1793,7 @@ 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) {
+    if (l != 0u) {
       memcpy(out + pos, lists[n].listElems(), l * sizeof(Value*));
     }
     pos += l;
@@ -1971,9 +1974,8 @@ static void prim_match(EvalState& state, const Pos& pos, Value** args,
       // limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
       throw EvalError("memory limit exceeded by regular expression '%s', at %s",
                       re, pos);
-    } else {
-      throw EvalError("invalid regular expression '%s', at %s", re, pos);
     }
+    throw EvalError("invalid regular expression '%s', at %s", re, pos);
   }
 }
 
@@ -2039,9 +2041,8 @@ static void prim_split(EvalState& state, const Pos& pos, Value** args,
       // limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
       throw EvalError("memory limit exceeded by regular expression '%s', at %s",
                       re, pos);
-    } else {
-      throw EvalError("invalid regular expression '%s', at %s", re, pos);
     }
+    throw EvalError("invalid regular expression '%s', at %s", re, pos);
   }
 }
 
@@ -2246,7 +2247,7 @@ 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) {
+  if (primOps == nullptr) {
     primOps = new PrimOps;
   }
   primOps->emplace_back(name, arity, fun);
@@ -2444,7 +2445,7 @@ void EvalState::createBaseEnv() {
   }
   addConstant("__nixPath", v);
 
-  if (RegisterPrimOp::primOps) {
+  if (RegisterPrimOp::primOps != nullptr) {
     for (auto& primOp : *RegisterPrimOp::primOps) {
       addPrimOp(std::get<0>(primOp), std::get<1>(primOp), std::get<2>(primOp));
     }
diff --git a/third_party/nix/src/libexpr/value-to-xml.cc b/third_party/nix/src/libexpr/value-to-xml.cc
index 44dede4875..7fab6e2ffe 100644
--- a/third_party/nix/src/libexpr/value-to-xml.cc
+++ b/third_party/nix/src/libexpr/value-to-xml.cc
@@ -111,7 +111,7 @@ static void printValueAsXML(EvalState& state, bool strict, bool location,
 
         XMLOpenElement _(doc, "derivation", xmlAttrs);
 
-        if (drvPath != "" && drvsSeen.find(drvPath) == drvsSeen.end()) {
+        if (!drvPath.empty() && drvsSeen.find(drvPath) == drvsSeen.end()) {
           drvsSeen.insert(drvPath);
           showAttrs(state, strict, location, *v.attrs, doc, context, drvsSeen);
         } else {