diff --git a/modules/home-environment.nix b/modules/home-environment.nix index c6fc345d..8e896dee 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -285,9 +285,31 @@ in home.activation.writeBoundary = dag.entryAnywhere ""; # Install packages to the user environment. - home.activation.installPackages = dag.entryAfter ["writeBoundary"] '' - $DRY_RUN_CMD nix-env -i ${cfg.path} - ''; + # + # Note, if we are running as a NixOS module then we cannot rely on + # `nix-envĀ -i` because our target may not allow modification of + # the Nix store. We will instead use the + # `users.users..packages` NixOS option. We still need this + # activation command, however, since some modules need to ensure + # that their activation commands are run after packages are + # guaranteed to be installed. + # + # In case the user has moved from a user-install of Home Manager + # to one managed through the NixOS module we attempt to uninstall + # the `home-manager-path` package if it is installed. + home.activation.installPackages = dag.entryAfter ["writeBoundary"] ( + if config.nixosSubmodule + then + '' + if nix-env -q | grep '^home-manager-path$'; then + nix-env -e home-manager-path + fi + '' + else + '' + $DRY_RUN_CMD nix-env -i ${cfg.path} + '' + ); home.activationPackage = let diff --git a/nixos/default.nix b/nixos/default.nix index c101f5a9..416876b7 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -32,6 +32,10 @@ in }; config = mkIf (cfg.users != {}) { + users.users = mapAttrs (username: usercfg: { + packages = usercfg.home.packages; + }) cfg.users; + systemd.services = mapAttrs' (username: usercfg: nameValuePair ("home-manager-${utils.escapeSystemdPath username}") { description = "Home Manager environment for ${username}";