about summary refs log tree commit diff
path: root/nixos/modules/system/boot/systemd/journald-upload.nix
blob: 6421e5fa486f98698d1ed407292cec608a9dfa99 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{ config, lib, pkgs, ... }:

let
  cfg = config.services.journald.upload;
  format = pkgs.formats.systemd;
in
{
  meta.maintainers = [ lib.maintainers.raitobezarius ];
  options.services.journald.upload = {
    enable = lib.mkEnableOption "uploading the systemd journal to a remote server";

    settings = lib.mkOption {
      default = { };

      description = lib.mdDoc ''
        Configuration for journal-upload. See {manpage}`journal-upload.conf(5)`
        for available options.
      '';

      type = lib.types.submodule {
        freeformType = format.type;

        options.Upload = {
          URL = lib.mkOption {
            type = lib.types.str;
            example = "https://192.168.1.1";
            description = ''
              The URL to upload the journal entries to.

              See the description of `--url=` option in
              {manpage}`systemd-journal-upload(8)` for the description of
              possible values.
            '';
          };

          ServerKeyFile = lib.mkOption {
            type = with lib.types; nullOr str;
            example = lib.literalExpression "./server-key.pem";
            # Since systemd-journal-upload uses a DynamicUser, permissions must
            # be done using groups
            description = ''
              SSL key in PEM format.

              In contrary to what the name suggests, this option configures the
              client private key sent to the remote journal server.

              This key should not be world-readable, and must be readably by
              the `systemd-journal` group.
            '';
            default = null;
          };

          ServerCertificateFile = lib.mkOption {
            type = with lib.types; nullOr str;
            example = lib.literalExpression "./server-ca.pem";
            description = ''
              SSL CA certificate in PEM format.

              In contrary to what the name suggests, this option configures the
              client certificate sent to the remote journal server.
            '';
            default = null;
          };

          TrustedCertificateFile = lib.mkOption {
            type = with lib.types; nullOr str;
            example = lib.literalExpression "./ca";
            description = ''
              SSL CA certificate.

              This certificate will be used to check the remote journal HTTPS
              server certificate.
            '';
            default = null;
          };

          NetworkTimeoutSec = lib.mkOption {
            type = with lib.types; nullOr str;
            example = "1s";
            description = ''
              When network connectivity to the server is lost, this option
              configures the time to wait for the connectivity to get restored.

              If the server is not reachable over the network for the
              configured time, `systemd-journal-upload` exits. Takes a value in
              seconds (or in other time units if suffixed with "ms", "min",
              "h", etc). For details, see {manpage}`systemd.time(5)`.
            '';
            default = null;
          };
        };
      };
    };
  };

  config = lib.mkIf cfg.enable {
    systemd.additionalUpstreamSystemUnits = [ "systemd-journal-upload.service" ];

    systemd.services."systemd-journal-upload" = {
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        Restart = "always";
        # To prevent flooding the server in case the server is struggling
        RestartSec = "3sec";
      };
    };

    environment.etc."systemd/journal-upload.conf".source =
      format.generate "journal-upload.conf" cfg.settings;
  };
}