about summary refs log tree commit diff
path: root/src/nix-env/main.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-01-05T11·18+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-01-05T11·18+0000
commitf83c5e3e5f3e6b33c095d6559a4b3cd5922e88ce (patch)
treea54f68b0882367374c88d58a6812461c7b40be0c /src/nix-env/main.cc
parent0e68af0ce380b09c14ff36084499c0d8a6590b25 (diff)
* Implemented Eelco V.'s `-p' command to switch profiles. It switches
  the symlink ~/.nix-userenv to the given argument (which defaults to
  .../links/current).  /etc/profile.d/nix-profile creates this symlink
  if it doesn't exist yet.  Example use:

  $ nix-env -l my_profile -i foo.nix subversion quake
  $ nix-env -p my_profile

  I don't like the term "profile".  Let's deprecate it :-)

Diffstat (limited to 'src/nix-env/main.cc')
-rw-r--r--src/nix-env/main.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc
index 7bced5be07..64ae6d4120 100644
--- a/src/nix-env/main.cc
+++ b/src/nix-env/main.cc
@@ -605,6 +605,26 @@ static void opQuery(Globals & globals,
 }
 
 
+static void opSwitchProfile(Globals & globals,
+    Strings opFlags, Strings opArgs)
+{
+    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"));
+
+    string linkPath = 
+        opArgs.size() == 0 ? globals.linkPath : opArgs.front();
+
+    string homeDir(getenv("HOME"));
+    if (homeDir == "") throw Error("HOME environment variable not set");
+
+    string linkPathFinal = homeDir + "/.nix-userenv";
+    
+    switchLink(linkPathFinal, linkPath);
+}
+
+
 void run(Strings args)
 {
     /* Use a higher default verbosity (lvlInfo). */
@@ -635,6 +655,8 @@ void run(Strings args)
                 format("`%1%' requires an argument") % arg);
             globals.linkPath = absPath(*i);
         }
+        else if (arg == "--profile" || arg == "-p") 
+            op = opSwitchProfile;
         else if (arg[0] == '-')
             opFlags.push_back(arg);
         else