-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathross.nix
113 lines (95 loc) · 3.26 KB
/
ross.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
let
awsKeyId = "AKIAI6QCDKDFAZFL5D5A"; # for [email protected]
region = "us-east-2"; # for Ohio
pkgs = import <nixpkgs> {};
in
{
network.description = "api.rossprogram.org";
resources.ec2KeyPairs.myKeyPair = {
accessKeyId = awsKeyId;
inherit region;
};
resources.ec2SecurityGroups.openPorts = { resources, ... }: {
accessKeyId = awsKeyId;
inherit region;
rules = [
{ toPort = 22; fromPort = 22; sourceIp = "0.0.0.0/0"; } # SSH
{ toPort = 80; fromPort = 80; sourceIp = "0.0.0.0/0"; } # HTTP
{ toPort = 443; fromPort = 443; sourceIp = "0.0.0.0/0"; } # HTTPS
];
};
api = { resources, config, nodes, ... }:
let
# build the backend node app
theServer = pkgs.callPackage ../backend/default.nix { yarn2nix = pkgs.yarn2nix-moretea; };
in {
# Cloud provider settings; here for AWS
deployment.targetEnv = "ec2";
deployment.ec2.accessKeyId = awsKeyId;
deployment.ec2.region = region;
deployment.ec2.instanceType = "t2.micro"; # a cheap one
deployment.ec2.ebsInitialRootDiskSize = 30; # GB
deployment.ec2.keyPair = resources.ec2KeyPairs.myKeyPair;
deployment.ec2.associatePublicIpAddress = true;
deployment.ec2.securityGroups = [ resources.ec2SecurityGroups.openPorts.name ];
nixpkgs.config.allowUnfree = true;
environment.systemPackages = with pkgs; [
pkgs.mongodb theServer
];
services.mongodb.enable = true;
services.nginx = {
enable = true;
# Use recommended settings
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
};
services.nginx.virtualHosts."api.rossprogram.org" = {
forceSSL = true;
enableACME = true;
default = true;
root = "/var/www/api.rossprogram.org";
locations = {
"/".proxyPass = "http://localhost:${config.systemd.services.node.environment.PORT}/";
};
};
security.acme.acceptTerms = true;
security.acme.certs = {
"api.rossprogram.org".email = "[email protected]";
};
systemd.services.node = {
description = "node service";
after = [ "network.target" ];
wantedBy = [ "default.target" ];
environment = {
PORT = "4000";
NODE_ENV = "production";
SECRET = builtins.readFile ./secret.key;
API_BASE = "https://api.rossprogram.org/";
SMTP_HOST = "email-smtp.us-east-1.amazonaws.com";
SMTP_PORT = "465";
SMTP_USER = "AKIAY4INV4Z4X3M2DKRS";
SMTP_PASS = builtins.readFile ./smtp.key;
STRIPE_SECRET = builtins.readFile ./stripe.key;
STRIPE_PUBLIC = "pk_live_EVv0HE4EnEnGBfjY2iBzPnuS003Q0UNubO";
STRIPE_ENDPOINT_SECRET=builtins.readFile ./stripe-endpoint.key;
MONGODB_DATABASE = "ross";
MONGODB_PORT = toString 27017;
MONGODB_HOST = "127.0.0.1";
};
serviceConfig = {
ExecStart = "${theServer}/bin/rossprogram-api";
User = "ross";
Restart = "always";
};
};
# for "security" do not run the node app as root
users.extraUsers = {
ross = {
isNormalUser = true;
};
};
networking.firewall.allowedTCPPorts = [ 80 443 ];
};
}