In home.activation one can specify activation script that are run in a systemd service (by that user) at startup. There is infrastructure to order those, e.g. with lib.hm.dag.entryAfter:
However in this case it fails as git has no user/email set. How do I tell home-manager to first set up git, then run the activation?
If it errors out, the ~/.config/git/config isnโt even created, so home-manager seems to run the activation before the setting up the programs. If I ignore the error in the activation with || true, the activation proceeds and the ~/.config/git/config is created.
I also donโt see anything programs.git-related in journalctl -eu home-manager-myUser.service, even with home-manager.verbose = true set.
This is probably a bad workaround but you could try telling git to set your email and username at the repo level, inside the script by referencing the config.programs.git.userEmail and userName? (You could also unset this at the end of the script).
I would guess this script is isolated to a good degree. I wouldnโt expect it to run in the environment of a login shell.
What @wyyllou suggests seems like the correct approach to me.
But thereโs something fishy to me about trying to clone a repo in a home manager activation script. At the very least, it wouldnโt work offline, would it?
Yeah I have my reasons to do that. Itโs also not a clone but executing a git command in a then extracted tarball of a repo. I wanted to keep complexity low for this example.
I had a similar issue, I could commit but couldnโt push. From my understanding, the script is ran as root, so it doesnโt have your ssh key or git config, and clone the repository with root config.
Have you considered a temporary git-config referenced by env var (i.e. GIT_CONFIG_GLOBAL)? I realise this side steps the ordering issue, but it also massively isolates the script from the existence or non-existence of a users configuration.