forked from lix-project/lix
make profile querying logic more consistent
Change-Id: I00a4a8ba7f3a33aa191383f745f5a1395602e938
This commit is contained in:
parent
88d9b70f67
commit
7f35e7e704
|
@ -320,6 +320,17 @@ Path rootProfilesDir()
|
||||||
return settings.nixStateDir + "/profiles/per-user/root";
|
return settings.nixStateDir + "/profiles/per-user/root";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Path getDefaultProfileLink()
|
||||||
|
{
|
||||||
|
if (getuid() == 0) {
|
||||||
|
return settings.nixStateDir + "/profiles/default";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.useXDGBaseDirectories) {
|
||||||
|
return createNixStateDir() + "/profile";
|
||||||
|
}
|
||||||
|
return getHome() + "/.nix-profile";
|
||||||
|
}
|
||||||
|
|
||||||
Path getDefaultProfile()
|
Path getDefaultProfile()
|
||||||
{
|
{
|
||||||
|
|
|
@ -227,6 +227,12 @@ Path defaultChannelsDir();
|
||||||
*/
|
*/
|
||||||
Path rootChannelsDir();
|
Path rootChannelsDir();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the symlink that is used as the default profile, but do not resolve it.
|
||||||
|
* (see getDefaultProfile() for where that link is.)
|
||||||
|
*/
|
||||||
|
Path getDefaultProfileLink();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve the default profile (~/.nix-profile by default,
|
* Resolve the default profile (~/.nix-profile by default,
|
||||||
* $XDG_STATE_HOME/nix/profile if XDG Base Directory Support is enabled),
|
* $XDG_STATE_HOME/nix/profile if XDG Base Directory Support is enabled),
|
||||||
|
|
|
@ -169,7 +169,7 @@ static int main_nix_channel(int argc, char ** argv)
|
||||||
nixDefExpr = getNixDefExpr();
|
nixDefExpr = getNixDefExpr();
|
||||||
|
|
||||||
// Figure out the name of the channels profile.
|
// Figure out the name of the channels profile.
|
||||||
profile = profilesDir() + "/channels";
|
profile = defaultChannelsDir();
|
||||||
createDirs(dirOf(profile));
|
createDirs(dirOf(profile));
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
|
@ -1297,7 +1297,7 @@ static void opSwitchProfile(Globals & globals, Strings opFlags, Strings opArgs)
|
||||||
throw UsageError("exactly one argument expected");
|
throw UsageError("exactly one argument expected");
|
||||||
|
|
||||||
Path profile = absPath(opArgs.front());
|
Path profile = absPath(opArgs.front());
|
||||||
Path profileLink = settings.useXDGBaseDirectories ? createNixStateDir() + "/profile" : getHome() + "/.nix-profile";
|
Path profileLink = getDefaultProfileLink();
|
||||||
|
|
||||||
switchLink(profileLink, profile);
|
switchLink(profileLink, profile);
|
||||||
}
|
}
|
||||||
|
@ -1531,8 +1531,9 @@ static int main_nix_env(int argc, char * * argv)
|
||||||
if (globals.profile == "")
|
if (globals.profile == "")
|
||||||
globals.profile = getEnv("NIX_PROFILE").value_or("");
|
globals.profile = getEnv("NIX_PROFILE").value_or("");
|
||||||
|
|
||||||
if (globals.profile == "")
|
if (globals.profile == "") {
|
||||||
globals.profile = getDefaultProfile();
|
globals.profile = ensureDefaultProfile();
|
||||||
|
}
|
||||||
|
|
||||||
op(globals, std::move(opFlags), std::move(opArgs));
|
op(globals, std::move(opFlags), std::move(opArgs));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue