]>
Commit | Line | Data |
---|---|---|
1 | { config, pkgs, lib, name, ... }: | |
2 | { | |
3 | options = { | |
4 | myServices.status = { | |
5 | enable = lib.mkOption { | |
6 | type = lib.types.bool; | |
7 | default = false; | |
8 | description = '' | |
9 | Whether to enable status app. | |
10 | ''; | |
11 | }; | |
12 | }; | |
13 | }; | |
14 | config = lib.mkIf config.myServices.status.enable { | |
15 | secrets.keys = [ | |
16 | { | |
17 | dest = "naemon-status/environment"; | |
18 | user = "naemon"; | |
19 | group = "naemon"; | |
20 | permission = "0400"; | |
21 | text = '' | |
22 | TOKENS=${builtins.concatStringsSep " " config.myEnv.monitoring.nrdp_tokens} | |
23 | ''; | |
24 | } | |
25 | ]; | |
26 | services.nginx = { | |
27 | enable = true; | |
28 | recommendedOptimisation = true; | |
29 | recommendedGzipSettings = true; | |
30 | recommendedProxySettings = true; | |
31 | upstreams."netdata".servers = { "127.0.0.1:19999" = {}; }; | |
32 | upstreams."netdata".extraConfig = '' | |
33 | keepalive 64; | |
34 | ''; | |
35 | virtualHosts."status.eban.bzh" = { | |
36 | acmeRoot = config.myServices.certificates.webroot; | |
37 | useACMEHost = name; | |
38 | forceSSL = true; | |
39 | locations."/".proxyPass = "http://unix:/run/naemon-status/socket.sock:/"; | |
40 | }; | |
41 | virtualHosts."status.immae.eu" = { | |
42 | acmeRoot = config.myServices.certificates.webroot; | |
43 | useACMEHost = name; | |
44 | forceSSL = true; | |
45 | locations."/".proxyPass = "http://unix:/run/naemon-status/socket.sock:/"; | |
46 | ||
47 | locations."= /netdata".return = "301 /netdata/"; | |
48 | locations."~ /netdata/(?<ndpath>.*)".extraConfig = '' | |
49 | proxy_redirect off; | |
50 | proxy_set_header Host $host; | |
51 | ||
52 | proxy_set_header X-Forwarded-Host $host; | |
53 | proxy_set_header X-Forwarded-Server $host; | |
54 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
55 | proxy_http_version 1.1; | |
56 | proxy_pass_request_headers on; | |
57 | proxy_set_header Connection "keep-alive"; | |
58 | proxy_store off; | |
59 | proxy_pass http://netdata/$ndpath$is_args$args; | |
60 | ||
61 | gzip on; | |
62 | gzip_proxied any; | |
63 | gzip_types *; | |
64 | ''; | |
65 | }; | |
66 | }; | |
67 | security.acme.certs."${name}" = { | |
68 | extraDomains."status.immae.eu" = null; | |
69 | extraDomains."status.eban.bzh" = null; | |
70 | user = config.services.nginx.user; | |
71 | group = config.services.nginx.group; | |
72 | }; | |
73 | ||
74 | myServices.certificates.enable = true; | |
75 | networking.firewall.allowedTCPPorts = [ 80 443 ]; | |
76 | systemd.services.naemon-status = { | |
77 | description = "Naemon status"; | |
78 | after = [ "network.target" ]; | |
79 | wantedBy = [ "multi-user.target" ]; | |
80 | ||
81 | serviceConfig = { | |
82 | EnvironmentFile = config.secrets.fullPaths."naemon-status/environment"; | |
83 | Type = "simple"; | |
84 | WorkingDirectory = "${./status}"; | |
85 | ExecStart = let | |
86 | python = pkgs.python3.withPackages (p: [ p.gunicorn p.flask p.flask_login ]); | |
87 | in | |
88 | "${python}/bin/gunicorn -w4 --bind unix:/run/naemon-status/socket.sock app:app"; | |
89 | User = "naemon"; | |
90 | RuntimeDirectory = "naemon-status"; | |
91 | StandardOutput = "journal"; | |
92 | StandardError = "inherit"; | |
93 | }; | |
94 | }; | |
95 | }; | |
96 | } |