How to put nixos config and home-manager config in the same file?

I have the following code, and the consists of configuration from NixOS and Home-Manager, which I am getting error for including this file in either side.

{ pkgs, dotfiles, ... }:

  # From HM
  xdg.configFile = { "leftwm/" = { source = "${dotfiles}/leftwm"; }; };

  # From NixOS
  services.xserver = {
    windowManager.leftwm = { enable = true; };
    displayManager = { defaultSession = "none+leftwm"; };

How can I fix the error, while keeping the config in the same file?

I don’t use home-manager but there is a section on wiki describing how to use it as a NixOS module. Did you check that out?

@winston0410 did you ever find a solution to this?
I’m trying to do the same thing to group two configs together in one file but home-manager is defined at the top level as a flake input.

I would like for example to add a desktop file to the droidcam config.