Why can't I use a submodule for homeConfigurations?

In order to avoid having to hard-code a username into my flake I tried making a submodule.

homeConfigurations = with pkgs.lib.types; submodule ({ name }: home-manager.lib.homeManagerConfiguration {
      inherit pkgs;
      modules = [./nix/home.nix];

      extraSpecialArgs = {
        username = name;
        inherit inputs system;
      };
    });

Can someone explain why this doesn’t work? I already figured that this wouldn’t work because everyone would be doing it if it was this easy. Also on a more fundamental level wouldn’t that take care of most flake issues? Why isn’t this design used?

Here’s the errors I got when trying to evaluate it:

nix run path:dotfiles/#homeConfigurations.“notyou”.activationPackage
error: flake ‘path:dotfiles/’ does not provide attribute ‘apps.x86_64-linux.homeConfigurations.notyou.activationPackage’, ‘packages.x86_64-linux.homeConfigurations.notyou.activationPackage’, ‘legacyPackages.x86_64-linux.homeConfigurations.notyou.activationPackage’ or ‘homeConfigurations.notyou.activationPackage’

It definitely exists tho because when I try to re-assign to “notyou” with this code

homeConfigurations.notyou = homeConfigurations.notyou;

then I get

error: attribute 'homeConfigurations.notyou' already defined at /nix/store/kxxcf5rlwddpcrfq719nm351z2wfcgv0-source/flake.nix:46:5
 
at /nix/store/kxxcf5rlwddpcrfq719nm351z2wfcgv0-source/flake.nix:56:5:
     55|
     56|     homeConfigurations.notyou = homeConfigurations.notyou;
       |     ^
     57|   };
nix run path:./#homeConfigurations."notyou".config.home.activationPackage
error: flake 'path:./' does not provide attribute 'apps.x86_64-linux.homeConfigurations.notyou.config.home.activationPackage', 'packages.x86_64-linux.homeConfigurations.notyou.config.home.activationPackage', 'legacyPackages.x86_64-linux.homeConfigurations.notyou.config.home.activationPackage' or 'homeConfigurations.notyou.config.home.activationPackage'

That didn’t work either

Do you have your config in github or somewhere we can take a look?

yeah but since this doesn’t work it’s not commited/on github.
A link to my config is here GitHub - DaniD3v/nixOS-dotfiles: The flake containing my user dotfiles

Nix modules have 3 parts and 2 ‘players’:

  1. Module author:
    1.1. defines what information the module accepts (starts with options.)
    1.2. defines what to do with this information when settled (starts with config. or not)
  2. Module user:
    2.3. set information to modules (starts with config. or not)

Confusion arises, because 1.2 is basically 2.3 with recursion(recursion).

submodule means you are trying to define a new type (1.1), without the rest of code I can’t be sure it starts with options or config or not?

Anyway since you trying to inject a parameter in flake, I would recommend you to play with inputs.
Move your username.nix as input of flake, set flake to false, input your input (username = import ${username}/username.nix; and pass a different input with --override-input (--override-input username path:./other-user).
It is the worst advice I could give you, since the ideal flake should be pure as Svalbarði water.