forked from lix-project/lix
make profile querying logic more consistent (?)
Change-Id: I00a4a8ba7f3a33aa191383f745f5a1395602e938
This commit is contained in:
parent
88d9b70f67
commit
0d1fee3d16
|
@ -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 {
|
||||
|
|
|
@ -81,7 +81,13 @@ static int main_nix_collect_garbage(int argc, char * * argv)
|
|||
|
||||
if (removeOld) {
|
||||
std::set<Path> dirsToClean = {
|
||||
profilesDir(), settings.nixStateDir + "/profiles", dirOf(getDefaultProfile())};
|
||||
// XXX: check
|
||||
profilesDir(),
|
||||
// XXX: refactor
|
||||
settings.nixStateDir + "/profiles",
|
||||
/// XXX: check
|
||||
dirOf(getDefaultProfile()),
|
||||
};
|
||||
for (auto & dir : dirsToClean)
|
||||
removeOldGenerations(dir);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue