···
1
+
# This module implements a systemd service for running journaldriver,
2
+
# a log forwarding agent that sends logs from journald to Stackdriver
5
+
# It can be enabled without extra configuration when running on GCP.
6
+
# On machines hosted elsewhere, the other configuration options need
9
+
# For further information please consult the documentation in the
10
+
# upstream repository at: https://github.com/aprilabank/journaldriver/
12
+
{ config, lib, pkgs, ...}:
14
+
with lib; let cfg = config.services.journaldriver;
16
+
options.services.journaldriver = {
21
+
Whether to enable journaldriver to forward journald logs to
22
+
Stackdriver Logging.
26
+
logLevel = mkOption {
30
+
Log level at which journaldriver logs its own output.
34
+
logName = mkOption {
35
+
type = with types; nullOr str;
38
+
Configures the name of the target log in Stackdriver Logging.
39
+
This option can be set to, for example, the hostname of a
40
+
machine to improve the user experience in the logging
45
+
googleCloudProject = mkOption {
46
+
type = with types; nullOr str;
49
+
Configures the name of the Google Cloud project to which to
50
+
forward journald logs.
52
+
This option is required on non-GCP machines, but should not be
53
+
set on GCP instances.
57
+
logStream = mkOption {
58
+
type = with types; nullOr str;
61
+
Configures the name of the Stackdriver Logging log stream into
62
+
which to write journald entries.
64
+
This option is required on non-GCP machines, but should not be
65
+
set on GCP instances.
69
+
applicationCredentials = mkOption {
70
+
type = with types; nullOr path;
73
+
Path to the service account private key (in JSON-format) used
74
+
to forward log entries to Stackdriver Logging on non-GCP
77
+
This option is required on non-GCP machines, but should not be
78
+
set on GCP instances.
83
+
config = mkIf cfg.enable {
84
+
systemd.services.journaldriver = {
85
+
description = "Stackdriver Logging journal forwarder";
86
+
script = "${pkgs.journaldriver}/bin/journaldriver";
87
+
after = [ "network-online.target" ];
88
+
wantedBy = [ "multi-user.target" ];
94
+
# This directive lets systemd automatically configure
95
+
# permissions on /var/lib/journaldriver, the directory in
96
+
# which journaldriver persists its cursor state.
97
+
StateDirectory = "journaldriver";
99
+
# This group is required for accessing journald.
100
+
SupplementaryGroups = "systemd-journal";
104
+
RUST_LOG = cfg.logLevel;
105
+
LOG_NAME = cfg.logName;
106
+
LOG_STREAM = cfg.logStream;
107
+
GOOGLE_CLOUD_PROJECT = cfg.googleCloudProject;
108
+
GOOGLE_APPLICATION_CREDENTIALS = cfg.applicationCredentials;