-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.nix
158 lines (150 loc) · 4.56 KB
/
module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
{ pkgs, config, lib, ... }:
let
cfg = config.dd-ix.website-content-api;
in
{
options.dd-ix.website-content-api = {
enable = lib.mkEnableOption "website-content-api";
package = lib.mkPackageOption pkgs "website-content-api" { };
content = lib.mkPackageOption pkgs "website-content" { };
domain = lib.mkOption {
type = lib.types.str;
description = "The domain the frontend should be served.";
};
http = {
host = lib.mkOption {
type = lib.types.str;
default = "http://127.0.0.1";
description = ''
To which IP website-content-api should bind.
'';
};
port = lib.mkOption {
type = lib.types.port;
default = 8080;
description = ''
To which port should website-content-api bind.
'';
};
};
listmonk = {
host = lib.mkOption {
type = lib.types.str;
default = "http://127.0.0.1";
description = ''
At which host is listmonk listening
'';
};
port = lib.mkOption {
type = lib.types.port;
default = 8081;
description = ''
At which port is listmonk listening
'';
};
user = lib.mkOption {
type = lib.types.str;
default = "admin";
description = ''
username of listmonk user
'';
};
passwordFile = lib.mkOption {
type = lib.types.path;
description = ''
path from where the user password can be read
'';
};
allowed_lists = lib.mkOption {
type = lib.types.listOf lib.types.int;
default = [ ];
description = ''
list of allowed mailing list ids
'';
};
};
logLevel = lib.mkOption {
type = lib.types.str;
default = "info";
description = ''log level of the application'';
};
url = lib.mkOption {
type = lib.types.str;
description = ''under which domain website-content-api serves its content'';
};
prometheusUrl = lib.mkOption {
type = lib.types.str;
description = ''base url of prometheus'';
};
ixpManagerUrl = lib.mkOption {
type = lib.types.str;
description = ''base url of ixp manager'';
};
};
config = lib.mkIf cfg.enable {
systemd.services.website-content-api = {
enable = true;
wantedBy = [ "multi-user.target" ];
environment = {
RUST_LOG = cfg.logLevel;
RUST_BACKTRACE = if (cfg.logLevel == "info") then "0" else "1";
WEBSITE_CONTENT_API_LISTEN_ADDR = "${cfg.http.host}:${toString cfg.http.port}";
WEBSITE_CONTENT_API_CONTENT_DIRECTORY = "${pkgs.website-content}/content/";
WEBSITE_CONTENT_API_BASE_URL = cfg.url;
WEBSITE_CONTENT_API_LISTMONK_URL = "${cfg.listmonk.host}:${toString cfg.listmonk.port}";
WEBSITE_CONTENT_API_LISTMONK_USER = cfg.listmonk.user;
WEBSITE_CONTENT_API_LISTMONK_PASSWORD_FILE = "%d/listmonk_pw";
WEBSITE_CONTENT_API_LISTMONK_LISTS = "${builtins.toJSON cfg.listmonk.allowed_lists}";
WEBSITE_CONTENT_API_PROMETHEUS_URL = cfg.prometheusUrl;
WEBSITE_CONTENT_API_IXP_MANAGER_URL = cfg.ixpManagerUrl;
};
serviceConfig = {
ExecStart = "${pkgs.website-content-api}/bin/foundation";
DynamicUser = true;
Restart = "always";
LoadCredential = "listmonk_pw:${cfg.listmonk.passwordFile}";
};
};
services.nginx = {
enable = true;
virtualHosts."${cfg.domain}".locations = {
"/text-blocks/assets/" = {
alias = "${cfg.content}/content/text_blocks/assets/";
tryFiles = "$uri $uri/ =404";
extraConfig = ''
expires max;
access_log off;
'';
};
"/blog/assets/" = {
alias = "${cfg.content}/content/blog/assets/";
tryFiles = "$uri $uri/ =404";
extraConfig = ''
expires max;
access_log off;
'';
};
"/event/assets/" = {
alias = "${cfg.content}/content/event/assets/";
tryFiles = "$uri $uri/ =404";
extraConfig = ''
expires max;
access_log off;
'';
};
"/team/assets/" = {
alias = "${cfg.content}/content/team/assets/";
tryFiles = "$uri $uri/ =404";
extraConfig = ''
expires max;
access_log off;
'';
};
"/" = {
recommendedProxySettings = true;
proxyPass = "http://${cfg.http.host}:${toString cfg.http.port}/";
};
};
};
};
}