Whats the best practice to change username

During installation i created main user with a name and now i wanted to change the username/login name. And currently i have declared my username inside flake.nix file with a variable.

Can i just change the username pointed by the variable directly ? if then should i do a direct rebuild or rebuild followed by flake update ?

or is it not advisable ?!

I have removed and added users fine via config, but not changed username using the config. I’d suggest that the approach is partly dependant upon the rest of your system and your risk appetite. Do you have lots of data on it (backed up of course), or a new build. Does the user and group ID matter for the operation of the system? Do you have a temporary system you can try it on first?

I’d add another temporary user and then edit the config elements for your first user with appropriate permissions and password - at least you can log in with the new user and edit the original. All my important data is on shared drives and I have a backup of my config so I’d feel safe trying this…