2020-04-24 23:36:52 +00:00
|
|
|
{ options, config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.grafana;
|
|
|
|
opt = options.services.grafana;
|
2021-01-05 17:05:55 +00:00
|
|
|
declarativePlugins = pkgs.linkFarm "grafana-plugins" (builtins.map (pkg: { name = pkg.pname; path = pkg; }) cfg.declarativePlugins);
|
2021-08-27 14:25:00 +00:00
|
|
|
useMysql = cfg.database.type == "mysql";
|
|
|
|
usePostgresql = cfg.database.type == "postgres";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
envOptions = {
|
|
|
|
PATHS_DATA = cfg.dataDir;
|
2021-01-05 17:05:55 +00:00
|
|
|
PATHS_PLUGINS = if builtins.isNull cfg.declarativePlugins then "${cfg.dataDir}/plugins" else declarativePlugins;
|
2020-04-24 23:36:52 +00:00
|
|
|
PATHS_LOGS = "${cfg.dataDir}/log";
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
SERVER_SERVE_FROM_SUBPATH = boolToString cfg.server.serveFromSubPath;
|
2020-04-24 23:36:52 +00:00
|
|
|
SERVER_PROTOCOL = cfg.protocol;
|
|
|
|
SERVER_HTTP_ADDR = cfg.addr;
|
|
|
|
SERVER_HTTP_PORT = cfg.port;
|
2021-04-05 15:23:46 +00:00
|
|
|
SERVER_SOCKET = cfg.socket;
|
2020-04-24 23:36:52 +00:00
|
|
|
SERVER_DOMAIN = cfg.domain;
|
|
|
|
SERVER_ROOT_URL = cfg.rootUrl;
|
|
|
|
SERVER_STATIC_ROOT_PATH = cfg.staticRootPath;
|
|
|
|
SERVER_CERT_FILE = cfg.certFile;
|
|
|
|
SERVER_CERT_KEY = cfg.certKey;
|
|
|
|
|
|
|
|
DATABASE_TYPE = cfg.database.type;
|
|
|
|
DATABASE_HOST = cfg.database.host;
|
|
|
|
DATABASE_NAME = cfg.database.name;
|
|
|
|
DATABASE_USER = cfg.database.user;
|
|
|
|
DATABASE_PASSWORD = cfg.database.password;
|
|
|
|
DATABASE_PATH = cfg.database.path;
|
|
|
|
DATABASE_CONN_MAX_LIFETIME = cfg.database.connMaxLifetime;
|
|
|
|
|
|
|
|
SECURITY_ADMIN_USER = cfg.security.adminUser;
|
|
|
|
SECURITY_ADMIN_PASSWORD = cfg.security.adminPassword;
|
|
|
|
SECURITY_SECRET_KEY = cfg.security.secretKey;
|
|
|
|
|
|
|
|
USERS_ALLOW_SIGN_UP = boolToString cfg.users.allowSignUp;
|
|
|
|
USERS_ALLOW_ORG_CREATE = boolToString cfg.users.allowOrgCreate;
|
|
|
|
USERS_AUTO_ASSIGN_ORG = boolToString cfg.users.autoAssignOrg;
|
|
|
|
USERS_AUTO_ASSIGN_ORG_ROLE = cfg.users.autoAssignOrgRole;
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
AUTH_DISABLE_LOGIN_FORM = boolToString cfg.auth.disableLoginForm;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
AUTH_ANONYMOUS_ENABLED = boolToString cfg.auth.anonymous.enable;
|
|
|
|
AUTH_ANONYMOUS_ORG_NAME = cfg.auth.anonymous.org_name;
|
|
|
|
AUTH_ANONYMOUS_ORG_ROLE = cfg.auth.anonymous.org_role;
|
2022-06-16 17:23:12 +00:00
|
|
|
|
|
|
|
AUTH_AZUREAD_NAME = "Azure AD";
|
|
|
|
AUTH_AZUREAD_ENABLED = boolToString cfg.auth.azuread.enable;
|
|
|
|
AUTH_AZUREAD_ALLOW_SIGN_UP = boolToString cfg.auth.azuread.allowSignUp;
|
|
|
|
AUTH_AZUREAD_CLIENT_ID = cfg.auth.azuread.clientId;
|
|
|
|
AUTH_AZUREAD_SCOPES = "openid email profile";
|
|
|
|
AUTH_AZUREAD_AUTH_URL = "https://login.microsoftonline.com/${cfg.auth.azuread.tenantId}/oauth2/v2.0/authorize";
|
|
|
|
AUTH_AZUREAD_TOKEN_URL = "https://login.microsoftonline.com/${cfg.auth.azuread.tenantId}/oauth2/v2.0/token";
|
|
|
|
AUTH_AZUREAD_ALLOWED_DOMAINS = cfg.auth.azuread.allowedDomains;
|
|
|
|
AUTH_AZUREAD_ALLOWED_GROUPS = cfg.auth.azuread.allowedGroups;
|
|
|
|
AUTH_AZUREAD_ROLE_ATTRIBUTE_STRICT = false;
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
AUTH_GOOGLE_ENABLED = boolToString cfg.auth.google.enable;
|
|
|
|
AUTH_GOOGLE_ALLOW_SIGN_UP = boolToString cfg.auth.google.allowSignUp;
|
|
|
|
AUTH_GOOGLE_CLIENT_ID = cfg.auth.google.clientId;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
ANALYTICS_REPORTING_ENABLED = boolToString cfg.analytics.reporting.enable;
|
|
|
|
|
|
|
|
SMTP_ENABLED = boolToString cfg.smtp.enable;
|
|
|
|
SMTP_HOST = cfg.smtp.host;
|
|
|
|
SMTP_USER = cfg.smtp.user;
|
|
|
|
SMTP_PASSWORD = cfg.smtp.password;
|
|
|
|
SMTP_FROM_ADDRESS = cfg.smtp.fromAddress;
|
|
|
|
} // cfg.extraOptions;
|
|
|
|
|
|
|
|
datasourceConfiguration = {
|
|
|
|
apiVersion = 1;
|
|
|
|
datasources = cfg.provision.datasources;
|
|
|
|
};
|
|
|
|
|
|
|
|
datasourceFile = pkgs.writeText "datasource.yaml" (builtins.toJSON datasourceConfiguration);
|
|
|
|
|
|
|
|
dashboardConfiguration = {
|
|
|
|
apiVersion = 1;
|
|
|
|
providers = cfg.provision.dashboards;
|
|
|
|
};
|
|
|
|
|
|
|
|
dashboardFile = pkgs.writeText "dashboard.yaml" (builtins.toJSON dashboardConfiguration);
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
notifierConfiguration = {
|
|
|
|
apiVersion = 1;
|
|
|
|
notifiers = cfg.provision.notifiers;
|
|
|
|
};
|
|
|
|
|
|
|
|
notifierFile = pkgs.writeText "notifier.yaml" (builtins.toJSON notifierConfiguration);
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
provisionConfDir = pkgs.runCommand "grafana-provisioning" { } ''
|
2021-03-09 03:18:52 +00:00
|
|
|
mkdir -p $out/{datasources,dashboards,notifiers}
|
2020-04-24 23:36:52 +00:00
|
|
|
ln -sf ${datasourceFile} $out/datasources/datasource.yaml
|
|
|
|
ln -sf ${dashboardFile} $out/dashboards/dashboard.yaml
|
2021-03-09 03:18:52 +00:00
|
|
|
ln -sf ${notifierFile} $out/notifiers/notifier.yaml
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
# Get a submodule without any embedded metadata:
|
|
|
|
_filter = x: filterAttrs (k: v: k != "_module") x;
|
|
|
|
|
|
|
|
# http://docs.grafana.org/administration/provisioning/#datasources
|
|
|
|
grafanaTypes.datasourceConfig = types.submodule {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Name of the datasource. Required.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
type = mkOption {
|
2021-06-28 23:13:55 +00:00
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Datasource type. Required.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
access = mkOption {
|
|
|
|
type = types.enum ["proxy" "direct"];
|
|
|
|
default = "proxy";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Access mode. proxy or direct (Server or Browser in the UI). Required.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
orgId = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Org id. will default to orgId 1 if not specified.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2022-06-16 17:23:12 +00:00
|
|
|
uid = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Custom UID which can be used to reference this datasource in other parts of the configuration, if not specified will be generated automatically.";
|
2022-06-16 17:23:12 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
url = mkOption {
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Url of the datasource.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
password = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Database password, if used.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
user = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Database user, if used.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
database = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Database name, if used.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
basicAuth = mkOption {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Enable/disable basic auth.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
basicAuthUser = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Basic auth username.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
basicAuthPassword = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Basic auth password.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
withCredentials = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Enable/disable with credentials headers.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
isDefault = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Mark as default datasource. Max one per org.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
jsonData = mkOption {
|
|
|
|
type = types.nullOr types.attrs;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Datasource specific configuration.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
secureJsonData = mkOption {
|
|
|
|
type = types.nullOr types.attrs;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Datasource specific secure configuration.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
version = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Version.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
editable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Allow users to edit datasources from the UI.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# http://docs.grafana.org/administration/provisioning/#dashboards
|
|
|
|
grafanaTypes.dashboardConfig = types.submodule {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "default";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Provider name.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
orgId = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Organization ID.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
folder = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Add dashboards to the specified folder.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
type = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "file";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Dashboard provider type.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
disableDeletion = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Disable deletion when JSON file is removed.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
updateIntervalSeconds = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 10;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "How often Grafana will scan for changed dashboards.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
options = {
|
|
|
|
path = mkOption {
|
|
|
|
type = types.path;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Path grafana will watch for dashboards.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2022-03-30 09:31:56 +00:00
|
|
|
foldersFromFilesStructure = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Use folder names from filesystem to create folders in Grafana.";
|
2022-03-30 09:31:56 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-03-09 03:18:52 +00:00
|
|
|
|
|
|
|
grafanaTypes.notifierConfig = types.submodule {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "default";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Notifier name.";
|
2021-03-09 03:18:52 +00:00
|
|
|
};
|
|
|
|
type = mkOption {
|
|
|
|
type = types.enum ["dingding" "discord" "email" "googlechat" "hipchat" "kafka" "line" "teams" "opsgenie" "pagerduty" "prometheus-alertmanager" "pushover" "sensu" "sensugo" "slack" "telegram" "threema" "victorops" "webhook"];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Notifier type.";
|
2021-03-09 03:18:52 +00:00
|
|
|
};
|
|
|
|
uid = mkOption {
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Unique notifier identifier.";
|
2021-03-09 03:18:52 +00:00
|
|
|
};
|
|
|
|
org_id = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Organization ID.";
|
2021-03-09 03:18:52 +00:00
|
|
|
};
|
|
|
|
org_name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "Main Org.";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Organization name.";
|
2021-03-09 03:18:52 +00:00
|
|
|
};
|
|
|
|
is_default = mkOption {
|
|
|
|
type = types.bool;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Is the default notifier.";
|
2021-03-09 03:18:52 +00:00
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
send_reminder = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Should the notifier be sent reminder notifications while alerts continue to fire.";
|
2021-03-09 03:18:52 +00:00
|
|
|
};
|
|
|
|
frequency = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "5m";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "How frequently should the notifier be sent reminders.";
|
2021-03-09 03:18:52 +00:00
|
|
|
};
|
|
|
|
disable_resolve_message = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Turn off the message that sends when an alert returns to OK.";
|
2021-03-09 03:18:52 +00:00
|
|
|
};
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.nullOr types.attrs;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Settings for the notifier type.";
|
2021-03-09 03:18:52 +00:00
|
|
|
};
|
|
|
|
secure_settings = mkOption {
|
|
|
|
type = types.nullOr types.attrs;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Secure settings for the notifier type.";
|
2021-03-09 03:18:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
in {
|
|
|
|
options.services.grafana = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "grafana");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
protocol = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Which protocol to listen.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "http";
|
|
|
|
type = types.enum ["http" "https" "socket"];
|
|
|
|
};
|
|
|
|
|
|
|
|
addr = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Listening address.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "127.0.0.1";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Listening port.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 3000;
|
2021-07-14 22:03:04 +00:00
|
|
|
type = types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-04-05 15:23:46 +00:00
|
|
|
socket = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Listening socket.";
|
2021-04-05 15:23:46 +00:00
|
|
|
default = "/run/grafana/grafana.sock";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
domain = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The public facing domain name used to access grafana from a browser.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "localhost";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
rootUrl = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Full public facing url.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "%(protocol)s://%(domain)s:%(http_port)s/";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
certFile = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Cert file for ssl.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
certKey = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Cert key for ssl.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
staticRootPath = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Root path for static assets.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "${cfg.package}/share/grafana/public";
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression ''"''${package}/share/grafana/public"'';
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Package to use.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = pkgs.grafana;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.grafana";
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.package;
|
|
|
|
};
|
2021-06-28 23:13:55 +00:00
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
declarativePlugins = mkOption {
|
|
|
|
type = with types; nullOr (listOf path);
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "If non-null, then a list of packages containing Grafana plugins to install. If set, plugins cannot be manually installed.";
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression "with pkgs.grafanaPlugins; [ grafana-piechart-panel ]";
|
2021-06-28 23:13:55 +00:00
|
|
|
# Make sure each plugin is added only once; otherwise building
|
|
|
|
# the link farm fails, since the same path is added multiple
|
|
|
|
# times.
|
|
|
|
apply = x: if isList x then lib.unique x else x;
|
2021-01-05 17:05:55 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
dataDir = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Data directory.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "/var/lib/grafana";
|
|
|
|
type = types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
database = {
|
|
|
|
type = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Database type.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "sqlite3";
|
|
|
|
type = types.enum ["mysql" "sqlite3" "postgres"];
|
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Database host.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "127.0.0.1:3306";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Database name.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "grafana";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Database user.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "root";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Database password.
|
|
|
|
This option is mutual exclusive with the passwordFile option.
|
|
|
|
'';
|
|
|
|
default = "";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
passwordFile = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
File that containts the database password.
|
|
|
|
This option is mutual exclusive with the password option.
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
path = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Database path.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "${cfg.dataDir}/data/grafana.db";
|
2021-12-19 01:06:50 +00:00
|
|
|
defaultText = literalExpression ''"''${config.${opt.dataDir}}/data/grafana.db"'';
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
connMaxLifetime = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Sets the maximum amount of time (in seconds) a connection may be reused.
|
|
|
|
For MySQL this setting should be shorter than the `wait_timeout' variable.
|
|
|
|
'';
|
|
|
|
default = "unlimited";
|
|
|
|
example = 14400;
|
|
|
|
type = types.either types.int (types.enum [ "unlimited" ]);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
provision = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "provision");
|
2020-04-24 23:36:52 +00:00
|
|
|
datasources = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Grafana datasources configuration.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = [];
|
|
|
|
type = types.listOf grafanaTypes.datasourceConfig;
|
|
|
|
apply = x: map _filter x;
|
|
|
|
};
|
|
|
|
dashboards = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Grafana dashboard configuration.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = [];
|
|
|
|
type = types.listOf grafanaTypes.dashboardConfig;
|
|
|
|
apply = x: map _filter x;
|
|
|
|
};
|
2021-03-09 03:18:52 +00:00
|
|
|
notifiers = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Grafana notifier configuration.";
|
2021-03-09 03:18:52 +00:00
|
|
|
default = [];
|
|
|
|
type = types.listOf grafanaTypes.notifierConfig;
|
|
|
|
apply = x: map _filter x;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
security = {
|
|
|
|
adminUser = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Default admin username.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "admin";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
adminPassword = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Default admin password.
|
|
|
|
This option is mutual exclusive with the adminPasswordFile option.
|
|
|
|
'';
|
|
|
|
default = "admin";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
adminPasswordFile = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Default admin password.
|
2022-08-12 12:06:08 +00:00
|
|
|
This option is mutual exclusive with the `adminPassword` option.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
secretKey = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Secret key used for signing.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "SW2YcwTIb9zpOOhoPsMm";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
secretKeyFile = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Secret key used for signing.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
server = {
|
|
|
|
serveFromSubPath = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Serve Grafana from subpath specified in rootUrl setting";
|
2022-06-16 17:23:12 +00:00
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
smtp = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "smtp");
|
2020-04-24 23:36:52 +00:00
|
|
|
host = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Host to connect to.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "localhost:25";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
user = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "User used for authentication.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
password = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Password used for authentication.
|
|
|
|
This option is mutual exclusive with the passwordFile option.
|
|
|
|
'';
|
|
|
|
default = "";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
passwordFile = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Password used for authentication.
|
|
|
|
This option is mutual exclusive with the password option.
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
};
|
|
|
|
fromAddress = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Email address used for sending.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "admin@grafana.localhost";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users = {
|
|
|
|
allowSignUp = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Disable user signup / registration.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
allowOrgCreate = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether user is allowed to create organizations.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
autoAssignOrg = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to automatically assign new users to default org.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
autoAssignOrgRole = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Default role new users will be auto assigned.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "Viewer";
|
|
|
|
type = types.enum ["Viewer" "Editor"];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
auth = {
|
2022-06-16 17:23:12 +00:00
|
|
|
disableLoginForm = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Set to true to disable (hide) the login form, useful if you use OAuth";
|
2022-06-16 17:23:12 +00:00
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
anonymous = {
|
|
|
|
enable = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to allow anonymous access.";
|
2021-05-20 23:08:51 +00:00
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
org_name = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Which organization to allow anonymous access to.";
|
2021-05-20 23:08:51 +00:00
|
|
|
default = "Main Org.";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
org_role = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Which role anonymous users have in the organization.";
|
2021-05-20 23:08:51 +00:00
|
|
|
default = "Viewer";
|
|
|
|
type = types.str;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2022-06-16 17:23:12 +00:00
|
|
|
azuread = {
|
|
|
|
enable = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to allow Azure AD OAuth.";
|
2022-06-16 17:23:12 +00:00
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
allowSignUp = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to allow sign up with Azure AD OAuth.";
|
2022-06-16 17:23:12 +00:00
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
clientId = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Azure AD OAuth client ID.";
|
2022-06-16 17:23:12 +00:00
|
|
|
default = "";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
clientSecretFile = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Azure AD OAuth client secret.";
|
2022-06-16 17:23:12 +00:00
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
};
|
|
|
|
tenantId = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-06-16 17:23:12 +00:00
|
|
|
Tenant id used to create auth and token url. Default to "common"
|
|
|
|
, let user sign in with any tenant.
|
|
|
|
'';
|
|
|
|
default = "common";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
allowedDomains = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-09-11 15:47:08 +00:00
|
|
|
Limits access to users who belong to specific domains.
|
|
|
|
Separate domains with space or comma.
|
2022-06-16 17:23:12 +00:00
|
|
|
'';
|
|
|
|
default = "";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
allowedGroups = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-09-11 15:47:08 +00:00
|
|
|
To limit access to authenticated users who are members of one or more groups,
|
|
|
|
set allowedGroups to a comma- or space-separated list of group object IDs.
|
|
|
|
You can find object IDs for a specific group on the Azure portal.
|
|
|
|
'';
|
2022-06-16 17:23:12 +00:00
|
|
|
default = "";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
};
|
2021-05-20 23:08:51 +00:00
|
|
|
google = {
|
|
|
|
enable = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to allow Google OAuth2.";
|
2021-05-20 23:08:51 +00:00
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
allowSignUp = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to allow sign up with Google OAuth2.";
|
2021-05-20 23:08:51 +00:00
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
clientId = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Google OAuth2 client ID.";
|
2021-05-20 23:08:51 +00:00
|
|
|
default = "";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
clientSecretFile = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Google OAuth2 client secret.";
|
2021-05-20 23:08:51 +00:00
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
analytics.reporting = {
|
|
|
|
enable = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to allow anonymous usage reporting to stats.grafana.net.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
extraOptions = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Extra configuration options passed as env variables as specified in
|
2022-08-12 12:06:08 +00:00
|
|
|
[documentation](http://docs.grafana.org/installation/configuration/),
|
2020-04-24 23:36:52 +00:00
|
|
|
but without GF_ prefix
|
|
|
|
'';
|
|
|
|
default = {};
|
|
|
|
type = with types; attrsOf (either str path);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
warnings = flatten [
|
|
|
|
(optional (
|
|
|
|
cfg.database.password != opt.database.password.default ||
|
|
|
|
cfg.security.adminPassword != opt.security.adminPassword.default
|
|
|
|
) "Grafana passwords will be stored as plaintext in the Nix store!")
|
|
|
|
(optional (
|
|
|
|
any (x: x.password != null || x.basicAuthPassword != null || x.secureJsonData != null) cfg.provision.datasources
|
|
|
|
) "Datasource passwords will be stored as plaintext in the Nix store!")
|
2021-03-09 03:18:52 +00:00
|
|
|
(optional (
|
|
|
|
any (x: x.secure_settings != null) cfg.provision.notifiers
|
|
|
|
) "Notifier secure settings will be stored as plaintext in the Nix store!")
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.database.password != opt.database.password.default -> cfg.database.passwordFile == null;
|
|
|
|
message = "Cannot set both password and passwordFile";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.security.adminPassword != opt.security.adminPassword.default -> cfg.security.adminPasswordFile == null;
|
|
|
|
message = "Cannot set both adminPassword and adminPasswordFile";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.security.secretKey != opt.security.secretKey.default -> cfg.security.secretKeyFile == null;
|
|
|
|
message = "Cannot set both secretKey and secretKeyFile";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.smtp.password != opt.smtp.password.default -> cfg.smtp.passwordFile == null;
|
|
|
|
message = "Cannot set both password and passwordFile";
|
|
|
|
}
|
2022-10-21 18:38:19 +00:00
|
|
|
{
|
|
|
|
assertion = all
|
|
|
|
({ type, access, ... }: type == "prometheus" -> access != "direct")
|
|
|
|
cfg.provision.datasources;
|
|
|
|
message = "For datasources of type `prometheus`, the `direct` access mode is not supported anymore (since Grafana 9.2.0)";
|
|
|
|
}
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.grafana = {
|
|
|
|
description = "Grafana Service Daemon";
|
|
|
|
wantedBy = ["multi-user.target"];
|
2021-08-27 14:25:00 +00:00
|
|
|
after = ["networking.target"] ++ lib.optional usePostgresql "postgresql.service" ++ lib.optional useMysql "mysql.service";
|
2020-04-24 23:36:52 +00:00
|
|
|
environment = {
|
|
|
|
QT_QPA_PLATFORM = "offscreen";
|
|
|
|
} // mapAttrs' (n: v: nameValuePair "GF_${n}" (toString v)) envOptions;
|
|
|
|
script = ''
|
2021-06-28 23:13:55 +00:00
|
|
|
set -o errexit -o pipefail -o nounset -o errtrace
|
|
|
|
shopt -s inherit_errexit
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
${optionalString (cfg.auth.azuread.clientSecretFile != null) ''
|
|
|
|
GF_AUTH_AZUREAD_CLIENT_SECRET="$(<${escapeShellArg cfg.auth.azuread.clientSecretFile})"
|
|
|
|
export GF_AUTH_AZUREAD_CLIENT_SECRET
|
|
|
|
''}
|
2021-05-20 23:08:51 +00:00
|
|
|
${optionalString (cfg.auth.google.clientSecretFile != null) ''
|
2021-06-28 23:13:55 +00:00
|
|
|
GF_AUTH_GOOGLE_CLIENT_SECRET="$(<${escapeShellArg cfg.auth.google.clientSecretFile})"
|
|
|
|
export GF_AUTH_GOOGLE_CLIENT_SECRET
|
2021-05-20 23:08:51 +00:00
|
|
|
''}
|
2020-04-24 23:36:52 +00:00
|
|
|
${optionalString (cfg.database.passwordFile != null) ''
|
2021-06-28 23:13:55 +00:00
|
|
|
GF_DATABASE_PASSWORD="$(<${escapeShellArg cfg.database.passwordFile})"
|
|
|
|
export GF_DATABASE_PASSWORD
|
2020-04-24 23:36:52 +00:00
|
|
|
''}
|
|
|
|
${optionalString (cfg.security.adminPasswordFile != null) ''
|
2021-06-28 23:13:55 +00:00
|
|
|
GF_SECURITY_ADMIN_PASSWORD="$(<${escapeShellArg cfg.security.adminPasswordFile})"
|
|
|
|
export GF_SECURITY_ADMIN_PASSWORD
|
2020-04-24 23:36:52 +00:00
|
|
|
''}
|
|
|
|
${optionalString (cfg.security.secretKeyFile != null) ''
|
2021-06-28 23:13:55 +00:00
|
|
|
GF_SECURITY_SECRET_KEY="$(<${escapeShellArg cfg.security.secretKeyFile})"
|
|
|
|
export GF_SECURITY_SECRET_KEY
|
2020-04-24 23:36:52 +00:00
|
|
|
''}
|
|
|
|
${optionalString (cfg.smtp.passwordFile != null) ''
|
2021-06-28 23:13:55 +00:00
|
|
|
GF_SMTP_PASSWORD="$(<${escapeShellArg cfg.smtp.passwordFile})"
|
|
|
|
export GF_SMTP_PASSWORD
|
2020-04-24 23:36:52 +00:00
|
|
|
''}
|
|
|
|
${optionalString cfg.provision.enable ''
|
|
|
|
export GF_PATHS_PROVISIONING=${provisionConfDir};
|
|
|
|
''}
|
2020-05-15 21:57:56 +00:00
|
|
|
exec ${cfg.package}/bin/grafana-server -homepath ${cfg.dataDir}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
WorkingDirectory = cfg.dataDir;
|
|
|
|
User = "grafana";
|
2021-04-05 15:23:46 +00:00
|
|
|
RuntimeDirectory = "grafana";
|
|
|
|
RuntimeDirectoryMode = "0755";
|
2021-09-18 10:52:07 +00:00
|
|
|
# Hardening
|
2021-10-28 06:52:43 +00:00
|
|
|
AmbientCapabilities = lib.mkIf (cfg.port < 1024) [ "CAP_NET_BIND_SERVICE" ];
|
|
|
|
CapabilityBoundingSet = if (cfg.port < 1024) then [ "CAP_NET_BIND_SERVICE" ] else [ "" ];
|
2021-09-18 10:52:07 +00:00
|
|
|
DeviceAllow = [ "" ];
|
|
|
|
LockPersonality = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectSystem = "full";
|
|
|
|
RemoveIPC = true;
|
|
|
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
SystemCallArchitectures = "native";
|
2021-10-28 06:52:43 +00:00
|
|
|
# Upstream grafana is not setting SystemCallFilter for compatibility
|
|
|
|
# reasons, see https://github.com/grafana/grafana/pull/40176
|
2022-09-09 14:08:57 +00:00
|
|
|
SystemCallFilter = [ "@system-service" "~@privileged" ];
|
2021-09-18 10:52:07 +00:00
|
|
|
UMask = "0027";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
preStart = ''
|
|
|
|
ln -fs ${cfg.package}/share/grafana/conf ${cfg.dataDir}
|
|
|
|
ln -fs ${cfg.package}/share/grafana/tools ${cfg.dataDir}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.grafana = {
|
|
|
|
uid = config.ids.uids.grafana;
|
|
|
|
description = "Grafana user";
|
|
|
|
home = cfg.dataDir;
|
|
|
|
createHome = true;
|
|
|
|
group = "grafana";
|
|
|
|
};
|
|
|
|
users.groups.grafana = {};
|
|
|
|
};
|
|
|
|
}
|