home-manager: handle missing per-user profiles directory

Specifically, if the global per-user profiles path do not exist and we
cannot create it during the activation, then place our profile in the
Home Manager data directory. We prefer to use the global location,
though, since it makes it visible to `nix-collect-garbage`.

This is intended to improve compatibility with Nix version 2.14 and
later, which no longer creates the per-user directories.

Also, use the Home Manager data directory to manage the gcroot for the
current generation. It does not have to sit in the global per-user
gcroots directory since it should never be eligible for GC.
This commit is contained in:
Robert Helgesson
2023-03-04 10:39:02 +01:00
parent 0f3dfc16d0
commit f69816489d
6 changed files with 149 additions and 98 deletions

View File

@@ -584,7 +584,7 @@ in
if config.submoduleSupport.externalPackageInstall
then
''
if [[ -e "$nixProfilePath"/manifest.json ]] ; then
if [[ -e $HOME/.nix-profile/manifest.json ]] ; then
nix profile list \
| { grep 'home-manager-path$' || test $? = 1; } \
| cut -d ' ' -f 4 \
@@ -608,7 +608,7 @@ in
$DRY_RUN_CMD $oldNix profile install $1
}
if [[ -e "$nixProfilePath"/manifest.json ]] ; then
if [[ -e $HOME/.nix-profile/manifest.json ]] ; then
INSTALL_CMD="nix profile install"
INSTALL_CMD_ACTUAL="nixReplaceProfile"
LIST_CMD="nix profile list"