make profile querying logic more consistent (?)

Change-Id: I00a4a8ba7f3a33aa191383f745f5a1395602e938
This commit is contained in:
Qyriad 2024-05-11 16:52:38 -06:00
parent 06eaea6ea3
commit a93667433f
3 changed files with 29 additions and 12 deletions

View file

@ -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 {

View file

@ -503,7 +503,7 @@ static bool keep(DrvInfo & drv)
static void installDerivations(Globals & globals, static void installDerivations(Globals & globals,
const Strings & args, const Path & profile) const Strings & args, const Path & profile)
{ {
debug("installing derivations"); debug("installing derivations into profile %s", profile);
/* Get the set of user environment elements to be installed. */ /* Get the set of user environment elements to be installed. */
DrvInfos newElems, newElemsTmp; DrvInfos newElems, newElemsTmp;
@ -554,8 +554,17 @@ static void installDerivations(Globals & globals,
if (globals.dryRun) return; if (globals.dryRun) return;
if (createUserEnv(*globals.state, allElems, bool success = createUserEnv(
profile, settings.envKeepDerivations, lockToken)) break; *globals.state,
allElems,
profile,
settings.envKeepDerivations,
lockToken
);
if (success) {
break;
}
} }
} }
@ -1297,7 +1306,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);
} }
@ -1463,8 +1472,10 @@ static int main_nix_env(int argc, char * * argv)
op = opQuery; op = opQuery;
opName = "-query"; opName = "-query";
} }
else if (*arg == "--profile" || *arg == "-p") else if (*arg == "--profile" || *arg == "-p") {
// XXX: check
globals.profile = absPath(getArg(*arg, arg, end)); globals.profile = absPath(getArg(*arg, arg, end));
}
else if (*arg == "--file" || *arg == "-f") else if (*arg == "--file" || *arg == "-f")
file = getArg(*arg, arg, end); file = getArg(*arg, arg, end);
else if (*arg == "--switch-profile" || *arg == "-S") { else if (*arg == "--switch-profile" || *arg == "-S") {
@ -1528,11 +1539,15 @@ static int main_nix_env(int argc, char * * argv)
globals.instSource.autoArgs = myArgs.getAutoArgs(*globals.state); globals.instSource.autoArgs = myArgs.getAutoArgs(*globals.state);
if (globals.profile == "") if (globals.profile == "") {
// XXX: refactor?
globals.profile = getEnv("NIX_PROFILE").value_or(""); globals.profile = getEnv("NIX_PROFILE").value_or("");
}
if (globals.profile == "") if (globals.profile == "") {
globals.profile = getDefaultProfile(); // XXX: check
globals.profile = ensureDefaultProfile();
}
op(globals, std::move(opFlags), std::move(opArgs)); op(globals, std::move(opFlags), std::move(opArgs));

View file

@ -20,6 +20,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
const Path & profile, bool keepDerivations, const Path & profile, bool keepDerivations,
const std::string & lockToken) const std::string & lockToken)
{ {
debug("asked to create a user env %s for %u drvs", profile, elems.size());
/* Build the components in the user environment, if they don't /* Build the components in the user environment, if they don't
exist already. */ exist already. */
std::vector<StorePathWithOutputs> drvsToBuild; std::vector<StorePathWithOutputs> drvsToBuild;
@ -131,10 +132,11 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
state.repair ? bmRepair : bmNormal); state.repair ? bmRepair : bmNormal);
/* Switch the current user environment to the output path. */ /* Switch the current user environment to the output path. */
auto store2 = state.store.dynamic_pointer_cast<LocalFSStore>(); auto localStore = state.store.dynamic_pointer_cast<LocalFSStore>();
if (store2) { if (localStore) {
PathLocks lock; PathLocks lock;
debug("locking profile %s", profile);
lockProfile(lock, profile); lockProfile(lock, profile);
Path lockTokenCur = optimisticLockProfile(profile); Path lockTokenCur = optimisticLockProfile(profile);
@ -144,7 +146,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
} }
debug("switching to new user environment"); debug("switching to new user environment");
Path generation = createGeneration(*store2, profile, topLevelOut); Path generation = createGeneration(*localStore, profile, topLevelOut);
switchLink(profile, generation); switchLink(profile, generation);
} }