From 071e28c869d3b0c5b3c1105da42f2a8e3ac4c1e2 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Thu, 8 Sep 2022 13:08:57 +0200 Subject: [PATCH] home-environment: fix activation on new style profiles When using the new style profiles we get conflicts when trying to replace the old `home-path` derivation. To avoid this conflict we delete the old `home-path` before the install. Unfortunately, `nix profile` does not yet have a equivalent for `nix-env --set` and we have to do this hackish workaround. See https://github.com/NixOS/nix/issues/6349 for the associated issue in Nix. Fixes #2848 (cherry picked from commit ccc9164b76e4167873ed819f0fb014635453ec68) --- modules/home-environment.nix | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/home-environment.nix b/modules/home-environment.nix index 9c0a7a1cf..c52d8d9c7 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -592,22 +592,37 @@ in '' else '' + function nixReplaceProfile() { + local oldNix="$(which nix)" + + nix profile list \ + | { grep 'home-manager-path$' || test $? = 1; } \ + | awk -F ' ' '{ print $4 }' \ + | cut -d ' ' -f 4 \ + | xargs -t $DRY_RUN_CMD nix profile remove $VERBOSE_ARG + + $DRY_RUN_CMD $oldNix profile install $1 + } + if [[ -e "$nixProfilePath"/manifest.json ]] ; then INSTALL_CMD="nix profile install" + INSTALL_CMD_ACTUAL="nixReplaceProfile" LIST_CMD="nix profile list" REMOVE_CMD_SYNTAX='nix profile remove {number | store path}' else INSTALL_CMD="nix-env -i" + INSTALL_CMD_ACTUAL="$DRY_RUN_CMD nix-env -i" LIST_CMD="nix-env -q" REMOVE_CMD_SYNTAX='nix-env -e {package name}' fi - if ! $DRY_RUN_CMD $INSTALL_CMD ${cfg.path} ; then + if ! $INSTALL_CMD_ACTUAL ${cfg.path} ; then echo _iError $'Oops, Nix failed to install your new Home Manager profile!\n\nPerhaps there is a conflict with a package that was installed using\n"%s"? Try running\n\n %s\n\nand if there is a conflicting package you can remove it with\n\n %s\n\nThen try activating your Home Manager configuration again.' "$INSTALL_CMD" "$LIST_CMD" "$REMOVE_CMD_SYNTAX" exit 1 fi - unset INSTALL_CMD LIST_CMD REMOVE_CMD_SYNTAX + unset -f nixReplaceProfile + unset INSTALL_CMD INSTALL_CMD_ACTUAL LIST_CMD REMOVE_CMD_SYNTAX '' );