Flake pass parameterr to dynamic user name on build

I have this flake.nix who I have to keep changing user variable between My two machines, But I have files .nix in common using the variable.
flake.nix · GitHub

Have any way to pass this variable as parameter on the nixos-rebuild to change dynamically ?

You can use genAttrs to have one attribute for each of your users. nixos-rebuild should be able to pick the correct one based on your host name.

Why do you need to change variables between to machines?

2 machines should mean 2 configurations, which seem to be defined in a file that you haven’t shown.

Im using this file in common home.nix · GitHub, this applications have to be in both machines, so I figure I dont need repeat in the host files, right ? Im new in nix language, can you give me a example on genAttrs? I read the files on github but I dont undestood

here my flake repo to be clear: GitHub - pedrohms/flake-config

What exactly is it you have to change?

I see 3 machines and 2 home configs, what exactly do you want to pass different “variables”?

Instead of using the user variable in the standalone configs, I have to be honest, you should just hardcode the relevant names!

Similarily for the 3 system configurations.

And of course, use inline modules as already showed above.

something like this should work

{
  nixosConfigurations = genAttrs [ "pedro" "framework" ] (user: nixosSystem {
    # blah blah blah
  });
}

I’m not sure why you would have 3 different configs for each username, did you want to have 6 different configs?

Ty @figsoda . Im new on nixos, but I have 1 config for each machine, and a home-manager flake for home-manager testing.

In your hosts/default.nix, you have notepedro, desenv07, and vm, how do they correspond to the usernames?

undefined variable ‘genAttrs’

this is in lib (nixpkgs.lib)

returning error: “error: value is a set while a string was expectederror: value is a set while a string was expected”. I have tried 2 ways:

Passing genAttrs to user but hes giving me error above:

error: value is a set while a string was expected

And passing as a functoin to nixosConfigurations:

  nixosConfigurations = nixpkgs.lib.genAttrs["desenv07" "notepedro"] ( user: nixosSystem {>
     (import ./hosts >{
       inherit (nixpkg>s) lib;
       inherit inputs n>ixpkgs user location  home-manager my-overlays;
     });
   }
 );

and its returning:

error: syntax error, unexpected ‘(’

from nix flake check.

Im hardcoding the user, but would be better if I could pass a parameter to set the user, because If I choose share this configuration with friends they could just choose which profile they prefer. Ps.: The third machine its, me testing a virtual machine configuration. The current flake configuration works flawless just missing this user issue

If your friends want to just copy, then they shall copy the relevant parts, not everything.