-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoenet.nix
More file actions
120 lines (97 loc) · 3.25 KB
/
Copy pathdoenet.nix
File metadata and controls
120 lines (97 loc) · 3.25 KB
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
{
network = {
description = "api.doenet.cloud";
};
defaults = {
imports = [ ./vultr.nix ];
};
################################################################
webserver = { config, pkgs, nodes, ... }:
let
# build the backend node app
theServer = pkgs.callPackage ../service/default.nix { yarn2nix = pkgs.yarn2nix-moretea; };
in {
deployment.targetHost = "45.77.159.207";
networking.privateIPv4 = "10.1.96.4";
networking.extraHosts = "${nodes.database.config.networking.privateIPv4} db";
environment.systemPackages = with pkgs; [
mongodb redis theServer
];
services.nginx = {
enable = true;
# Use recommended settings
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
};
services.nginx.virtualHosts."api.doenet.cloud" = {
forceSSL = true;
enableACME = true;
default = true;
root = "/var/www/api.doenet.cloud";
locations = {
"/".proxyPass = "http://localhost:${config.systemd.services.node.environment.PORT}";
"=/iframe.js" = {
root = "${theServer}/dist/";
extraConfig = ''
etag off;
add_header etag "\"${builtins.substring 11 32 theServer.outPath}\"";
'';
};
};
};
security.acme.certs = {
"api.doenet.cloud".email = "fowler@doenet.org";
};
systemd.services.node = {
description = "node service";
after = [ "network.target" ];
wantedBy = [ "default.target" ];
environment = {
PORT = "4000";
NODE_ENV = "production";
SECRET = builtins.readFile ./secret.key;
MONGODB_DATABASE = "lrs";
MONGODB_USER = "lrs";
MONGODB_PASS = nodes.database.config.services.mongodb.initialRootPassword;
MONGODB_HOST = nodes.database.config.services.mongodb.bind_ip;
MONGODB_PORT = toString 27017;
REDIS_HOST = nodes.database.config.services.redis.bind;
REDIS_PORT = toString nodes.database.config.services.redis.port;
REDIS_PASS = nodes.database.config.services.redis.requirePass;
LOGGLY_TOKEN = builtins.readFile ./loggly.key;
LOGGLY_SUBDOMAIN = "doenet";
};
serviceConfig = {
ExecStart = "${theServer}/bin/doenet-service";
User = "doenet";
Restart = "always";
};
};
# for "security" do not run the node app as root
users.extraUsers = {
doenet = { };
};
networking.firewall.allowedTCPPorts = [ 80 443 ];
};
################################################################
database = { config, pkgs, ... }:
{
deployment.targetHost = "149.28.42.92";
networking.privateIPv4 = "10.1.96.3";
services.redis = {
enable = true;
bind = config.networking.privateIPv4;
port = 6379;
requirePass = builtins.readFile ./redis.key;
};
services.mongodb = {
enable = true;
bind_ip = config.networking.privateIPv4;
enableAuth = true;
initialRootPassword = builtins.readFile ./mongodb.key;
};
networking.firewall.interfaces.ens7.allowedTCPPorts = [ config.services.redis.port 27017 ];
};
}