about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-02-06T10·59+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-02-06T10·59+0000
commit49bafe1faf4eedf0f059740be4f99c700ee93fe7 (patch)
tree4a244ca54e78b4bf6bd66c08b156348b77f00165
parent66e94d3275e9a0a549c28b7d0ad5f3f897e2fbf0 (diff)
* Use the profile pointed to by ~/.nix-profile if no --profile
  argument is specified.

-rw-r--r--src/libutil/util.cc2
-rw-r--r--src/nix-env/main.cc17
2 files changed, 12 insertions, 7 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 5c8b7279c42d..3a6914cba149 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -101,7 +101,7 @@ bool pathExists(const Path & path)
 {
     int res;
     struct stat st;
-    res = stat(path.c_str(), &st);
+    res = lstat(path.c_str(), &st);
     if (!res) return true;
     if (errno != ENOENT)
         throw SysError(format("getting status of %1%") % path);
diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc
index 20b7da655d54..00b6c7f8d3a9 100644
--- a/src/nix-env/main.cc
+++ b/src/nix-env/main.cc
@@ -645,12 +645,11 @@ static void opSwitchProfile(Globals & globals,
 {
     if (opFlags.size() > 0)
         throw UsageError(format("unknown flags `%1%'") % opFlags.front());
-    if (opArgs.size() > 1)
-        throw UsageError(format("`--profile' takes at most one argument"));
+    if (opArgs.size() != 1)
+        throw UsageError(format("`--profile' takes exactly one argument"));
 
-    Path profile = 
-        absPath(opArgs.size() == 0 ? globals.profile : opArgs.front());
-    Path profileLink = getHomeDir() + "/.nix-userenv";
+    Path profile = opArgs.front();
+    Path profileLink = getHomeDir() + "/.nix-profile";
 
     switchLink(profileLink, profile);
 }
@@ -680,7 +679,6 @@ void run(Strings args)
     Operation op = 0;
     
     Globals globals;
-    globals.profile = canonPath(nixStateDir + "/profiles/default");
     globals.nixExprPath = getDefNixExprPath();
 
     for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
@@ -723,6 +721,13 @@ void run(Strings args)
 
     if (!op) throw UsageError("no operation specified");
 
+    if (globals.profile == "") {
+        Path profileLink = getHomeDir() + "/.nix-profile";
+        globals.profile = pathExists(profileLink)
+            ? absPath(readLink(profileLink), dirOf(profileLink))
+            : canonPath(nixStateDir + "/profiles/default");
+    }
+    
     openDB();
 
     op(globals, opFlags, opArgs);