diff --git a/modules/home-environment.nix b/modules/home-environment.nix
index c98cb9ea9..05931c09b 100644
--- a/modules/home-environment.nix
+++ b/modules/home-environment.nix
@@ -307,9 +307,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.<name?>.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.submoduleSupport.enable
+      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 1e1131f9c..2de7b6f83 100644
--- a/nixos/default.nix
+++ b/nixos/default.nix
@@ -30,6 +30,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}";