-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.nix
117 lines (109 loc) · 3.28 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
{ 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.
'';
};
};
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_PROMETHEUS_URL = cfg.prometheusUrl;
WEBSITE_CONTENT_API_IXP_MANAGER_URL = cfg.ixpManagerUrl;
};
serviceConfig = {
ExecStart = "${pkgs.website-content-api}/bin/foundation";
DynamicUser = true;
Restart = "always";
};
};
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}/";
};
};
};
};
}