-
Notifications
You must be signed in to change notification settings - Fork 33
/
split.nix
102 lines (79 loc) · 2.29 KB
/
split.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
let
region = "us-west-1";
accessKeyId = "default";
in
{ machine = { config, pkgs, resources, ... }: {
deployment = {
targetEnv = "ec2";
ec2 = {
inherit accessKeyId region;
instanceType = "t2.nano";
keyPair = resources.ec2KeyPairs.my-key-pair;
securityGroups = [
resources.ec2SecurityGroups."http"
resources.ec2SecurityGroups."ssh"
];
};
};
networking.firewall.allowedTCPPorts = [ 80 ];
services.postgresql = {
enable = true;
authentication = ''
local all all ident map=mapping
'';
identMap = ''
mapping root postgres
mapping postgres postgres
'';
package = pkgs.postgresql_11;
initialScript = ./initialScript.sql;
};
systemd.services.simple-twitter = {
wantedBy = [ "multi-user.target" ];
after = [ "postgresql.service" ];
script =
let
ghc =
pkgs.haskellPackages.ghcWithPackages (pkgs: [
pkgs.blaze-html
pkgs.blaze-markup
pkgs.exceptions
pkgs.http-api-data
pkgs.optparse-generic
pkgs.postgresql-simple
pkgs.servant
pkgs.servant-blaze
pkgs.servant-server
pkgs.text
pkgs.transformers
pkgs.warp
]
);
code = ./Main.hs;
simple-twitter = pkgs.runCommand "simple-twitter" {} ''
${ghc}/bin/ghc -O -Wall -Werror ${code} -o $out
'';
in
''
${simple-twitter} --connectPort ${toString config.services.postgresql.port}
'';
};
};
resources = {
ec2KeyPairs.my-key-pair = { inherit region accessKeyId; };
ec2SecurityGroups = {
"http" = {
inherit accessKeyId region;
rules = [
{ fromPort = 80; toPort = 80; sourceIp = "0.0.0.0/0"; }
];
};
"ssh" = {
inherit accessKeyId region;
rules = [
{ fromPort = 22; toPort = 22; sourceIp = "0.0.0.0/0"; }
];
};
};
};
}