aboutsummaryrefslogtreecommitdiff
path: root/src/nix-env
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/nix-env
parentd343c03edb8d4d2be7aca4f1a377544b3889b8b3 (diff)
parentc3aaf3b8da1a925c569389f13a861816a781a3c8 (diff)
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/nix-env')
-rw-r--r--src/nix-env/nix-env.cc43
1 files changed, 28 insertions, 15 deletions
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);