Run script after user gets created

So, I would like to run a script after a user specified in users.users gets created. Searching the Internet didn’t bring up many things, and doing a Ctrl+F on the entire manual page of the NixOS manual regarding options only got me:

  • system.userActivationScripts – runs on every nixos-rebuild, and I only want it to run upon the creation of a specific user
  • system.activationScripts – same but the naming doesn’t make it as clear as the previous one as to when these scripts run

Now, I could use one of those and just implement some very simple logic in my script to detect if it ran before and prevent from running it more than once, but I want to see if there’s a better way of doing this.

what does this script do, there might be a better way.

Make some folders and clone some Git repos. Not much basically

Do you need these to run during install, or is it appropriate (better?) to run on first login?

For the latter, a user systemd service would work.

You might also look at using home-manager for these users, and you can set up a lot more

1 Like

During install would be best, since this way the first boot would have a better out of the box experience, and if it’d run at first boot, the first time the user would log in, it would log in into nothing.

I do have home-manager, but until I figure out how to properly install it for the user from the configuration.nix file for better automation, I was thinking of using this script to also install home-manager for the user.