forked from input-output-hk/jormungandr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
136 lines (123 loc) · 4.67 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
utils.url = "github:kreisys/flake-utils";
naersk.url = "github:nmattia/naersk";
naersk.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, utils, naersk }:
let
workspaceCargo = builtins.fromTOML (builtins.readFile ./Cargo.toml);
inherit (workspaceCargo.workspace) members;
in utils.lib.simpleFlake {
inherit nixpkgs;
systems = [ "x86_64-linux" "aarch64-linux" ];
preOverlays = [ naersk ];
overlay = final: prev:
let lib = prev.lib;
in (lib.listToAttrs (lib.forEach members (member:
lib.nameValuePair member (final.naersk.buildPackage {
inherit ((builtins.fromTOML
(builtins.readFile (./. + "/${member}/Cargo.toml"))).package)
name version;
root = ./.;
nativeBuildInputs = with final; [ pkg-config protobuf rustfmt ];
buildInputs = with final; [ openssl ];
PROTOC = "${final.protobuf}/bin/protoc";
PROTOC_INCLUDE = "${final.protobuf}/include";
})))) // {
jormungandr-entrypoint = let
script = final.writeShellScriptBin "entrypoint" ''
set -exuo pipefail
ulimit -n 1024
nodeConfig="$NOMAD_TASK_DIR/node-config.json"
runConfig="$NOMAD_TASK_DIR/running.json"
runYaml="$NOMAD_TASK_DIR/running.yaml"
name="jormungandr"
chmod u+rwx -R "$NOMAD_TASK_DIR" || true
function convert () {
chmod u+rwx -R "$NOMAD_TASK_DIR" || true
cp "$nodeConfig" "$runConfig"
remarshal --if json --of yaml "$runConfig" > "$runYaml"
}
if [ "$RESET" = "true" ]; then
echo "RESET is given, will start from scratch..."
rm -rf "$STORAGE_DIR"
elif [ -d "$STORAGE_DIR" ]; then
echo "$STORAGE_DIR found, not restoring from backup..."
else
echo "$STORAGE_DIR not found, restoring backup..."
restic restore latest \
--verbose=5 \
--no-lock \
--tag "$NAMESPACE" \
--target / \
|| echo "couldn't restore backup, continue startup procedure..."
fi
set +x
echo "waiting for $REQUIRED_PEER_COUNT peers"
until [ "$(jq -e -r '.p2p.trusted_peers | length' < "$nodeConfig" || echo 0)" -ge $REQUIRED_PEER_COUNT ]; do
sleep 1
done
set -x
convert
if [ -n "$PRIVATE" ]; then
echo "Running with node with secrets..."
exec jormungandr \
--storage "$STORAGE_DIR" \
--config "$NOMAD_TASK_DIR/running.yaml" \
--genesis-block $NOMAD_TASK_DIR/block0.bin/block0.bin \
--secret $NOMAD_SECRETS_DIR/bft-secret.yaml \
"$@" || true
else
echo "Running with follower node..."
exec jormungandr \
--storage "$STORAGE_DIR" \
--config "$NOMAD_TASK_DIR/running.yaml" \
--genesis-block $NOMAD_TASK_DIR/block0.bin/block0.bin \
"$@" || true
fi
'';
in final.symlinkJoin {
name = "entrypoint";
paths = with final; [
jormungandr
script
bashInteractive
coreutils
curl
diffutils
fd
findutils
gnugrep
gnused
htop
jormungandr
jq
lsof
netcat
procps
remarshal
restic
ripgrep
strace
tcpdump
tmux
tree
utillinux
vim
yq
];
};
};
packages = { jormungandr, jcli, jormungandr-entrypoint }@pkgs: pkgs;
devShell =
{ mkShell, rustc, cargo, pkg-config, openssl, protobuf, rustfmt }:
mkShell {
PROTOC = "${protobuf}/bin/protoc";
PROTOC_INCLUDE = "${protobuf}/include";
buildInputs = [ rustc cargo pkg-config openssl protobuf rustfmt ];
};
hydraJobs = { jormungandr, jcli, jormungandr-entrypoint }@pkgs: pkgs;
};
}