From d57c59e7cb4beba06825c042df35cc1f707bb41a Mon Sep 17 00:00:00 2001
From: Robert Helgesson <robert@rycee.net>
Date: Thu, 29 Apr 2021 17:53:56 +0200
Subject: [PATCH] home-environment: extra message on nix-env error

When profile installation fails during activation we'll print an extra
message that explain that, if the error is due to conflicting
packages, then it may be that the user has a manually installed copy
of the package.

Fixes #1244
---
 modules/home-environment.nix | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/modules/home-environment.nix b/modules/home-environment.nix
index b9b3a8cc8..c08d0ea7e 100644
--- a/modules/home-environment.nix
+++ b/modules/home-environment.nix
@@ -493,7 +493,24 @@ in
         ''
       else
         ''
-          $DRY_RUN_CMD nix-env -i ${cfg.path}
+          if ! $DRY_RUN_CMD nix-env -i ${cfg.path} ; then
+            cat <<EOF
+
+          Oops, nix-env failed to install your new Home Manager profile!
+
+          Perhaps there is a conflict with a package that was installed using
+          'nix-env -i'? Try running
+
+              nix-env -q
+
+          and if there is a conflicting package you can remove it with
+
+              nix-env -e {package name}
+
+          Then try activating your Home Manager configuration again.
+          EOF
+            exit 1
+          fi
         ''
     );