about summary refs log tree commit diff
path: root/src/nix-env
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-05-05T14·40+0200
committerEelco Dolstra <edolstra@gmail.com>2017-05-05T15·08+0200
commit465cb6824401541d82489e11b5223dbfd50bb132 (patch)
tree98b112563cbf08c29e94c4ddc0755de95524186f /src/nix-env
parenteba840c8a13b465ace90172ff76a0db2899ab11b (diff)
Figure out the user's home directory if $HOME is not set
Diffstat (limited to 'src/nix-env')
-rw-r--r--src/nix-env/nix-env.cc14
1 files changed, 3 insertions, 11 deletions
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index 908c09bc8c8a..da39bf36ab65 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -192,17 +192,9 @@ static void loadDerivations(EvalState & state, Path nixExprPath,
 }
 
 
-static Path getHomeDir()
-{
-    Path homeDir(getEnv("HOME", ""));
-    if (homeDir == "") throw Error("HOME environment variable not set");
-    return homeDir;
-}
-
-
 static Path getDefNixExprPath()
 {
-    return getHomeDir() + "/.nix-defexpr";
+    return getHome() + "/.nix-defexpr";
 }
 
 
@@ -1188,7 +1180,7 @@ static void opSwitchProfile(Globals & globals, Strings opFlags, Strings opArgs)
         throw UsageError(format("exactly one argument expected"));
 
     Path profile = absPath(opArgs.front());
-    Path profileLink = getHomeDir() + "/.nix-profile";
+    Path profileLink = getHome() + "/.nix-profile";
 
     switchLink(profileLink, profile);
 }
@@ -1413,7 +1405,7 @@ int main(int argc, char * * argv)
             globals.profile = getEnv("NIX_PROFILE", "");
 
         if (globals.profile == "") {
-            Path profileLink = getHomeDir() + "/.nix-profile";
+            Path profileLink = getHome() + "/.nix-profile";
             globals.profile = pathExists(profileLink)
                 ? absPath(readLink(profileLink), dirOf(profileLink))
                 : canonPath(settings.nixStateDir + "/profiles/default");