about summary refs log tree commit diff
path: root/src/nix-env
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-env')
-rw-r--r--src/nix-env/help.txt2
-rw-r--r--src/nix-env/main.cc22
2 files changed, 24 insertions, 0 deletions
diff --git a/src/nix-env/help.txt b/src/nix-env/help.txt
index d940bd209d60..3f15e6a8e2de 100644
--- a/src/nix-env/help.txt
+++ b/src/nix-env/help.txt
@@ -12,6 +12,8 @@ Operations:
 The previous operations take a list of derivation names.  The special
 name `*' may be used to indicate all derivations.
 
+  --profile / -p [FILE]: switch to specified user environment 
+
   --version: output version information
   --help: display help
 
diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc
index 7bced5be07a2..64ae6d4120b3 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