about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/system/boot/systemd/journald-gateway.nix
blob: 854965282344d9190feb1a1a148b6dc2f9a9900e (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
{ config, lib, pkgs, ... }:

let
  cfg = config.services.journald.gateway;

  cliArgs = lib.cli.toGNUCommandLineShell { } {
    # If either of these are null / false, they are not passed in the command-line
    inherit (cfg) cert key trust system user merge;
  };
in
{
  meta.maintainers = [ lib.maintainers.raitobezarius ];
  options.services.journald.gateway = {
    enable = lib.mkEnableOption "the HTTP gateway to the journal";

    port = lib.mkOption {
      default = 19531;
      type = lib.types.port;
      description = ''
        The port to listen to.
      '';
    };

    cert = lib.mkOption {
      default = null;
      type = with lib.types; nullOr str;
      description = lib.mdDoc ''
        The path to a file or `AF_UNIX` stream socket to read the server
        certificate from.

        The certificate must be in PEM format. This option switches
        `systemd-journal-gatewayd` into HTTPS mode and must be used together
        with {option}`services.journald.gateway.key`.
      '';
    };

    key = lib.mkOption {
      default = null;
      type = with lib.types; nullOr str;
      description = lib.mdDoc ''
        Specify the path to a file or `AF_UNIX` stream socket to read the
        secret server key corresponding to the certificate specified with
        {option}`services.journald.gateway.cert` from.

        The key must be in PEM format.

        This key should not be world-readable, and must be readably by the
        `systemd-journal-gateway` user.
      '';
    };

    trust = lib.mkOption {
      default = null;
      type = with lib.types; nullOr str;
      description = lib.mdDoc ''
        Specify the path to a file or `AF_UNIX` stream socket to read a CA
        certificate from.

        The certificate must be in PEM format.

        Setting this option enforces client certificate checking.
      '';
    };

    system = lib.mkOption {
      default = true;
      type = lib.types.bool;
      description = lib.mdDoc ''
        Serve entries from system services and the kernel.

        This has the same meaning as `--system` for {manpage}`journalctl(1)`.
      '';
    };

    user = lib.mkOption {
      default = true;
      type = lib.types.bool;
      description = lib.mdDoc ''
        Serve entries from services for the current user.

        This has the same meaning as `--user` for {manpage}`journalctl(1)`.
      '';
    };

    merge = lib.mkOption {
      default = false;
      type = lib.types.bool;
      description = lib.mdDoc ''
        Serve entries interleaved from all available journals, including other
        machines.

        This has the same meaning as `--merge` option for
        {manpage}`journalctl(1)`.
      '';
    };
  };

  config = lib.mkIf cfg.enable {
    assertions = [
      {
        # This prevents the weird case were disabling "system" and "user"
        # actually enables both because the cli flags are not present.
        assertion = cfg.system || cfg.user;
        message = ''
          systemd-journal-gatewayd cannot serve neither "system" nor "user"
          journals.
        '';
      }
    ];

    systemd.additionalUpstreamSystemUnits = [
      "systemd-journal-gatewayd.socket"
      "systemd-journal-gatewayd.service"
    ];

    users.users.systemd-journal-gateway.uid = config.ids.uids.systemd-journal-gateway;
    users.users.systemd-journal-gateway.group = "systemd-journal-gateway";
    users.groups.systemd-journal-gateway.gid = config.ids.gids.systemd-journal-gateway;

    systemd.services.systemd-journal-gatewayd.serviceConfig.ExecStart = [
        # Clear the default command line
        ""
        "${pkgs.systemd}/lib/systemd/systemd-journal-gatewayd ${cliArgs}"
    ];

    systemd.sockets.systemd-journal-gatewayd = {
      wantedBy = [ "sockets.target" ];
      listenStreams = [
        # Clear the default port
        ""
        (toString cfg.port)
      ];
    };
  };
}