aboutsummaryrefslogtreecommitdiff
path: root/modules/profiles/upgrade/default.nix
blob: e91d0bae6947b5372a89a5399888f931c67065e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# modules/profiles/upgrade/default.nix
#
# Weekly package upgrades to keep select systems up to date. A service also
# reports server events to notify me when a system updates or restarts.

{
  inputs,
  config,
  ...
}:
{
  system.autoUpgrade = {
    enable = true;
    flake = inputs.self.outPath;
    flags = [
      "--update-input"
      "nixpkgs"
      "-L"
    ];
    dates = "Sat *-*-* 06:00:00";
    randomizedDelaySec = "45min";
    allowReboot = true;
  };

  systemd.services."server-monitor" =
    let
      dependencies = [ "network-online.target" ];
    in
    {
      wantedBy = [ "multi-user.target" ];
      wants = dependencies;
      after = dependencies;
      serviceConfig.Type = "oneshot";
      script = ''
        ACTION="restarted"

        # If a system has been up for *at least* 90 seconds, make the assumption
        # that the system's configuration was rebuilt and activated.
        if [ "$(cat /proc/uptime | cut -f1 -d.)" -gt 90 ]; then
          ACTION="activated a new configuration"
        fi

        /run/current-system/sw/bin/pushover -t "${config.networking.hostName}" \
          "Server $ACTION on $(date '+%a, %b %d at %T %p %Z')."
      '';
    };
}