summaryrefslogtreecommitdiff
path: root/hostnix/elmo/system.nix
blob: fe0ddb0518cf0757117490136dbf7361e69bb504 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{ config, pkgs, ... }:

{
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  boot.tmp.useTmpfs = true;
  nix.settings.build-dir = "/var/tmp";

  time.timeZone = "America/New_York";

  networking.hostName = "elmo";
  networking.domain = "mou.fo";

  # TODO switch to networkd
  networking.networkmanager.enable = true;

  services.avahi = {
    enable = true;
    nssmdns4 = true;
    publish = {
      enable = true;
      addresses = true;
    };
  };

  # https://nixos.wiki/wiki/Hardware/Apple#Auto_Restart
  systemd.services.enable-autorestart = {
    description = "Boot after power failure (server mode)";
    wantedBy = [ "multi-user.target" ];
    serviceConfig = {
      Type = "oneshot";
    };
    # https://superuser.com/a/1051137
    script = "${pkgs.pciutils}/bin/setpci -s 00:1f.0 0xa4.b=0";
  };

  systemd.services.boot-email = {
    description = "Boot email";
    wantedBy = [ "multi-user.target" ];
    serviceConfig = {
      Type = "oneshot";
    };
    script = ''
      echo -e "Subject: ${config.networking.fqdn} restarted\n\n$(date)" | /run/wrappers/bin/sendmail root
    '';
  };

  # https://wiki.archlinux.org/index.php/Systemd/Timers#MAILTO
  systemd.services."status-email@" = {
    description = "Status email for %i";
    unitConfig = {
      # Throttle notifications to twice daily.
      StartLimitIntervalSec = "12hr";
      StartLimitBurst = "1";
    };
    serviceConfig = {
      Type = "oneshot";
    };
    scriptArgs = "%i";
    script = ''
      /run/wrappers/bin/sendmail root <<EOF
      From: systemd <root>
      Subject: $1 status
      Content-Transfer-Encoding: 8bit
      Content-Type: text/plain; charset=UTF-8

      $(systemctl status --full "$1")
      EOF
    '';
  };
}