summaryrefslogtreecommitdiff
path: root/hosts/muhammed/update-git-repos/default.nix
blob: 673f86d71511ce333b97351ac39e380c359b5365 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{pkgs, ...}: {
  launchd.agents."update-git-repos" = {
    serviceConfig = {
      ProgramArguments = let
        script = pkgs.writeShellScript "update-git-repos" ''
          printf '\x1b[1m=> Starting %s\x1b[0m\n' "$(basename "$0")"
          find ~/Source ~/Projects -name '*.git' -print0 | while read -d $'\0' -r repo; do
            printf '\x1b[1m=> Updating %s\x1b[0m\n' "$repo"
            git -C "$repo" fetch --all
          done
        '';
      in
        # This *should* forward the scripts output to the universal logging system.
        # I can't really figure it out and I kind of hate all of Apple's tooling.
        ["/bin/sh" "-c" "${script} 2>&1 | logger -s"];

      # Only run this service when network is available.
      KeepAlive.NetworkState = true;

      StartInterval = 3600; # Once an hour.
    };
  };
}