From 2e257f40e68ed1730c43fff1e8a010f47f4cb072 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Wed, 19 Jul 2017 00:12:34 +0200 Subject: [PATCH] home-manager: remove manually installed home-manager If the `home-manager` module is enabled then check if the `home-manager` package is installed using `nix-env -i` and if so then it is automatically uninstalled before the new package environment, which includes home-manager, is installed. --- modules/programs/home-manager.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/programs/home-manager.nix b/modules/programs/home-manager.nix index 09c662ac0..413f56687 100644 --- a/modules/programs/home-manager.nix +++ b/modules/programs/home-manager.nix @@ -1,6 +1,7 @@ { config, lib, pkgs, ... }: with lib; +with import ../lib/dag.nix; let @@ -35,5 +36,17 @@ in inherit (cfg) modulesPath; }) ]; + + # Uninstall manually installed home-manager, if such exists. + # Without this a file collision error will be printed. + home.activation.uninstallHomeManager = + dagEntryBetween [ "installPackages" ] [ "writeBoundary" ] '' + if nix-env -q | grep -q '^home-manager$' ; then + $DRY_RUN_CMD nix-env -e home-manager + + echo "You can now remove the 'home-manager' entry in" + echo "'~/.config/nixpkgs/config.nix', if you want." + fi + ''; }; }