okay, tests pass

Change-Id: I2610ed6b3405969d07775e7d72fee9ebfb50cc29
This commit is contained in:
Qyriad 2024-05-10 18:41:07 -06:00
parent 2955732baa
commit 7d1ce1420b
5 changed files with 61 additions and 31 deletions

View file

@ -307,7 +307,22 @@ std::string optimisticLockProfile(const Path & profile)
Path profilesDir()
{
return fmt("%s/profiles/per-user/%s", settings.nixStateDir, getUserName());
Path const dir = fmt("%s/profiles/per-user/%s", settings.nixStateDir, getUserName());
return dir;
try {
createNixStateDir();
} catch (SysError const & e) {
warn("ignoring error creating Nix XDG state dir: %s", e.what());
}
try {
createDirs(dir);
} catch (SysError const & e) {
warn("ignoring error creating home profiles link: %s", e.what());
}
return dir;
auto profileRoot =
(getuid() == 0)
@ -340,31 +355,25 @@ Path ensureDefaultProfile()
Path const profileLink = getDefaultProfileLink();
try {
Path const profile = profilesDir() + "/profile";
if (!pathExists(profileLink)) {
try {
replaceSymlink(profile, profileLink);
} catch (SysError const & e) {
std::cerr << fmt("error while replaceSymlink(%s, %s)\n", profile, profileLink);
std::cerr << fmt("(attempted because %s does not exist)\n", profileLink);
throw;
}
}
// Backwards compatibiliy measure: Make root's profile available as
// `.../default` as it's what NixOS and most of the init scripts expect
Path const globalProfileLink = settings.nixStateDir + "/profiles/default";
if (getuid() == 0 && !pathExists(globalProfileLink)) {
try {
replaceSymlink(profile, globalProfileLink);
} catch (SysError const & e) {
std::cerr << fmt("error while uid0 replaceSymlink(%s, %s)\n", profile, globalProfileLink);
}
}
auto const absProfile = absPath(readLink(profileLink), dirOf(profileLink));
return absProfile;
return absPath(readLink(profileLink), dirOf(profileLink));
} catch (Error const & e) {
std::cerr << "returning original profileLink " << profileLink << std::endl;
std::cerr << "err was " << e.what() << "\n";
return profileLink;
throw;
//return profileLink;
//std::cerr << "returning original profileLink " << profileLink << std::endl;
//std::cerr << "err was " << e.what() << "\n";
//return profileLink;
}
}
@ -383,8 +392,6 @@ Path getDefaultProfile()
}
return profileLink;
//Path const globalProfileLink = settings.nixStateDir + "/profiles/default";
}
Path defaultChannelsDir()

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;
}
}
}

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);
}

View file

@ -37,8 +37,10 @@ nix-env -qa '*' --description | grepQuiet silly
# Query the system.
nix-env -qa '*' --system | grepQuiet $system
readlink $HOME/.nix-profile || true
eza --tree -la $HOME/.local/state/nix || true
# Install "foo-1.0".
nix-env -i foo-1.0
nix-env --debug -i foo-1.0
# Query installed: should contain foo-1.0 now (which should be
# executable).

View file

@ -21,11 +21,12 @@ in {
users.users.alice.isNormalUser = true;
#virtualisation.additionalPaths = [ pkgs.hello.drvPath ];
#nix.settings.substituters = lib.mkForce [ ];
nix.settings.experimental-features = [ "nix-command" "flakes" ];
#nix.settings.experimental-features = [ "nix-command" "flakes" ];
nix.settings = {
substituters = lib.mkForce [ ];
#experimental-features = [ "nix-command" "flakes" ];
experimental-features = [ "nix-command" "flakes" ];
allowed-users = [ "alice" ];
use-xdg-base-directories = true;
};
nix.nixPath = [ "nixpkgs=${pkgs.path}" ];
#nix.package = pkgs.nixVersions.nix_2_18;
@ -38,8 +39,6 @@ in {
# fmt: off
start_all()
machine.wait_for_unit("getty@tty1.service")
machine.wait_for_unit("nix-daemon.socket")
machine.wait_for_unit("multi-user.target")
machine.succeed("nix -vv --version >&2")
@ -52,6 +51,8 @@ in {
nix-env --version -vv >&2
""")
print(machine.succeed("systemctl cat nix-daemon.service"))
# Initial state.
machine.succeed("""
su --login alice -c '
@ -86,6 +87,15 @@ in {
:' >&2
""")
machine.succeed("""
su --login alice -c '
set -euxo pipefail
PAGER=cat nix-env --option use-xdg-base-directories false --query '*'
${ezaTree} ~
${ezaTree} /nix/var/nix/profiles
:' >&2
""")
machine.succeed("""
su --login alice -c '
set -euxo pipefail