forked from lix-project/lix
Add getDefaultProfile() function
This commit is contained in:
parent
a07da2fd7a
commit
a7aabd7cc7
|
@ -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. */
|
rebuilt. */
|
||||||
string optimisticLockProfile(const Path & profile);
|
string optimisticLockProfile(const Path & profile);
|
||||||
|
|
||||||
|
/* Resolve ~/.nix-profile. If ~/.nix-profile doesn't exist yet, create
|
||||||
|
it. */
|
||||||
|
Path getDefaultProfile();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1427,21 +1427,8 @@ static int _main(int argc, char * * argv)
|
||||||
if (globals.profile == "")
|
if (globals.profile == "")
|
||||||
globals.profile = getEnv("NIX_PROFILE", "");
|
globals.profile = getEnv("NIX_PROFILE", "");
|
||||||
|
|
||||||
if (globals.profile == "") {
|
if (globals.profile == "")
|
||||||
Path profileLink = getHome() + "/.nix-profile";
|
globals.profile = getDefaultProfile();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
op(globals, opFlags, opArgs);
|
op(globals, opFlags, opArgs);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue