aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-10-10 12:54:37 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-10-10 12:54:37 +0200
commite99bb9121787ae30a1872f63b326ce5c130ec7ef (patch)
treeecdd2b7ba575b0848d2770f8e74b40646f512c71 /src
parentd343c03edb8d4d2be7aca4f1a377544b3889b8b3 (diff)
parentc3aaf3b8da1a925c569389f13a861816a781a3c8 (diff)
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/eval.cc24
-rw-r--r--src/libexpr/get-drvs.cc3
-rw-r--r--src/libexpr/parser.y5
-rw-r--r--src/libexpr/primops.cc6
-rw-r--r--src/libexpr/value-to-xml.cc5
-rw-r--r--src/libstore/build.cc11
-rw-r--r--src/libstore/builtins/buildenv.cc3
-rw-r--r--src/libstore/local-store.cc32
-rw-r--r--src/libstore/local-store.hh2
-rw-r--r--src/libstore/local.mk5
-rw-r--r--src/libstore/misc.cc9
-rw-r--r--src/libstore/references.cc3
-rw-r--r--src/libstore/store-api.cc3
-rw-r--r--src/libstore/store-api.hh3
-rw-r--r--src/libutil/json.cc5
-rw-r--r--src/libutil/json.hh5
-rw-r--r--src/libutil/util.cc10
-rw-r--r--src/libutil/util.hh6
-rwxr-xr-xsrc/nix-build/nix-build.cc2
-rwxr-xr-xsrc/nix-channel/nix-channel.cc8
-rw-r--r--src/nix-daemon/nix-daemon.cc9
-rw-r--r--src/nix-env/nix-env.cc43
-rw-r--r--src/nix-store/dotgraph.cc7
-rw-r--r--src/nix-store/nix-store.cc3
-rw-r--r--src/nix/progress-bar.cc2
-rw-r--r--src/nix/search.cc5
-rw-r--r--src/nix/verify.cc3
-rw-r--r--src/resolve-system-dependencies/resolve-system-dependencies.cc4
28 files changed, 123 insertions, 103 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index ec751ad31..31f8f5862 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -47,11 +47,10 @@ static void printValue(std::ostream & str, std::set<const Value *> & active, con
{
checkInterrupt();
- if (active.find(&v) != active.end()) {
+ if (!active.insert(&v).second) {
str << "<CYCLE>";
return;
}
- active.insert(&v);
switch (v.type) {
case tInt:
@@ -1486,8 +1485,7 @@ void EvalState::forceValueDeep(Value & v)
std::function<void(Value & v)> recurse;
recurse = [&](Value & v) {
- if (seen.find(&v) != seen.end()) return;
- seen.insert(&v);
+ if (!seen.insert(&v).second) return;
forceValue(v);
@@ -1905,8 +1903,7 @@ 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;
- seen.insert(s);
+ if (!seen.insert(s).second) return 0;
return strlen(s) + 1;
};
@@ -1914,8 +1911,7 @@ 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;
- seen.insert(&v);
+ if (!seen.insert(&v).second) return 0;
size_t sz = sizeof(Value);
@@ -1930,8 +1926,7 @@ size_t valueSize(Value & v)
sz += doString(v.path);
break;
case tAttrs:
- if (seen.find(v.attrs) == seen.end()) {
- seen.insert(v.attrs);
+ if (seen.insert(v.attrs).second) {
sz += sizeof(Bindings) + sizeof(Attr) * v.attrs->capacity();
for (auto & i : *v.attrs)
sz += doValue(*i.value);
@@ -1940,8 +1935,7 @@ size_t valueSize(Value & v)
case tList1:
case tList2:
case tListN:
- if (seen.find(v.listElems()) == seen.end()) {
- seen.insert(v.listElems());
+ if (seen.insert(v.listElems()).second) {
sz += v.listSize() * sizeof(Value *);
for (size_t n = 0; n < v.listSize(); ++n)
sz += doValue(*v.listElems()[n]);
@@ -1962,8 +1956,7 @@ size_t valueSize(Value & v)
sz += doValue(*v.primOpApp.right);
break;
case tExternal:
- if (seen.find(v.external) != seen.end()) break;
- seen.insert(v.external);
+ if (!seen.insert(v.external).second) break;
sz += v.external->valueSize(seen);
break;
default:
@@ -1974,8 +1967,7 @@ size_t valueSize(Value & v)
};
doEnv = [&](Env & env) -> size_t {
- if (seen.find(&env) != seen.end()) return 0;
- seen.insert(&env);
+ if (!seen.insert(&env).second) return 0;
size_t sz = sizeof(Env) + sizeof(Value *) * env.size;
diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc
index 21a4d7917..4e22a1d77 100644
--- a/src/libexpr/get-drvs.cc
+++ b/src/libexpr/get-drvs.cc
@@ -277,8 +277,7 @@ static bool getDerivation(EvalState & state, Value & v,
/* Remove spurious duplicates (e.g., a set like `rec { x =
derivation {...}; y = x;}'. */
- if (done.find(v.attrs) != done.end()) return false;
- done.insert(v.attrs);
+ if (!done.insert(v.attrs).second) return false;
DrvInfo drv(state, attrPath, v.attrs);
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 967c88d9b..93834bec6 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -1,5 +1,5 @@
%glr-parser
-%pure-parser
+%define api.pure
%locations
%define parse.error verbose
%defines
@@ -138,11 +138,10 @@ static void addAttr(ExprAttrs * attrs, AttrPath & attrPath,
static void addFormal(const Pos & pos, Formals * formals, const Formal & formal)
{
- if (formals->argNames.find(formal.name) != formals->argNames.end())
+ if (!formals->argNames.insert(formal.name).second)
throw ParseError(format("duplicate formal function argument '%1%' at %2%")
% formal.name % pos);
formals->formals.push_front(formal);
- formals->argNames.insert(formal.name);
}
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 32ce00bbc..7c3e5a4da 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -396,8 +396,7 @@ static void prim_genericClosure(EvalState & state, const Pos & pos, Value * * ar
throw EvalError(format("attribute 'key' required, at %1%") % pos);
state.forceValue(*key->value);
- if (doneKeys.find(key->value) != doneKeys.end()) continue;
- doneKeys.insert(key->value);
+ if (!doneKeys.insert(key->value).second) continue;
res.push_back(e);
/* Call the `operator' function with `e' as argument. */
@@ -1273,13 +1272,12 @@ static void prim_listToAttrs(EvalState & state, const Pos & pos, Value * * args,
string name = state.forceStringNoCtx(*j->value, pos);
Symbol sym = state.symbols.create(name);
- if (seen.find(sym) == seen.end()) {
+ if (seen.insert(sym).second) {
Bindings::iterator j2 = v2.attrs->find(state.symbols.create(state.sValue));
if (j2 == v2.attrs->end())
throw TypeError(format("'value' attribute missing in a call to 'listToAttrs', at %1%") % pos);
v.attrs->push_back(Attr(sym, j2->value, j2->pos));
- seen.insert(sym);
}
}
diff --git a/src/libexpr/value-to-xml.cc b/src/libexpr/value-to-xml.cc
index 00b1918a8..1f0b1541d 100644
--- a/src/libexpr/value-to-xml.cc
+++ b/src/libexpr/value-to-xml.cc
@@ -105,10 +105,9 @@ static void printValueAsXML(EvalState & state, bool strict, bool location,
XMLOpenElement _(doc, "derivation", xmlAttrs);
- if (drvPath != "" && drvsSeen.find(drvPath) == drvsSeen.end()) {
- drvsSeen.insert(drvPath);
+ if (drvPath != "" && drvsSeen.insert(drvPath).second)
showAttrs(state, strict, location, *v.attrs, doc, context, drvsSeen);
- } else
+ else
doc.writeEmptyElement("repeated");
}
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 53e357435..cdf848c98 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -568,10 +568,9 @@ UserLock::UserLock()
{
auto lockedPaths(lockedPaths_.lock());
- if (lockedPaths->count(fnUserLock))
+ if (!lockedPaths->insert(fnUserLock).second)
/* We already have a lock on this one. */
continue;
- lockedPaths->insert(fnUserLock);
}
try {
@@ -620,8 +619,8 @@ UserLock::UserLock()
UserLock::~UserLock()
{
auto lockedPaths(lockedPaths_.lock());
- assert(lockedPaths->count(fnUserLock));
- lockedPaths->erase(fnUserLock);
+ auto erased = lockedPaths->erase(fnUserLock);
+ assert(erased);
}
@@ -1125,10 +1124,8 @@ void DerivationGoal::addWantedOutputs(const StringSet & outputs)
needRestart = true;
} else
for (auto & i : outputs)
- if (wantedOutputs.find(i) == wantedOutputs.end()) {
- wantedOutputs.insert(i);
+ if (wantedOutputs.insert(i).second)
needRestart = true;
- }
}
diff --git a/src/libstore/builtins/buildenv.cc b/src/libstore/builtins/buildenv.cc
index 74e706664..096593886 100644
--- a/src/libstore/builtins/buildenv.cc
+++ b/src/libstore/builtins/buildenv.cc
@@ -123,8 +123,7 @@ static Path out;
static void addPkg(const Path & pkgDir, int priority)
{
- if (done.count(pkgDir)) return;
- done.insert(pkgDir);
+ if (!done.insert(pkgDir).second) return;
createLinks(pkgDir, out, priority);
try {
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 307c00dbb..6bc3079a5 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -70,15 +70,17 @@ LocalStore::LocalStore(const Params & params)
createSymlink(profilesDir, gcRootsDir + "/profiles");
}
+ for (auto & perUserDir : {profilesDir + "/per-user", gcRootsDir + "/per-user"}) {
+ createDirs(perUserDir);
+ if (chmod(perUserDir.c_str(), 0755) == -1)
+ throw SysError("could not set permissions on '%s' to 755", perUserDir);
+ }
+
+ createUser(getUserName(), getuid());
+
/* Optionally, create directories and set permissions for a
multi-user install. */
if (getuid() == 0 && settings.buildUsersGroup != "") {
-
- Path perUserDir = profilesDir + "/per-user";
- createDirs(perUserDir);
- if (chmod(perUserDir.c_str(), 01777) == -1)
- throw SysError(format("could not set permissions on '%1%' to 1777") % perUserDir);
-
mode_t perm = 01775;
struct group * gr = getgrnam(settings.buildUsersGroup.get().c_str());
@@ -1285,8 +1287,7 @@ void LocalStore::verifyPath(const Path & path, const PathSet & store,
{
checkInterrupt();
- if (done.find(path) != done.end()) return;
- done.insert(path);
+ if (!done.insert(path).second) return;
if (!isStorePath(path)) {
printError(format("path '%1%' is not in the Nix store") % path);
@@ -1426,4 +1427,19 @@ void LocalStore::signPathInfo(ValidPathInfo & info)
}
+void LocalStore::createUser(const std::string & userName, uid_t userId)
+{
+ for (auto & dir : {
+ fmt("%s/profiles/per-user/%s", stateDir, userName),
+ fmt("%s/gcroots/per-user/%s", stateDir, userName)
+ }) {
+ createDirs(dir);
+ if (chmod(dir.c_str(), 0755) == -1)
+ throw SysError("changing permissions of directory '%s'", dir);
+ if (chown(dir.c_str(), userId, getgid()) == -1)
+ throw SysError("changing owner of directory '%s'", dir);
+ }
+}
+
+
}
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index 3ae34c403..379a06af8 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -293,6 +293,8 @@ private:
Path getRealStoreDir() override { return realStoreDir; }
+ void createUser(const std::string & userName, uid_t userId) override;
+
friend class DerivationGoal;
friend class SubstitutionGoal;
};
diff --git a/src/libstore/local.mk b/src/libstore/local.mk
index 89fc918c3..d690fea28 100644
--- a/src/libstore/local.mk
+++ b/src/libstore/local.mk
@@ -39,9 +39,12 @@ libstore_CXXFLAGS = \
-DNIX_LIBEXEC_DIR=\"$(libexecdir)\" \
-DNIX_BIN_DIR=\"$(bindir)\" \
-DNIX_MAN_DIR=\"$(mandir)\" \
- -DSANDBOX_SHELL="\"$(sandbox_shell)\"" \
-DLSOF=\"$(lsof)\"
+ifneq ($(sandbox_shell),)
+libstore_CXXFLAGS += -DSANDBOX_SHELL="\"$(sandbox_shell)\""
+endif
+
$(d)/local-store.cc: $(d)/schema.sql.gen.hh
$(d)/build.cc:
diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc
index dddf13430..05b93d4c9 100644
--- a/src/libstore/misc.cc
+++ b/src/libstore/misc.cc
@@ -29,8 +29,7 @@ void Store::computeFSClosure(const PathSet & startPaths,
{
auto state(state_.lock());
if (state->exc) return;
- if (state->paths.count(path)) return;
- state->paths.insert(path);
+ if (!state->paths.insert(path).second) return;
state->pending++;
}
@@ -175,8 +174,7 @@ void Store::queryMissing(const PathSet & targets,
{
auto state(state_.lock());
- if (state->done.count(path)) return;
- state->done.insert(path);
+ if (!state->done.insert(path).second) return;
}
DrvPathWithOutputs i2 = parseDrvPathWithOutputs(path);
@@ -252,8 +250,7 @@ Paths Store::topoSortPaths(const PathSet & paths)
if (parents.find(path) != parents.end())
throw BuildError(format("cycle detected in the references of '%1%' from '%2%'") % path % *parent);
- if (visited.find(path) != visited.end()) return;
- visited.insert(path);
+ if (!visited.insert(path).second) return;
parents.insert(path);
PathSet references;
diff --git a/src/libstore/references.cc b/src/libstore/references.cc
index 5b7eb1f84..0dcc264c3 100644
--- a/src/libstore/references.cc
+++ b/src/libstore/references.cc
@@ -36,11 +36,10 @@ static void search(const unsigned char * s, size_t len,
}
if (!match) continue;
string ref((const char *) s + i, refLength);
- if (hashes.find(ref) != hashes.end()) {
+ if (hashes.erase(ref)) {
debug(format("found reference to '%1%' at offset '%2%'")
% ref % i);
seen.insert(ref);
- hashes.erase(ref);
}
++i;
}
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index e8c1c1fdd..d0ef4e95b 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -949,8 +949,7 @@ std::list<ref<Store>> getDefaultSubstituters()
StringSet done;
auto addStore = [&](const std::string & uri) {
- if (done.count(uri)) return;
- done.insert(uri);
+ if (!done.insert(uri).second) return;
try {
stores.push_back(openStore(uri));
} catch (Error & e) {
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 5733bd9de..a9b073be4 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -629,6 +629,9 @@ public:
return storePath;
}
+ virtual void createUser(const std::string & userName, uid_t userId)
+ { }
+
protected:
Stats stats;
diff --git a/src/libutil/json.cc b/src/libutil/json.cc
index 0a6fb65f0..74e37b4c4 100644
--- a/src/libutil/json.cc
+++ b/src/libutil/json.cc
@@ -171,4 +171,9 @@ JSONObject JSONPlaceholder::object()
return JSONObject(state);
}
+JSONPlaceholder::~JSONPlaceholder()
+{
+ assert(!first || std::uncaught_exception());
+}
+
}
diff --git a/src/libutil/json.hh b/src/libutil/json.hh
index 02a39917f..83213ca66 100644
--- a/src/libutil/json.hh
+++ b/src/libutil/json.hh
@@ -168,10 +168,7 @@ public:
{
}
- ~JSONPlaceholder()
- {
- assert(!first || std::uncaught_exception());
- }
+ ~JSONPlaceholder();
template<typename T>
void write(const T & v)
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 98a7ea397..9d6bec034 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -486,6 +486,16 @@ std::pair<AutoCloseFD, Path> createTempFile(const Path & prefix)
}
+std::string getUserName()
+{
+ auto pw = getpwuid(geteuid());
+ std::string name = pw ? pw->pw_name : getEnv("USER", "");
+ if (name.empty())
+ throw Error("cannot figure out user name");
+ return name;
+}
+
+
static Lazy<Path> getHome2([]() {
Path homeDir = getEnv("HOME");
if (homeDir.empty()) {
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 2bf9725af..9f8c7092d 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -122,6 +122,12 @@ void deletePath(const Path & path);
void deletePath(const Path & path, unsigned long long & bytesFreed);
+/* Create a temporary directory. */
+Path createTempDir(const Path & tmpRoot = "", const Path & prefix = "nix",
+ bool includePid = true, bool useGlobalCounter = true, mode_t mode = 0755);
+
+std::string getUserName();
+
/* Return $HOME or the user's home directory from /etc/passwd. */
Path getHome();
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc
index 53a564676..50909608a 100755
--- a/src/nix-build/nix-build.cc
+++ b/src/nix-build/nix-build.cc
@@ -412,7 +412,7 @@ static void _main(int argc, char * * argv)
auto rcfile = (Path) tmpDir + "/rc";
writeFile(rcfile, fmt(
(keepTmp ? "" : "rm -rf '%1%'; "s) +
- "[ -n \"$PS1\" ] && [ -e ~/.bashrc ] && source ~/.bashrc; "
+ (pure ? "" : "[ -n \"$PS1\" ] && [ -e ~/.bashrc ] && source ~/.bashrc;") +
"%2%"
"dontAddDisableDepTrack=1; "
"[ -e $stdenv/setup ] && source $stdenv/setup; "
diff --git a/src/nix-channel/nix-channel.cc b/src/nix-channel/nix-channel.cc
index 06eb3d23b..70aa5c966 100755
--- a/src/nix-channel/nix-channel.cc
+++ b/src/nix-channel/nix-channel.cc
@@ -159,13 +159,7 @@ static int _main(int argc, char ** argv)
nixDefExpr = home + "/.nix-defexpr";
// Figure out the name of the channels profile.
- ;
- auto pw = getpwuid(geteuid());
- std::string name = pw ? pw->pw_name : getEnv("USER", "");
- if (name.empty())
- throw Error("cannot figure out user name");
- profile = settings.nixStateDir + "/profiles/per-user/" + name + "/channels";
- createDirs(dirOf(profile));
+ profile = fmt("%s/profiles/per-user/%s/channels", settings.nixStateDir, getUserName());
enum {
cNone,
diff --git a/src/nix-daemon/nix-daemon.cc b/src/nix-daemon/nix-daemon.cc
index e88aaf636..cd18489b0 100644
--- a/src/nix-daemon/nix-daemon.cc
+++ b/src/nix-daemon/nix-daemon.cc
@@ -742,7 +742,8 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
}
-static void processConnection(bool trusted)
+static void processConnection(bool trusted,
+ const std::string & userName, uid_t userId)
{
MonitorFdHup monitor(from.fd);
@@ -793,6 +794,8 @@ static void processConnection(bool trusted)
params["path-info-cache-size"] = "0";
auto store = openStore(settings.storeUri, params);
+ store->createUser(userName, userId);
+
tunnelLogger->stopWork();
to.flush();
@@ -1053,7 +1056,7 @@ static void daemonLoop(char * * argv)
/* Handle the connection. */
from.fd = remote.get();
to.fd = remote.get();
- processConnection(trusted);
+ processConnection(trusted, user, peer.uid);
exit(0);
}, options);
@@ -1133,7 +1136,7 @@ static int _main(int argc, char * * argv)
}
}
} else {
- processConnection(true);
+ processConnection(true, "root", 0);
}
} else {
daemonLoop(argv);
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index 87b2e43f0..199dc92aa 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -124,11 +124,10 @@ static void getAllExprs(EvalState & state,
string attrName = i;
if (hasSuffix(attrName, ".nix"))
attrName = string(attrName, 0, attrName.size() - 4);
- if (attrs.find(attrName) != attrs.end()) {
+ if (!attrs.insert(attrName).second) {
printError(format("warning: name collision in input Nix expressions, skipping '%1%'") % path2);
continue;
}
- attrs.insert(attrName);
/* Load the expression on demand. */
Value & vFun = state.getBuiltin("import");
Value & vArg(*state.allocValue());
@@ -193,12 +192,6 @@ static void loadDerivations(EvalState & state, Path nixExprPath,
}
-static Path getDefNixExprPath()
-{
- return getHome() + "/.nix-defexpr";
-}
-
-
static long getPriority(EvalState & state, DrvInfo & drv)
{
return drv.queryMetaInt("priority", 0);
@@ -307,10 +300,8 @@ static DrvInfos filterBySelector(EvalState & state, const DrvInfos & allElems,
/* Insert only those elements in the final list that we
haven't inserted before. */
for (auto & j : matches)
- if (done.find(j.second) == done.end()) {
- done.insert(j.second);
+ if (done.insert(j.second).second)
elems.push_back(j.first);
- }
}
checkSelectorUse(selectors);
@@ -1330,9 +1321,22 @@ static int _main(int argc, char * * argv)
Globals globals;
globals.instSource.type = srcUnknown;
- globals.instSource.nixExprPath = getDefNixExprPath();
+ globals.instSource.nixExprPath = getHome() + "/.nix-defexpr";
globals.instSource.systemFilter = "*";
+ if (!pathExists(globals.instSource.nixExprPath)) {
+ try {
+ createDirs(globals.instSource.nixExprPath);
+ replaceSymlink(
+ fmt("%s/profiles/per-user/%s/channels", settings.nixStateDir, getUserName()),
+ globals.instSource.nixExprPath + "/channels");
+ if (getuid() != 0)
+ replaceSymlink(
+ fmt("%s/profiles/per-user/root/channels", settings.nixStateDir),
+ globals.instSource.nixExprPath + "/channels_root");
+ } catch (Error &) { }
+ }
+
globals.dryRun = false;
globals.preserveInstalled = false;
globals.removeAll = false;
@@ -1425,9 +1429,18 @@ static int _main(int argc, char * * argv)
if (globals.profile == "") {
Path profileLink = getHome() + "/.nix-profile";
- globals.profile = pathExists(profileLink)
- ? absPath(readLink(profileLink), dirOf(profileLink))
- : canonPath(settings.nixStateDir + "/profiles/default");
+ try {
+ if (!pathExists(profileLink)) {
+ replaceSymlink(
+ getuid() == 0
+ ? settings.nixStateDir + "/profiles/default"
+ : fmt("%s/profiles/per-user/%s/profile", settings.nixStateDir, getUserName()),
+ profileLink);
+ }
+ globals.profile = absPath(readLink(profileLink), dirOf(profileLink));
+ } catch (Error &) {
+ globals.profile = profileLink;
+ }
}
op(globals, opFlags, opArgs);
diff --git a/src/nix-store/dotgraph.cc b/src/nix-store/dotgraph.cc
index abdfa5e58..d448654fe 100644
--- a/src/nix-store/dotgraph.cc
+++ b/src/nix-store/dotgraph.cc
@@ -71,9 +71,7 @@ void printClosure(const Path & nePath, const StoreExpr & fs)
Path path = *(workList.begin());
workList.erase(path);
- if (doneSet.find(path) == doneSet.end()) {
- doneSet.insert(path);
-
+ if (doneSet.insert(path).second) {
ClosureElems::const_iterator elem = fs.closure.elems.find(path);
if (elem == fs.closure.elems.end())
throw Error(format("bad closure, missing path '%1%'") % path);
@@ -104,8 +102,7 @@ void printDotGraph(ref<Store> store, const PathSet & roots)
Path path = *(workList.begin());
workList.erase(path);
- if (doneSet.find(path) != doneSet.end()) continue;
- doneSet.insert(path);
+ if (!doneSet.insert(path).second) continue;
cout << makeNode(path, symbolicName(path), "#ff0000");
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index 0cbceb02f..19384499d 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -242,11 +242,10 @@ const string treeNull = " ";
static void printTree(const Path & path,
const string & firstPad, const string & tailPad, PathSet & done)
{
- if (done.find(path) != done.end()) {
+ if (!done.insert(path).second) {
cout << format("%1%%2% [...]\n") % firstPad % path;
return;
}
- done.insert(path);
cout << format("%1%%2%\n") % firstPad % path;
diff --git a/src/nix/progress-bar.cc b/src/nix/progress-bar.cc
index c0bcfb0c9..5c05d6b22 100644
--- a/src/nix/progress-bar.cc
+++ b/src/nix/progress-bar.cc
@@ -120,7 +120,7 @@ public:
void log(State & state, Verbosity lvl, const std::string & s)
{
if (state.active) {
- writeToStderr("\r\e[K" + s + ANSI_NORMAL "\n");
+ writeToStderr("\r\e[K" + filterANSIEscapes(s, !isTTY) + ANSI_NORMAL "\n");
draw(state);
} else {
auto s2 = s + ANSI_NORMAL "\n";
diff --git a/src/nix/search.cc b/src/nix/search.cc
index 70de717d1..caea25cdc 100644
--- a/src/nix/search.cc
+++ b/src/nix/search.cc
@@ -75,10 +75,6 @@ struct CmdSearch : SourceExprCommand, MixJSON
Example{
"To search for git and frontend or gui:",
"nix search git 'frontend|gui'"
- },
- Example{
- "To display the description of the found packages:",
- "nix search git --verbose"
}
};
}
@@ -262,6 +258,7 @@ struct CmdSearch : SourceExprCommand, MixJSON
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66145 */
if (!jsonCacheFile)
throw Error("error writing to %s", tmpFile);
+ throw;
}
if (writeCache && rename(tmpFile.c_str(), jsonCacheFileName.c_str()) == -1)
diff --git a/src/nix/verify.cc b/src/nix/verify.cc
index f55766eda..81abf434f 100644
--- a/src/nix/verify.cc
+++ b/src/nix/verify.cc
@@ -113,8 +113,7 @@ struct CmdVerify : StorePathsCommand
auto doSigs = [&](StringSet sigs) {
for (auto sig : sigs) {
- if (sigsSeen.count(sig)) continue;
- sigsSeen.insert(sig);
+ if (!sigsSeen.insert(sig).second) continue;
if (validSigs < ValidPathInfo::maxSigs && info->checkSignature(publicKeys, sig))
validSigs++;
}
diff --git a/src/resolve-system-dependencies/resolve-system-dependencies.cc b/src/resolve-system-dependencies/resolve-system-dependencies.cc
index e02cfc03e..45e8b6796 100644
--- a/src/resolve-system-dependencies/resolve-system-dependencies.cc
+++ b/src/resolve-system-dependencies/resolve-system-dependencies.cc
@@ -117,9 +117,7 @@ Path resolveSymlink(const Path & path)
std::set<string> resolveTree(const Path & path, PathSet & deps)
{
std::set<string> results;
- if (deps.count(path))
- return {};
- deps.insert(path);
+ if (!deps.insert(path).second) return {};
for (auto & lib : runResolver(path)) {
results.insert(lib);
for (auto & p : resolveTree(lib, deps)) {