forked from The-Blockchain-Company/bcc-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.nix
225 lines (193 loc) · 6.81 KB
/
shell.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
let defaultCustomConfig = import ./nix/custom-config.nix defaultCustomConfig;
# This file is used by nix-shell.
# It just takes the shell attribute from default.nix.
in
{ config ? {}
, sourcesOverride ? {}
, withHoogle ? defaultCustomConfig.withHoogle
, clusterProfile ? defaultCustomConfig.localCluster.profileName
, autoStartCluster ? defaultCustomConfig.localCluster.autoStartCluster
, autoStartClusterArgs ? ""
, workbenchDevMode ? defaultCustomConfig.localCluster.workbenchDevMode
, withR ? false
, customConfig ? {
inherit withHoogle;
localCluster = {
inherit autoStartCluster workbenchDevMode;
profileName = clusterProfile;
};
}
, pkgs ? import ./nix {
inherit config sourcesOverride customConfig;
}
}:
with pkgs;
let
inherit (pkgs) customConfig;
inherit (customConfig) withHoogle localCluster withR;
inherit (localCluster) autoStartCluster workbenchDevMode;
commandHelp =
''
echo "
Commands:
* nix flake lock --update-input <tbcoNix|haskellNix> - update nix build input
* bcc-cli - used for key generation and other operations tasks
* wb - cluster workbench
* start-cluster - start a local development cluster
* stop-cluster - stop a local development cluster
* restart-cluster - restart the last cluster run (in 'run/current')
(WARNING: logs & node DB will be wiped clean)
"
'';
# Test cases will assume a UTF-8 locale and provide text in this character encoding.
# So force the character encoding to UTF-8 and provide locale data.
setLocale =
''
export LANG="en_US.UTF-8"
'' + lib.optionalString haveGlibcLocales ''
export LOCALE_ARCHIVE="${pkgs.glibcLocales}/lib/locale/locale-archive"
'';
haveGlibcLocales = pkgs.glibcLocales != null && stdenv.hostPlatform.libc == "glibc";
# This provides a development environment that can be used with nix-shell or
# lorri. See https://The-Blockchain-Company.github.io/haskell.nix/user-guide/development/
# NOTE: due to some cabal limitation,
# you have to remove all `source-repository-package` entries from cabal.project
# after entering nix-shell for cabal to use nix provided dependencies for them.
mkCluster =
{ useCabalRun }:
callPackage ./nix/supervisord-cluster
{ inherit useCabalRun;
inherit (localCluster) profileName;
workbench = pkgs.callPackage ./nix/workbench { inherit useCabalRun; };
};
rstudio = pkgs.rstudioWrapper.override {
packages = with pkgs.rPackages; [ car dplyr ggplot2 reshape2 ];
};
shell =
let cluster = mkCluster { useCabalRun = true; };
in bccNodeProject.shellFor {
name = "cabal-dev-shell";
inherit withHoogle;
packages = lib.attrVals bccNodeProject.projectPackages;
tools = {
haskell-language-server = {
version = "latest";
index-state = "2021-06-22T00:00:00Z";
# inherit (bccNodeProject) index-state;
};
};
# These programs will be available inside the nix-shell.
nativeBuildInputs = with haskellPackages; [
bcc-ping
cabalWrapped
ghcid
weeder
nixWrapped
pkgconfig
profiteur
profiterole
python3Packages.supervisor
ghc-prof-flamegraph
sqlite-interactive
tmux
pkgs.git
pkgs.hlint
pkgs.moreutils
] ++ lib.optional haveGlibcLocales pkgs.glibcLocales
## Workbench's main script is called directly in dev mode.
++ lib.optionals (!workbenchDevMode)
[
cluster.workbench.workbench
]
++ lib.optionals withR
[
rstudio
]
## Local cluster not available on Darwin,
## because psmisc fails to build on Big Sur.
++ lib.optionals (!stdenv.isDarwin)
[
pkgs.psmisc
cluster.start
cluster.stop
cluster.restart
];
# Prevents cabal from choosing alternate plans, so that
# *all* dependencies are provided by Nix.
exactDeps = true;
shellHook = ''
echo 'nix-shell options & flags: withHoogle=${toString withHoogle} clusterProfile=${clusterProfile} autoStartCluster=${toString autoStartCluster} workbenchDevMode=${toString workbenchDevMode}'
${cluster.workbench.shellHook}
${lib.optionalString autoStartCluster ''
function atexit() {
if wb backend is-running
then echo "workbench: stopping cluster (because 'autoStartCluster' implies this):"
stop-cluster
fi
}
trap atexit EXIT
''}
unset NIX_ENFORCE_PURITY
${setLocale}
${lib.optionalString autoStartCluster ''
echo "workbench: starting cluster (because 'autoStartCluster' is true):"
start-cluster ${autoStartClusterArgs}
''}
${commandHelp}
set +e
'';
};
devops =
let cluster = mkCluster { useCabalRun = false; };
in bccNodeProject.shellFor {
name = "devops-shell";
packages = _: [];
nativeBuildInputs = [
nixWrapped
bcc-cli
bech32
bcc-ping
bcc-node
python3Packages.supervisor
python3Packages.ipython
cluster.start
cluster.stop
cluster.restart
bcclib-py
cluster.workbench.workbench
] ++ (lib.optionals (!stdenv.isDarwin) [
psmisc
]);
# Prevents cabal from choosing alternate plans, so that
# *all* dependencies are provided by Nix.
exactDeps = true;
shellHook = ''
echo "DevOps Tools" \
| ${figlet}/bin/figlet -f banner -c \
| ${lolcat}/bin/lolcat
wb explain-mode
${cluster.workbench.shellHook}
# Socket path default to first node launched by "start-cluster":
export BCC_NODE_SOCKET_PATH=$(wb backend get-node-socket-path ${cluster.stateDir})
${setLocale}
# Unless using specific network:
${lib.optionalString (__hasAttr "network" customConfig) ''
export BCC_NODE_SOCKET_PATH="$PWD/state-node-${customConfig.network}/node.socket"
${lib.optionalString (__hasAttr "utxo" pkgs.commonLib.bccLib.environments.${customConfig.network}) ''
# Selfnode and other test clusters have public secret keys that we pull from tbco-nix
echo "To access funds use UTXO_SKEY and UTXO_VKEY environment variables"
export UTXO_SKEY="${pkgs.commonLib.bccLib.environments.${customConfig.network}.utxo.signing}"
export UTXO_VKEY="${pkgs.commonLib.bccLib.environments.${customConfig.network}.utxo.verification}"
''}
''}
echo "NOTE: you may need to use a github access token if you hit rate limits with nix flake update:"
echo ' edit ~/.config/nix/nix.conf and add line `access-tokens = "github.com=23ac...b289"`'
${commandHelp}
${lib.optionalString autoStartCluster ''
echo "workbench: starting cluster (because 'autoStartCluster' is true):"
start-cluster
''}
'';
};
in
shell // { inherit devops; }