summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorJörg Thalheim <joerg@thalheim.io>2018-09-20 23:02:33 +0100
committerJörg Thalheim <joerg@thalheim.io>2018-09-20 23:06:10 +0100
commit9046673696ecca27faf3fb9f2986e2e535028e04 (patch)
tree49ec1725cfde60b6285f264fa6461bc5c78c7b1b /nixos
parent7eb9c348fb600ff7d0098628ea663ae80d8732a3 (diff)
downloadnixpkgs-9046673696ecca27faf3fb9f2986e2e535028e04.tar
nixpkgs-9046673696ecca27faf3fb9f2986e2e535028e04.tar.gz
nixpkgs-9046673696ecca27faf3fb9f2986e2e535028e04.tar.bz2
nixpkgs-9046673696ecca27faf3fb9f2986e2e535028e04.tar.lz
nixpkgs-9046673696ecca27faf3fb9f2986e2e535028e04.tar.xz
nixpkgs-9046673696ecca27faf3fb9f2986e2e535028e04.tar.zst
nixpkgs-9046673696ecca27faf3fb9f2986e2e535028e04.zip
nixos/grafana: option to configure smtp
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/monitoring/grafana.nix54
1 files changed, 52 insertions, 2 deletions
diff --git a/nixos/modules/services/monitoring/grafana.nix b/nixos/modules/services/monitoring/grafana.nix
index 1f7d67daba7..c0c16a429d8 100644
--- a/nixos/modules/services/monitoring/grafana.nix
+++ b/nixos/modules/services/monitoring/grafana.nix
@@ -4,6 +4,7 @@ with lib;
 
 let
   cfg = config.services.grafana;
+  opt = options.services.grafana;
 
   envOptions = {
     PATHS_DATA = cfg.dataDir;
@@ -41,6 +42,12 @@ let
     AUTH_ANONYMOUS_ORG_ROLE = cfg.auth.anonymous.org_role;
 
     ANALYTICS_REPORTING_ENABLED = boolToString cfg.analytics.reporting.enable;
+
+    SMTP_ENABLE = 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;
 
 in {
@@ -205,6 +212,41 @@ in {
       };
     };
 
+    smtp = {
+      enable = mkEnableOption "smtp";
+      host = mkOption {
+        description = "Host to connect to";
+        default = "localhost:25";
+        type = types.str;
+      };
+      user = mkOption {
+        description = "User used for authentication";
+        default = "";
+        type = types.str;
+      };
+      password = mkOption {
+        description = ''
+          Password used for authentication.
+          This option is mutual exclusive with the passwordFile option.
+        '';
+        default = "";
+        type = types.str;
+      };
+      passwordFile = mkOption {
+        description = ''
+          Password used for authentication.
+          This option is mutual exclusive with the password option.
+        '';
+        default = null;
+        type = types.nullOr types.path;
+      };
+      fromAddress = mkOption {
+        description = "Email address used for sending";
+        default = "admin@grafana.localhost";
+        type = types.str;
+      };
+    };
+
     users = {
       allowSignUp = mkOption {
         description = "Disable user signup / registration";
@@ -271,8 +313,8 @@ in {
 
   config = mkIf cfg.enable {
     warnings = optional (
-      cfg.database.password != options.services.grafana.database.password.default ||
-      cfg.security.adminPassword != options.services.grafana.security.adminPassword.default
+      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!";
 
     environment.systemPackages = [ cfg.package ];
@@ -290,6 +332,10 @@ in {
         assertion = cfg.security.secretKeyFile != opt.security.secretKeyFile.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 secretKeyFile";
+      }
     ];
 
     systemd.services.grafana = {
@@ -309,7 +355,11 @@ in {
         ${optionalString (cfg.security.secretKeyFile != null) ''
           export GF_SECURITY_SECRET_KEY="$(cat ${escapeShellArg cfg.security.secretKeyFile})"
         ''}
+        ${optionalString (cfg.smtp.passwordFile != null) ''
+          export GF_SMTP_PASSWORD="$(cat ${escapeShellArg cfg.smtp.passwordFile})"
+        ''}
         exec ${cfg.package.bin}/bin/grafana-server -homepath ${cfg.dataDir}
+      '';
       serviceConfig = {
         WorkingDirectory = cfg.dataDir;
         User = "grafana";