-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
269 lines (248 loc) · 14 KB
/
flake.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
{
description = "env";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
composable-vm.url = "github:ComposableFi/composable-vm";
composable-nix.url = "github:ComposableFi/nix";
composable-networks.url = "github:ComposableFi/networks";
cosmos = {
url = "github:informalsystems/cosmos.nix/dz/38";
};
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs @ {
flake-parts,
composable-networks,
composable-nix,
composable-vm,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
./args.nix
];
systems = ["x86_64-linux" "aarch64-linux"];
perSystem = {
config,
self',
inputs',
pkgs,
system,
buildInputs,
runtimeInputs,
...
}: let
networks = pkgs.networksLib.networks;
bootstrap-config-module = {
system.stateVersion = "23.05";
services.openssh.enable = true;
environment.systemPackages = [];
users.users.root.openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO/PGg+j/Y5gP/e7zyMCyK+f0YfImZgKZ3IUUWmkoGtT dz@pop-os" # dzmitry-lahoda
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDNY+BfeToEN1+1HTSggNrFHYhYFl9H9dPgIJy558OgWHsYrhMA7PHUy3VK0DjnIT9jFU1PF3/v1tpgUij9bOm6Md6N7Dn2/XL6/FqPNJ9i408V6DdCmH65aJ2tnSJJ4aicD9P39MHVG6tYPKJX9BrHiGzLPLi+c/4CWXIcj/u4aAuvspfCu6a5jWPj03XBwUUbkmdgyvEJ7wJoiOKE1b/Ilxiithau7w0GgHG3e1RUMeVy4aaNET3sTlhiJf4k+cL+7MIM13wUiqjglyzBfMGQKPsaHFuMMsfK4lHploLkBZeopiIxyRzQeRODFsuUSR+J/oL7TiIyMALCEqErRb8OrmPI7NKYRqokfU20YTgOSW+t7JxCx5vtYHyw2HVMZTnSeHAFfcclBh1Vi4vqHymNhJXEh35k/iLdUNdcMgHyqmjZZecpAT3fIULOlGfyfc6kKFmfAYWFcci+ByE0e0T82BlLWJHBuQTByu2w+IzUA81uKBqBqNgLayi49Bpwg5k= dz@pop-os
" # dzmitry-lahoda
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAsGO0KDHzP5swgMDDqCOo7siBoEvKnyAAXcI7CKhBHg dz@pop-os" # GH actions of env
];
};
# run by 3rd party
mantis-solver = ''
${builtins.readFile ./setup_secrets.sh}
RUST_BACKTRACE=full RUST_LOG="trace,rustls=warn,reqwest=warn" ${composable-vm.packages.${system}.mantis}/bin/mantis solve --rpc-centauri "${networks.pica.mainnet.RPC}" --grpc-centauri "${networks.pica.mainnet.GRPC}" --cvm-contract "centauri19dw7w5cm48aeqwszva8kxmnfnft7wp4xt4s73ksyhdya704r3cdq389szq" --wallet "$MANTIS_COSMOS_MNEMONIC" --order-contract="centauri1f0a8md6ukrgmpyrpjv9pm5x9d4wx7mumcdr3qjc8mlguqssjy7xq4eennk" --main-chain-id="${networks.pica.mainnet.CHAIN_ID}" --router="http://ec2-54-246-72-76.eu-west-1.compute.amazonaws.com:8000" --gas="2000000000" | tee /var/log/mantis.log
'';
mantis-solver-simulator = ''
${builtins.readFile ./setup_secrets.sh}
RUST_BACKTRACE=1 RUST_LOG="trace,rustls=warn,reqwest=warn" ${composable-vm.packages.${system}.mantis}/bin/mantis simulate --rpc-centauri "${networks.pica.mainnet.RPC}" --grpc-centauri "${networks.pica.mainnet.GRPC}" --order-contract="centauri1f0a8md6ukrgmpyrpjv9pm5x9d4wx7mumcdr3qjc8mlguqssjy7xq4eennk" --wallet "$MANTIS_COSMOS_MNEMONIC" --cvm-contract "centauri19dw7w5cm48aeqwszva8kxmnfnft7wp4xt4s73ksyhdya704r3cdq389szq" --main-chain-id="${networks.pica.mainnet.CHAIN_ID}" --coins="20000000000ppica,10000ibc/47BD209179859CDE4A2806763D7189B6E6FE13A17880FE2B42DE1E6C1E329E23" --coins="10000ibc/B063BCBCD45084893C9889EBE472D666F7E6F56300897DCECDFD7EB88C3E8609,10000ibc/47BD209179859CDE4A2806763D7189B6E6FE13A17880FE2B42DE1E6C1E329E23" | tee /var/log/mantis.log
'';
# --coins="10000ibc/247DEF7C0E022DC3FAF5EB13A38C616252B5B85651803E03710CCBD581673C87,10000ibc/47BD209179859CDE4A2806763D7189B6E6FE13A17880FE2B42DE1E6C1E329E23" --coins="1000ibc/F34DC2408B2EB193D2A82388AC5F9AC86282B14BBF623A8581BBE075654547CD,10000ibc/47BD209179859CDE4A2806763D7189B6E6FE13A17880FE2B42DE1E6C1E329E23"
# --coins="3571632929589ibc/F472078E60F4AA887DA65A6009E501882594AAA5721C3C13F54724E6B29F1718,10000ibc/47BD209179859CDE4A2806763D7189B6E6FE13A17880FE2B42DE1E6C1E329E23" --coins="100000ibc/4472060867B1527ECE6456D82B463A536EAF4ABC57E0099FF5302F4C93D8C65E,10000ibc/47BD209179859CDE4A2806763D7189B6E6FE13A17880FE2B42DE1E6C1E329E23" --coins="10000ibc/B063BCBCD45084893C9889EBE472D666F7E6F56300897DCECDFD7EB88C3E8609,10000ibc/47BD209179859CDE4A2806763D7189B6E6FE13A17880FE2B42DE1E6C1E329E23" --coins="10000ibc/C727DE941C39B6A780B10FF3B3CD72B7DAFAF625C2902433C3CD5A672B33A94B,10000ibc/47BD209179859CDE4A2806763D7189B6E6FE13A17880FE2B42DE1E6C1E329E23" --coins="10000ibc/247DEF7C0E022DC3FAF5EB13A38C616252B5B85651803E03710CCBD581673C87,10000ibc/B063BCBCD45084893C9889EBE472D666F7E6F56300897DCECDFD7EB88C3E8609" --coins="1000ibc/F34DC2408B2EB193D2A82388AC5F9AC86282B14BBF623A8581BBE075654547CD,10000ibc/B063BCBCD45084893C9889EBE472D666F7E6F56300897DCECDFD7EB88C3E8609" --coins="10000ibc/,10000ibc/B063BCBCD45084893C9889EBE472D666F7E6F56300897DCECDFD7EB88C3E8609" --coins="3571632929589ibc/F472078E60F4AA887DA65A6009E501882594AAA5721C3C13F54724E6B29F1718,10000ibc/B063BCBCD45084893C9889EBE472D666F7E6F56300897DCECDFD7EB88C3E8609" --coins="100000ibc/4472060867B1527ECE6456D82B463A536EAF4ABC57E0099FF5302F4C93D8C65E,10000ibc/B063BCBCD45084893C9889EBE472D666F7E6F56300897DCECDFD7EB88C3E8609" --coins="10000ibc/C727DE941C39B6A780B10FF3B3CD72B7DAFAF625C2902433C3CD5A672B33A94B,10000ibc/B063BCBCD45084893C9889EBE472D666F7E6F56300897DCECDFD7EB88C3E8609" --coins="10000ibc/B063BCBCD45084893C9889EBE472D666F7E6F56300897DCECDFD7EB88C3E8609,10000ibc/247DEF7C0E022DC3FAF5EB13A38C616252B5B85651803E03710CCBD581673C87" --coins="1000ibc/F34DC2408B2EB193D2A82388AC5F9AC86282B14BBF623A8581BBE075654547CD,10000ibc/247DEF7C0E022DC3FAF5EB13A38C616252B5B85651803E03710CCBD581673C87" --coins="10000ibc/,10000ibc/247DEF7C0E022DC3FAF5EB13A38C616252B5B85651803E03710CCBD581673C87" --coins="3571632929589ibc/F472078E60F4AA887DA65A6009E501882594AAA5721C3C13F54724E6B29F1718,10000ibc/247DEF7C0E022DC3FAF5EB13A38C616252B5B85651803E03710CCBD581673C87" --coins="100000ibc/4472060867B1527ECE6456D82B463A536EAF4ABC57E0099FF5302F4C93D8C65E,10000ibc/247DEF7C0E022DC3FAF5EB13A38C616252B5B85651803E03710CCBD581673C87" --coins="10000ibc/C727DE941C39B6A780B10FF3B3CD72B7DAFAF625C2902433C3CD5A672B33A94B,10000ibc/247DEF7C0E022DC3FAF5EB13A38C616252B5B85651803E03710CCBD581673C87" --coins="10000ibc/B063BCBCD45084893C9889EBE472D666F7E6F56300897DCECDFD7EB88C3E8609,3571632929589ibc/F472078E60F4AA887DA65A6009E501882594AAA5721C3C13F54724E6B29F1718" --coins="10000ibc/247DEF7C0E022DC3FAF5EB13A38C616252B5B85651803E03710CCBD581673C87,3571632929589ibc/F472078E60F4AA887DA65A6009E501882594AAA5721C3C13F54724E6B29F1718" --coins="1000ibc/F34DC2408B2EB193D2A82388AC5F9AC86282B14BBF623A8581BBE075654547CD,3571632929589ibc/F472078E60F4AA887DA65A6009E501882594AAA5721C3C13F54724E6B29F1718" --coins="10000ibc/,3571632929589ibc/F472078E60F4AA887DA65A6009E501882594AAA5721C3C13F54724E6B29F1718" --coins="100000ibc/4472060867B1527ECE6456D82B463A536EAF4ABC57E0099FF5302F4C93D8C65E,3571632929589ibc/F472078E60F4AA887DA65A6009E501882594AAA5721C3C13F54724E6B29F1718" --coins="10000ibc/B063BCBCD45084893C9889EBE472D666F7E6F56300897DCECDFD7EB88C3E8609,3571632929589ibc/F472078E60F4AA887DA65A6009E501882594AAA5721C3C13F54724E6B29F1718" --coins="10000ibc/C727DE941C39B6A780B10FF3B3CD72B7DAFAF625C2902433C3CD5A672B33A94B,3571632929589ibc/F472078E60F4AA887DA65A6009E501882594AAA5721C3C13F54724E6B29F1718"
# run by 3rd party
mantis-blackbox-script = ''
export CVM_ADDRESS='osmo15rquxg3zw8tcgj82hkz2qzy4f69nzzt5yl2qlgqkw6l9drlhfvcsr2yc8y'
RUST_BACKTRACE=1 RUST_LOG="trace,rustls=warn,reqwest=warn" ${composable-vm.packages.${system}.mantis-blackbox}/bin/mantis-blackbox | tee /var/log/blackbox.log
'';
mkLiveConfigModule = script: {
networking.firewall.enable = true;
networking.firewall.allowedTCPPorts = [80 22 443 22290];
environment.systemPackages = [
composable-vm.packages.${system}.mantis
composable-vm.packages.${system}.mantis-blackbox
pkgs.procps
];
systemd.services = {
mantis = {
enable = true;
wantedBy = ["multi-user.target"];
after = ["network.target"];
inherit script;
unitConfig = {
StartLimitIntervalSec = 0;
StartLimitBurst = 2147483647;
};
serviceConfig = {
Restart = "always";
Type = "simple";
RestartSec = 12;
};
};
};
};
nixos-config-mantis-blackbox =
(inputs.nixpkgs.lib.nixosSystem {
inherit system;
modules = [
bootstrap-config-module
{
networking.firewall.enable = true;
networking.firewall.allowedTCPPorts = [80 22 443 22290 8000];
environment.systemPackages = [composable-vm.packages.${system}.mantis-blackbox];
systemd.services.mantis = {
enable = true;
wantedBy = ["multi-user.target"];
after = ["network.target"];
script = mantis-blackbox-script;
unitConfig = {
StartLimitIntervalSec = 0;
StartLimitBurst = 2147483647;
};
serviceConfig = {
Restart = "always";
Type = "simple";
};
};
}
"${inputs.nixpkgs}/nixos/modules/virtualisation/amazon-image.nix"
];
})
.config
.system
.build
.toplevel;
mantis-vm = inputs.nixos-generators.nixosGenerate {
inherit pkgs;
format = "vm";
modules = [
bootstrap-config-module
{
services.getty.autologinUser = "root";
virtualisation.forwardPorts = [
{
from = "host";
host.port = 8000;
guest.port = 80;
}
];
}
(mkLiveConfigModule mantis-solver)
];
};
bootstrap-img-name = "nixos-bootstrap-${system}";
bootstrap-img = inputs.nixos-generators.nixosGenerate {
inherit pkgs;
format = "amazon";
modules = [
bootstrap-config-module
{amazonImage.name = bootstrap-img-name;}
];
};
nixos-config-mantis-solver =
(inputs.nixpkgs.lib.nixosSystem {
inherit system;
modules = [
bootstrap-config-module
(mkLiveConfigModule mantis-solver)
"${inputs.nixpkgs}/nixos/modules/virtualisation/amazon-image.nix"
];
})
.config
.system
.build
.toplevel;
nixos-config-mantis-solver-simulator =
(inputs.nixpkgs.lib.nixosSystem {
inherit system;
modules = [
bootstrap-config-module
(mkLiveConfigModule mantis-solver-simulator)
"${inputs.nixpkgs}/nixos/modules/virtualisation/amazon-image.nix"
];
})
.config
.system
.build
.toplevel;
bootstrap-img-path = "${bootstrap-img}/${bootstrap-img-name}.vhd";
deploy-shell = pkgs.mkShell {
packages = [pkgs.opentofu];
TF_VAR_bootstrap_img_path = bootstrap-img-path;
TF_VAR_MANTIS_SOLVER_CONFIG_PATH = "${nixos-config-mantis-solver}";
TF_VAR_MANTIS_SOLVER_SIMULATOR_CONFIG = "${nixos-config-mantis-solver-simulator}";
};
terraform = pkgs.writeShellApplication {
name = "terraform";
runtimeInputs = [pkgs.opentofu];
text = ''
if [ -f .env ]; then
# shellcheck disable=SC1091
source .env
fi
export TF_VAR_bootstrap_img_path="${bootstrap-img-path}"
export TF_VAR_MANTIS_SOLVER_CONFIG_PATH="${nixos-config-mantis-solver}"
export TF_VAR_MANTIS_SOLVER_SIMULATOR_CONFIG="${nixos-config-mantis-solver-simulator}"
export TF_VAR_MANTIS_BLACKBOX_CONFIG_PATH="${nixos-config-mantis-blackbox}"
export TF_VAR_AWS_REGION="eu-central-1"
# (
# cd terraform/github.com
# # shellcheck disable=SC2068
# tofu $@
# )
(
cd terraform/aws
# shellcheck disable=SC2068
tofu $@
)
'';
};
in rec {
formatter = pkgs.alejandra;
packages = {
inherit
mantis-vm
bootstrap-img
terraform
;
mantis-node-1 = pkgs.writeShellScriptBin "mantis-node-1" mantis-solver;
};
devShells.default = let
networks = pkgs.networksLib.networks;
sh = pkgs.networksLib.sh;
in
pkgs.mkShell {
TF_VAR_bootstrap_img_path = bootstrap-img-path;
TF_VAR_MANTIS_SOLVER_CONFIG_PATH = "${nixos-config-mantis-solver}";
buildInputs = runtimeInputs;
EXECUTOR_WASM_FILE = "${
pkgs.cw-cvm-executor
}/lib/cw_cvm_executor.wasm";
OUTPOST_WASM_FILE = "${
pkgs.cw-cvm-outpost
}/lib/cw_cvm_outpost.wasm";
ORDER_WASM_FILE = "${
pkgs.cw-mantis-order
}/lib/cw_mantis_order.wasm";
shellHook = ''
rm --force --recursive ~/.banksy
mkdir --parents ~/.banksy/config
echo 'keyring-backend = "os"' >> ~/.banksy/config/client.toml
echo 'output = "json"' >> ~/.banksy/config/client.toml
echo 'node = "${networks.pica.mainnet.NODE}"' >> ~/.banksy/config/client.toml
echo 'chain-id = "${networks.pica.mainnet.CHAIN_ID}"' >> ~/.banksy/config/client.toml
rm ~/.osmosisd/config/client.toml
osmosisd set-env mainnet
'';
};
};
};
}