make profile querying logic more consistent (?)

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

View file

@ -169,7 +169,7 @@ static int main_nix_channel(int argc, char ** argv)
nixDefExpr = getNixDefExpr();
// Figure out the name of the channels profile.
profile = profilesDir() + "/channels";
profile = defaultChannelsDir();
createDirs(dirOf(profile));
enum {

View file

@ -503,7 +503,7 @@ static bool keep(DrvInfo & drv)
static void installDerivations(Globals & globals,
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. */
DrvInfos newElems, newElemsTmp;
@ -554,8 +554,17 @@ static void installDerivations(Globals & globals,
if (globals.dryRun) return;
if (createUserEnv(*globals.state, allElems,
profile, settings.envKeepDerivations, lockToken)) break;
bool success = createUserEnv(
*globals.state,
allElems,
profile,
settings.envKeepDerivations,
lockToken
);
if (success) {
break;
}
}
}
@ -1296,6 +1305,7 @@ static void opSwitchProfile(Globals & globals, Strings opFlags, Strings opArgs)
if (opArgs.size() != 1)
throw UsageError("exactly one argument expected");
// XXX: refactor
Path profile = absPath(opArgs.front());
Path profileLink = settings.useXDGBaseDirectories ? createNixStateDir() + "/profile" : getHome() + "/.nix-profile";
@ -1463,8 +1473,10 @@ static int main_nix_env(int argc, char * * argv)
op = opQuery;
opName = "-query";
}
else if (*arg == "--profile" || *arg == "-p")
else if (*arg == "--profile" || *arg == "-p") {
// XXX: check
globals.profile = absPath(getArg(*arg, arg, end));
}
else if (*arg == "--file" || *arg == "-f")
file = getArg(*arg, arg, end);
else if (*arg == "--switch-profile" || *arg == "-S") {
@ -1528,11 +1540,15 @@ static int main_nix_env(int argc, char * * argv)
globals.instSource.autoArgs = myArgs.getAutoArgs(*globals.state);
if (globals.profile == "")
if (globals.profile == "") {
// XXX: refactor?
globals.profile = getEnv("NIX_PROFILE").value_or("");
}
if (globals.profile == "")
globals.profile = getDefaultProfile();
if (globals.profile == "") {
// XXX: check
globals.profile = ensureDefaultProfile();
}
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 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
exist already. */
std::vector<StorePathWithOutputs> drvsToBuild;
@ -131,10 +132,11 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
state.repair ? bmRepair : bmNormal);
/* 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;
debug("locking profile %s", profile);
lockProfile(lock, profile);
Path lockTokenCur = optimisticLockProfile(profile);
@ -144,7 +146,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
}
debug("switching to new user environment");
Path generation = createGeneration(*store2, profile, topLevelOut);
Path generation = createGeneration(*localStore, profile, topLevelOut);
switchLink(profile, generation);
}