git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/grafana: option to configure smtp
commit9046673696ecca27faf3fb9f2986e2e535028e04 authorJörg Thalheim <joerg@thalheim.io> dateThu 20 Sep 2018, 23:02 (8 years ago) parent7eb9c34
1 file changed+52−2
nixos/modules/services/monitoring/grafana.nix+52−2
nixos/modules/services/monitoring/grafana.nix+52−2
@@ -4,6 +4,7 @@ with lib;
44
55let
66 cfg = config.services.grafana;
7+ opt = options.services.grafana;
78
89 envOptions = {
910 PATHS_DATA = cfg.dataDir;
@@ -41,6 +42,12 @@ let
4142 AUTH_ANONYMOUS_ORG_ROLE = cfg.auth.anonymous.org_role;
4243
4344 ANALYTICS_REPORTING_ENABLED = boolToString cfg.analytics.reporting.enable;
45+
46+ SMTP_ENABLE = boolToString cfg.smtp.enable;
47+ SMTP_HOST = cfg.smtp.host;
48+ SMTP_USER = cfg.smtp.user;
49+ SMTP_PASSWORD = cfg.smtp.password;
50+ SMTP_FROM_ADDRESS = cfg.smtp.fromAddress;
4451 } // cfg.extraOptions;
4552
4653in {
@@ -205,6 +212,41 @@ in {
205212 };
206213 };
207214
215+ smtp = {
216+ enable = mkEnableOption "smtp";
217+ host = mkOption {
218+ description = "Host to connect to";
219+ default = "localhost:25";
220+ type = types.str;
221+ };
222+ user = mkOption {
223+ description = "User used for authentication";
224+ default = "";
225+ type = types.str;
226+ };
227+ password = mkOption {
228+ description = ''
229+ Password used for authentication.
230+ This option is mutual exclusive with the passwordFile option.
231+ '';
232+ default = "";
233+ type = types.str;
234+ };
235+ passwordFile = mkOption {
236+ description = ''
237+ Password used for authentication.
238+ This option is mutual exclusive with the password option.
239+ '';
240+ default = null;
241+ type = types.nullOr types.path;
242+ };
243+ fromAddress = mkOption {
244+ description = "Email address used for sending";
245+ default = "admin@grafana.localhost";
246+ type = types.str;
247+ };
248+ };
249+
208250 users = {
209251 allowSignUp = mkOption {
210252 description = "Disable user signup / registration";
@@ -271,8 +313,8 @@ in {
271313
272314 config = mkIf cfg.enable {
273315 warnings = optional (
274− cfg.database.password != options.services.grafana.database.password.default ||
275− cfg.security.adminPassword != options.services.grafana.security.adminPassword.default
316+ cfg.database.password != opt.database.password.default ||
317+ cfg.security.adminPassword != opt.security.adminPassword.default
276318 ) "Grafana passwords will be stored as plaintext in the Nix store!";
277319
278320 environment.systemPackages = [ cfg.package ];
@@ -290,6 +332,10 @@ in {
290332 assertion = cfg.security.secretKeyFile != opt.security.secretKeyFile.default -> cfg.security.secretKeyFile == null;
291333 message = "Cannot set both secretKey and secretKeyFile";
292334 }
335+ {
336+ assertion = cfg.smtp.password != opt.smtp.password.default -> cfg.smtp.passwordFile == null;
337+ message = "Cannot set both password and secretKeyFile";
338+ }
293339 ];
294340
295341 systemd.services.grafana = {
@@ -309,7 +355,11 @@ in {
309355 ${optionalString (cfg.security.secretKeyFile != null) ''
310356 export GF_SECURITY_SECRET_KEY="$(cat ${escapeShellArg cfg.security.secretKeyFile})"
311357 ''}
358+ ${optionalString (cfg.smtp.passwordFile != null) ''
359+ export GF_SMTP_PASSWORD="$(cat ${escapeShellArg cfg.smtp.passwordFile})"
360+ ''}
312361 exec ${cfg.package.bin}/bin/grafana-server -homepath ${cfg.dataDir}
362+ '';
313363 serviceConfig = {
314364 WorkingDirectory = cfg.dataDir;
315365 User = "grafana";