1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 22:01:15 +02:00

Figure out the user's home directory if $HOME is not set

This commit is contained in:
Eelco Dolstra 2017-05-05 16:40:12 +02:00
parent eba840c8a1
commit 465cb68244
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
8 changed files with 84 additions and 36 deletions

View file

@ -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");