From 42fd3a80424a260ca49d562b2767e05479a71dc9 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Sat, 11 May 2024 16:52:38 -0600 Subject: [PATCH] make profile querying logic more consistent (?) Change-Id: I00a4a8ba7f3a33aa191383f745f5a1395602e938 --- src/nix-channel/nix-channel.cc | 2 +- src/nix-env/nix-env.cc | 29 ++++++++++++++++++++++------- src/nix-env/user-env.cc | 8 +++++--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/nix-channel/nix-channel.cc b/src/nix-channel/nix-channel.cc index 26003f021..c7d951d0b 100644 --- a/src/nix-channel/nix-channel.cc +++ b/src/nix-channel/nix-channel.cc @@ -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 { diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index ad255a1e1..25fbccc8a 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -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; + } } } @@ -1463,8 +1472,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 +1539,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)); diff --git a/src/nix-env/user-env.cc b/src/nix-env/user-env.cc index f0131a458..70a1fe903 100644 --- a/src/nix-env/user-env.cc +++ b/src/nix-env/user-env.cc @@ -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 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(); + auto localStore = state.store.dynamic_pointer_cast(); - 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); }