How to change the username
If you want to change the default username to something other than nixos
, use the wsl.defaultUser
option.
When building your own tarball, this should be sufficient. A user with the name specified in that option will be created automatically.
Changing the username on an already installed system is possible as well. Follow these instructions to make sure, the change gets applied correctly:
- Change the
wsl.defaultUser
setting in your configuration to the desired username. - Apply the configuration:
sudo nixos-rebuild boot
Do not usenixos-rebuild switch
! It may lead to the new user account being misconfigured. - Exit the WSL shell and stop your NixOS distro:
wsl -t NixOS
. - Start a shell inside NixOS and immediately exit it to apply the new generation:
wsl -d NixOS --user root exit
- Stop the distro again:
wsl -t NixOS
- Open a WSL shell. Your new username should be applied now!