about summary refs log tree commit diff
path: root/modules/services/sendsms/default.nix
blob: dde77cac063bebf3f9201263d4c7be3356dd4ec4 (plain) (blame)
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
# send SMS based on actions
{ pkgs, config, lib, ... }:
let
  cfg = config.my.services.sendsms;
  secrets = config.age.secrets;
in
{
  options.my.services.sendsms = {
    enable = lib.mkEnableOption "send SMS when the host reboots";
  };

  config = lib.mkIf cfg.enable {
    systemd.services.sendsms-reboot = {
      description = "Send an SMS when the host has booted";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      path = [ pkgs.sendsms ];
      restartIfChanged = false;

      unitConfig = {
        # If the gate file exists, it means we've already send the
        # message, nothing to do
        ConditionPathExists = "!/run/sendsms/reboot";
      };

      serviceConfig = {
        Type = "oneshot";
        ExecStart = "${pkgs.sendsms}/bin/sendsms --config ${secrets."sendsms/config".path} reboot";

        # Write a gate file so we don't send a message multiple times
        ExecStartPost = "${pkgs.coreutils}/bin/touch /run/sendsms/reboot";

        Restart = "on-failure";

        # Runtime directory and mode
        RuntimeDirectory = "sendsms";
        RuntimeDirectoryMode = "0755";
        RuntimeDirectoryPreserve = "yes";

        # Access write directories
        UMask = "0027";

        # Capabilities
        CapabilityBoundingSet = "";

        # Security
        NoNewPrivileges = true;

        # Sandboxing
        ProtectSystem = "strict";
        ProtectHome = true;
        PrivateTmp = true;
        PrivateUsers = true;
        ProtectHostname = true;
        ProtectClock = true;
        ProtectKernelTunables = true;
        ProtectKernelModules = true;
        ProtectKernelLogs = true;
        ProtectControlGroups = true;
        LockPersonality = true;
        MemoryDenyWriteExecute = true;
        RestrictRealtime = true;
        RestrictSUIDSGID = true;
        PrivateMounts = true;

        # System Call Filtering
        SystemCallArchitectures = "native";
        SystemCallFilter = "~@clock @cpu-emulation @debug @keyring @memlock @module @mount @obsolete @raw-io @reboot @setuid @swap";
      };
    };
  };
}