I (maybe) found a way to have Home Manager config as normal NixOS module

I tried to understand how home-manager works since I knew that NixOS module requires a schema that is as an attr set

{
  imports = ...
  options = ...
  config = ...
}

(and there is a shorthand version).

so I realized that home-manager has to generate something like that. I played with it a bit:

a = inputs.home-manager.nixosModule { inherit lib pkgs; config = { home-manager = { }; }; utils = { }; };

b = builtins.head a.config.contents;

c = builtins.head a.config.contents).home-manager;

and I can see that it is generating { config = ... imports = ... }.

I wonder is it possible to have both system config and user config (HM) in a single file?

In most cases this wouldn’t be needed but in some cases such freedom:

  config = {
    systemd.services.my-custom-user-app = {
      # ...
    };

	home-manager.users.custom-app-user {
      # ...
    };
  };

would be nice!

(this might not be the best example but I’m sure you can come up with some real use cases)

So is this even possible?