1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-13 14:02:42 +01:00

Migrate the old profiles to the new location

Make sure that we don’t just create the new profiles directory, but that
we also migrate every existing profile to it.
This commit is contained in:
regnat 2021-10-05 17:40:03 +02:00 committed by Théophane Hufschmitt
parent a3979e67f4
commit be28cb9262

View file

@ -293,17 +293,24 @@ Path getDefaultProfile()
Path profileLink = getHome() + "/.nix-profile";
try {
// Migrate from the “old-style” profiles stored under `/nix/var`:
// If the link exists and points to the old location, rewrite it to the
// new one (otherwise keep-it as-it-is as it might have been
// intentionnally changed, in which case we shouldnt touch it)
// If the link exists and points to the old location, then:
// - Rewrite it to point to the new location
// - For every generation of the old default profile, create a symlink
// from the new directory to it (so that all the previous profiles
// and generations are still available).
auto legacyProfile = getuid() == 0
? settings.nixStateDir + "/profiles/default"
: fmt("%s/profiles/per-user/%s/profile", settings.nixStateDir, getUserName());
if (!pathExists(profileLink) ||
(isLink(profileLink) &&
readLink(profileLink) == legacyProfile)
) {
replaceSymlink(profilesDir() + "/profile", profileLink);
auto newProfile = profilesDir() + "/profile";
if (!pathExists(profileLink)
|| (isLink(profileLink)
&& readLink(profileLink) == legacyProfile)) {
replaceSymlink(newProfile, profileLink);
for (auto & oldGen : findGenerations(legacyProfile).first) {
replaceSymlink(
oldGen.path,
newProfile + "/" + std::string(baseNameOf(oldGen.path)));
}
}
return absPath(readLink(profileLink), dirOf(profileLink));
} catch (Error &) {