1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-25 03:39:36 +01:00

Move the default profiles to the user’s home

Rather than using `/nix/var/nix/{profiles,gcroots}/per-user/`, put the user
profiles and gcroots under `$XDG_DATA_DIR/nix/{profiles,gcroots}`.

This means that the daemon no longer needs to manage these paths itself
(they are fully handled client-side). In particular, it doesn’t have to
`chown` them anymore (removing one need for root).

This does change the layout of the gc-roots created by nix-env, and is
likely to break some stuff, so I’m not sure how to properly handle that.
This commit is contained in:
Théophane Hufschmitt 2022-04-13 10:26:50 +02:00
parent deb35c84b3
commit a5919f4754
11 changed files with 42 additions and 41 deletions

View file

@ -280,16 +280,30 @@ std::string optimisticLockProfile(const Path & profile)
}
Path profilesDir()
{
auto profileRoot = getDataDir() + "/nix/profiles";
createDirs(profileRoot);
return profileRoot;
}
Path getDefaultProfile()
{
Path profileLink = getHome() + "/.nix-profile";
try {
if (!pathExists(profileLink)) {
replaceSymlink(
getuid() == 0
? settings.nixStateDir + "/profiles/default"
: fmt("%s/profiles/per-user/%s/profile", settings.nixStateDir, getUserName()),
profileLink);
// 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)
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);
}
return absPath(readLink(profileLink), dirOf(profileLink));
} catch (Error &) {