forked from remik2212/holochain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.nix
More file actions
242 lines (200 loc) · 6.15 KB
/
Copy pathdefault.nix
File metadata and controls
242 lines (200 loc) · 6.15 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
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
# This is an example of what downstream consumers of holonix should do
# This is also used to dogfood as many commands as possible for holonix
# For example the release process for holonix uses this file
let
# point this to your local config.nix file for this project
# example.config.nix shows and documents a lot of the options
config = import ./config.nix;
# START HOLONIX IMPORT BOILERPLATE
holonix = import (
if ! config.holonix.use-github
then config.holonix.local.path
else fetchTarball {
url = "https://github.com/${config.holonix.github.owner}/${config.holonix.github.repo}/tarball/${config.holonix.github.ref}";
sha256 = config.holonix.github.sha256;
}
) { config = config; use-stable-rust = true; };
# END HOLONIX IMPORT BOILERPLATE
in
with holonix.pkgs;
{
dev-shell = stdenv.mkDerivation (holonix.shell // {
name = "dev-shell";
shellHook = holonix.pkgs.lib.concatStrings [
holonix.shell.shellHook
''
touch .env
source .env
export HC_TARGET_PREFIX=$NIX_ENV_PREFIX
export CARGO_TARGET_DIR="$HC_TARGET_PREFIX/target"
export HC_TEST_WASM_DIR="$HC_TARGET_PREFIX/.wasm_target"
mkdir -p $HC_TEST_WASM_DIR
export CARGO_CACHE_RUSTC_INFO=1
export HC_WASM_CACHE_PATH="$HC_TARGET_PREFIX/.wasm_cache"
mkdir -p $HC_WASM_CACHE_PATH
export PEWPEWPEW_PORT=4343
''
];
buildInputs = [
holonix.pkgs.gnuplot
holonix.pkgs.flamegraph
holonix.pkgs.fd
holonix.pkgs.ngrok
holonix.pkgs.jq
]
++ holonix.shell.buildInputs
# release hooks
++ (holonix.pkgs.callPackage ./release {
pkgs = holonix.pkgs;
config = config;
}).buildInputs
# main test script
++ (holonix.pkgs.callPackage ./test {
pkgs = holonix.pkgs;
}).buildInputs
++ ([(
holonix.pkgs.writeShellScriptBin "hc-install" ''
hc-install-holochain
hc-install-dna-util
hc-doctor
''
)])
++ ([(
holonix.pkgs.writeShellScriptBin "hc-uninstall" ''
hc-uninstall-holochain
hc-uninstall-dna-util
hc-doctor
''
)])
++ ([(
holonix.pkgs.writeShellScriptBin "hc-install-holochain" ''
cargo install --no-default-features --path crates/holochain
echo 'holochain installed!'
echo
''
)])
++ ([(
holonix.pkgs.writeShellScriptBin "hc-uninstall-holochain" ''
cargo uninstall holochain
echo 'holochain uninstalled!'
echo
''
)])
++ ([(
holonix.pkgs.writeShellScriptBin "hc-install-dna-util" ''
cargo install --path crates/dna_util
echo 'dna util installed!'
echo
''
)])
++ ([(
holonix.pkgs.writeShellScriptBin "hc-uninstall-dna-util" ''
cargo uninstall dna_util
echo 'dna util uninstalled!'
echo
''
)])
++ ([(
holonix.pkgs.writeShellScriptBin "hc-doctor" ''
echo "### holochain doctor ###"
echo
echo "if you have installed holochain directly using hc-install it should be in the cargo root"
echo "if that is what you want it may be worth running hc-install to 'refresh' it as HEAD moves quickly"
echo
echo "if you are using the more stable binaries provided by holonix it should be in /nix/store/../bin"
echo
echo "cargo install root:"
echo $CARGO_INSTALL_ROOT
echo
echo "holochain binary installation:"
command -v holochain
echo
echo "dna-util binary installation"
command -v dna-util
echo
''
)])
# convenience command for executing dna-util
# until such time as we have release artifacts
# that can be built directly as nix packages
++ ([(
holonix.pkgs.writeShellScriptBin "dna-util" ''
cargo run --manifest-path "''${HC_TARGET_PREFIX}/crates/dna_util/Cargo.toml" -- "''${@}"
''
)])
++ ([(
holonix.pkgs.writeShellScriptBin "hc-bench" ''
cargo bench --bench bench
'')])
++ ([(
holonix.pkgs.writeShellScriptBin "hc-fmt-all" ''
fd Cargo.toml crates | xargs -L 1 cargo fmt --manifest-path
'')])
++ ([(
holonix.pkgs.writeShellScriptBin "hc-bench-github" ''
set -x
# the first arg is the authentication token for github
# @todo this is only required because the repo is currently private
token=''${1}
# set the target dir to somewhere it is less likely to be accidentally deleted
CARGO_TARGET_DIR=$BENCH_OUTPUT_DIR
# run benchmarks from a github archive based on any ref github supports
# @param ref: the github ref to benchmark
function bench {
## vars
ref=$1
dir="$TMP/$ref"
tarball="$dir/tarball.tar.gz"
## process
### fresh start
mkdir -p $dir
rm -f $dir/$tarball
### fetch code to bench
curl -L --cacert $SSL_CERT_FILE -H "Authorization: token $token" "https://github.com/holochain/holochain/archive/$ref.tar.gz" > $tarball
tar -zxvf $tarball -C $dir
### bench code
cd $dir/holochain-$ref
cargo bench --bench bench -- --save-baseline $ref
}
# load an existing report and push it as a comment to github
function add_comment_to_commit {
## convert the report to POST-friendly json and push to github comment API
jq \
-n \
--arg report \
"\`\`\`$( cargo bench --bench bench -- --baseline $1 --load-baseline $2 )\`\`\`" \
'{body: $report}' \
| curl \
-L \
--cacert $SSL_CERT_FILE \
-H "Authorization: token $token" \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/holochain/holochain/commits/$2/comments \
-d@-
}
commit=''${2}
bench $commit
# @todo make this flexible based on e.g. the PR base on github
compare=develop
bench $compare
add_comment_to_commit $compare $commit
'')])
++ ([(
holonix.pkgs.writeShellScriptBin "pewpewpew" ''
# compile and build pewpewpew
( cd crates/pewpewpew && cargo run )
'')])
++ ([(
holonix.pkgs.writeShellScriptBin "pewpewpew-ngrok" ''
# serve up a local pewpewpew instance that github can point to for testing
ngrok http http://127.0.0.1:$PEWPEWPEW_PORT
'')])
++ ([(
holonix.pkgs.writeShellScriptBin "pewpewpew-gen-secret" ''
# generate a new github secret
cat /dev/urandom | head -c 64 | base64
'')])
;
});
}