Add getDefaultProfile() function
This commit is contained in:
@@ -256,4 +256,22 @@ string optimisticLockProfile(const Path & profile)
|
||||
}
|
||||
|
||||
|
||||
Path getDefaultProfile()
|
||||
{
|
||||
Path profileLink = getHome() + "/.nix-profile";
|
||||
try {
|
||||
if (!pathExists(profileLink)) {
|
||||
replaceSymlink(
|
||||
getuid() == 0
|
||||
? settings.nixStateDir + "/profiles/default"
|
||||
: fmt("%s/profiles/per-user/%s/profile", settings.nixStateDir, getUserName()),
|
||||
profileLink);
|
||||
}
|
||||
return absPath(readLink(profileLink), dirOf(profileLink));
|
||||
} catch (Error &) {
|
||||
return profileLink;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -64,4 +64,8 @@ void lockProfile(PathLocks & lock, const Path & profile);
|
||||
rebuilt. */
|
||||
string optimisticLockProfile(const Path & profile);
|
||||
|
||||
/* Resolve ~/.nix-profile. If ~/.nix-profile doesn't exist yet, create
|
||||
it. */
|
||||
Path getDefaultProfile();
|
||||
|
||||
}
|
||||
|
||||
+2
-15
@@ -1427,21 +1427,8 @@ static int _main(int argc, char * * argv)
|
||||
if (globals.profile == "")
|
||||
globals.profile = getEnv("NIX_PROFILE", "");
|
||||
|
||||
if (globals.profile == "") {
|
||||
Path profileLink = getHome() + "/.nix-profile";
|
||||
try {
|
||||
if (!pathExists(profileLink)) {
|
||||
replaceSymlink(
|
||||
getuid() == 0
|
||||
? settings.nixStateDir + "/profiles/default"
|
||||
: fmt("%s/profiles/per-user/%s/profile", settings.nixStateDir, getUserName()),
|
||||
profileLink);
|
||||
}
|
||||
globals.profile = absPath(readLink(profileLink), dirOf(profileLink));
|
||||
} catch (Error &) {
|
||||
globals.profile = profileLink;
|
||||
}
|
||||
}
|
||||
if (globals.profile == "")
|
||||
globals.profile = getDefaultProfile();
|
||||
|
||||
op(globals, opFlags, opArgs);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user