Run script on user creation

Hi all

i created an installation using nixos 25.6 and nowadays im not using flakes , and i want to know if there is a way to run a script after user creation . For example i create an user and copy some directories using rsync from my nas

thanks

Never had a user for this, but if you really need it one place to start might be to look into how users.users gets implemented in nixos/modules/config/users-groups.nix and how the activation script at nixos/modules/config/update-users-groups.pl works.

Realistically, if I needed something like what you are describing, I’d probably maintain a shell script in the same repo as my NixOS config that I just run manually on standing up a new machine. A bit messy perhaps, but a pragmatic approach to something wouldn’t expect to do often.

I think the script is a good starting point. I usually have a justfile where I write commands (so i remember them).

As the script/justfile starts showing limitations, you could move to a more advanced setup by writing your own nix module to extend the existing users.users. The nix module could use a oneshot systemd service. For example, adding a users.users.<name>.provisionScript. You could then specify what resources to wait for before running, or when to retry, and add some hardening.