Setup mail server and restructure some things
This commit is contained in:
		
					parent
					
						
							
								fa3db3bad6
							
						
					
				
			
			
				commit
				
					
						4a802ab44d
					
				
			
		
					 90 changed files with 512 additions and 66 deletions
				
			
		
							
								
								
									
										17
									
								
								config/hosts/metrics/configuration.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								config/hosts/metrics/configuration.nix
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
{ ... }:
 | 
			
		||||
{
 | 
			
		||||
  boot.loader.grub = {
 | 
			
		||||
    enable = true;
 | 
			
		||||
    device = "/dev/vda";
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  networking = {
 | 
			
		||||
    hostName = "metrics";
 | 
			
		||||
    firewall = {
 | 
			
		||||
      enable = true;
 | 
			
		||||
      allowedTCPPorts = [ 80 443 ];
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  system.stateVersion = "23.05";
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								config/hosts/metrics/default.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								config/hosts/metrics/default.nix
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
{ ... }:
 | 
			
		||||
{
 | 
			
		||||
  imports = [
 | 
			
		||||
    ./configuration.nix
 | 
			
		||||
    ./grafana.nix
 | 
			
		||||
    ./prometheus.nix
 | 
			
		||||
    ./nginx.nix
 | 
			
		||||
  ];
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										36
									
								
								config/hosts/metrics/grafana.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								config/hosts/metrics/grafana.nix
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,36 @@
 | 
			
		|||
{ config, ... }:
 | 
			
		||||
{
 | 
			
		||||
  services.grafana = {
 | 
			
		||||
    enable = true;
 | 
			
		||||
    settings = {
 | 
			
		||||
      server = {
 | 
			
		||||
        domain = "grafana.grzb.de";
 | 
			
		||||
        root_url = "https://${config.services.grafana.settings.server.domain}";
 | 
			
		||||
      };
 | 
			
		||||
      security = {
 | 
			
		||||
        cookie_secure = true;
 | 
			
		||||
        cookie_samesite = "strict";
 | 
			
		||||
        admin_user = "yuri";
 | 
			
		||||
        admin_password = "$__file{/secrets/metrics-grafana-admin-password.secret}";
 | 
			
		||||
        admin_email = "yuri@nekover.se";
 | 
			
		||||
      };
 | 
			
		||||
      smtp = {
 | 
			
		||||
        enabled = true;
 | 
			
		||||
        host = "mail.grzb.de:465";
 | 
			
		||||
        user = "grafana";
 | 
			
		||||
        password = "$__file{/secrets/metrics-grafana-smtp-password.secret}";
 | 
			
		||||
        from_address = "grafana@robot.grzb.de";
 | 
			
		||||
        from_name = "Grafana";
 | 
			
		||||
        startTLS_policy = "NoStartTLS";
 | 
			
		||||
      };
 | 
			
		||||
    };
 | 
			
		||||
    provision.datasources.settings.datasources = [
 | 
			
		||||
      {
 | 
			
		||||
        name = "Prometheus";
 | 
			
		||||
        type = "prometheus";
 | 
			
		||||
        url = "http://localhost:${builtins.toString config.services.prometheus.port}";
 | 
			
		||||
        isDefault = true;
 | 
			
		||||
      }
 | 
			
		||||
    ];
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										27
									
								
								config/hosts/metrics/nginx.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								config/hosts/metrics/nginx.nix
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,27 @@
 | 
			
		|||
{ config, ... }:
 | 
			
		||||
{
 | 
			
		||||
  services.nginx = {
 | 
			
		||||
    enable = true;
 | 
			
		||||
    virtualHosts = {
 | 
			
		||||
      ${config.services.grafana.settings.server.domain} = {
 | 
			
		||||
        forceSSL = true;
 | 
			
		||||
        enableACME = true;
 | 
			
		||||
        listen = [
 | 
			
		||||
          {
 | 
			
		||||
            addr = "0.0.0.0";
 | 
			
		||||
            port = 80;
 | 
			
		||||
          }
 | 
			
		||||
          {
 | 
			
		||||
            addr = "0.0.0.0";
 | 
			
		||||
            port = 443;
 | 
			
		||||
            ssl = true;
 | 
			
		||||
          }
 | 
			
		||||
        ];
 | 
			
		||||
        locations."/" = {
 | 
			
		||||
          proxyPass = "http://${config.services.grafana.settings.server.http_addr}:${builtins.toString config.services.grafana.settings.server.http_port}";
 | 
			
		||||
          proxyWebsockets = true;
 | 
			
		||||
        };
 | 
			
		||||
      };
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								config/hosts/metrics/prometheus.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								config/hosts/metrics/prometheus.nix
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
{ hosts, ... }:
 | 
			
		||||
{
 | 
			
		||||
  services.prometheus = {
 | 
			
		||||
    enable = true;
 | 
			
		||||
    scrapeConfigs = [
 | 
			
		||||
      {
 | 
			
		||||
        job_name = "node";
 | 
			
		||||
        static_configs = builtins.map (name: {
 | 
			
		||||
          targets = [
 | 
			
		||||
            "${name}.${hosts.${name}.site}.grzb.de:9100"
 | 
			
		||||
          ];
 | 
			
		||||
          labels = {
 | 
			
		||||
            host = "${name}.${hosts.${name}.site}.grzb.de";
 | 
			
		||||
          };
 | 
			
		||||
        }) (builtins.attrNames hosts);
 | 
			
		||||
      }
 | 
			
		||||
    ];
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								config/hosts/metrics/secrets.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								config/hosts/metrics/secrets.nix
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
{ ... }:
 | 
			
		||||
{
 | 
			
		||||
  deployment.keys."metrics-grafana-admin-password.secret" = {
 | 
			
		||||
    keyCommand = [ "env" "GNUPGHOME=/home/yuri/.passinfra_gnupg" "PASSWORD_STORE_DIR=/home/yuri/pass/infra" "pass" "metrics/grafana/admin-password" ];
 | 
			
		||||
    destDir = "/secrets";
 | 
			
		||||
    user = "grafana";
 | 
			
		||||
    group = "grafana";
 | 
			
		||||
    permissions = "0640";
 | 
			
		||||
    uploadAt = "pre-activation";
 | 
			
		||||
  };
 | 
			
		||||
  deployment.keys."metrics-grafana-smtp-password.secret" = {
 | 
			
		||||
    keyCommand = [ "env" "GNUPGHOME=/home/yuri/.passinfra_gnupg" "PASSWORD_STORE_DIR=/home/yuri/pass/infra" "pass" "metrics/grafana/smtp-password" ];
 | 
			
		||||
    destDir = "/secrets";
 | 
			
		||||
    user = "grafana";
 | 
			
		||||
    group = "grafana";
 | 
			
		||||
    permissions = "0640";
 | 
			
		||||
    uploadAt = "pre-activation";
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue