forked from IntersectMBO/cardano-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.nix
More file actions
278 lines (254 loc) · 10.8 KB
/
shell.nix
File metadata and controls
278 lines (254 loc) · 10.8 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
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
270
271
272
273
274
275
276
277
278
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
{ # Compile with `--enable-profiling` or not.
profiledBuild ? defaultCustomConfig.profiledBuild
# For example "space-info+eventlog+info-table".
, profilingType ? defaultCustomConfig.profilingType
, withHoogle ? defaultCustomConfig.withHoogle
, profileName ? defaultCustomConfig.localCluster.profileName
, backendName ? defaultCustomConfig.localCluster.backendName
, useCabalRun ? true
, workbenchDevMode ? defaultCustomConfig.localCluster.workbenchDevMode
, workbenchStartArgs ? defaultCustomConfig.localCluster.workbenchStartArgs
, customConfig ? {
inherit profiledBuild profilingType withHoogle;
localCluster = {
inherit profileName backendName useCabalRun workbenchDevMode workbenchStartArgs;
};
}
, pkgs ? import ./nix customConfig
}:
with pkgs;
let
inherit (pkgs) customConfig;
inherit (customConfig) withHoogle localCluster;
inherit (localCluster) profileName workbenchDevMode workbenchStartArgs;
inherit (pkgs.haskell-nix) haskellLib;
# An attrset containing the parsed profiling options.
profiling =
let
# Split nix-shell "profilingType" argument in "PROFILING_MODE+MODIFIERS".
profilingTypeParts = lib.strings.splitString "+" profilingType;
# Get and check the first part of the "profilingType" nix-shell argument.
profilingTypeParam =
let
# The available profiling modes and if a profiled runtime is required.
options =
{
# Time and allocation profiling.
################################
################################
### `-p`: produces a standard time profile report.
"time" = true;
### `-P`: produces a more detailed report containing the actual
### time and allocation data as well (not used much.).
"time-detail" = true;
# RTS options for heap profiling
################################
################################
# There are several different kinds of heap profile that can be
# generated. All the different profile types yield a graph of live
# heap against time, but they differ in how the live heap is
# broken down into bands. The following RTS options select which
# break-down to use:
### `-hb` (Requires -prof):
### Breaks down the graph by biography.
"space-bio" = true;
### `-hd` (Requires -prof):
### Breaks down the graph by closure description. For actual data,
### the description is just the constructor name, for other
### closures it is a compiler-generated string identifying the
### closure.
"space-closure" = true;
### `-hc` (Requires -prof):
### Breaks down the graph by the cost-centre stack which produced
### the data.
"space-cost" = true;
### `-hT` (This does not require the profiling runtime):
### Breaks down the graph by heap closure type.
"space-heap" = false;
### `-hi` (This does not require the profiling runtime):
### Break down the graph by the address of the info table of a
### closure. For this to produce useful output the program must
### have been compiled with -finfo-table-map but it does not
### require the profiling runtime.
"space-info" = false;
### `-hm` (Requires -prof).
### Break down the live heap by the module containing the code
### which produced the data.
"space-module" = true;
### `-hr` (Requires -prof):
### Break down the graph by retainer set.
"space-retainer" = true;
### `-hy` (Requires -prof):
### Breaks down the graph by type. For closures which have
### function type or unknown/polymorphic type, the string will
### represent an approximation to the actual type.
"space-type" = true;
}
;
requestedPrefix =
if (builtins.length profilingTypeParts > 0)
then builtins.elemAt profilingTypeParts 0
else "none" # For easier handling keep the default as "none".
;
in
if requestedPrefix == null || requestedPrefix == "" || requestedPrefix == "none"
then "none" # For easier handling keep the default as "none".
else
# Check if the profiling option exists.
if !(__hasAttr requestedPrefix options)
then throw "FATAL: WB_PROFILING must be one of: none, ${toString (pkgs.lib.strings.intersperse "," (__attrNames options))}"
else
# Check is the profiling options needs a profiled runtime.
let needsProfiledBuild = options."${requestedPrefix}";
in if needsProfiledBuild && !profiledBuild
then throw "FATAL: profiling type \"${requestedPrefix}\" needs a profiled runtime"
else requestedPrefix
;
# Get and check the modifiers of the "profilingType" nix-shell argument.
profilingTypeModifiers =
let
# The available modifiers.
options = [ "eventlog" "info-table" ];
requestedModifiers =
if (builtins.length profilingTypeParts >= 2)
then builtins.tail profilingTypeParts
else [] # For easier handling keep the default as an empty list.
;
in
if builtins.all (m: builtins.elem m options) requestedModifiers
then requestedModifiers
else throw "FATAL: The WB_PROFILING modifiers (PROFILING_MODE+MODIFIER) must be of: none, ${toString (pkgs.lib.strings.intersperse "," options)}"
;
in
{ inherit profiledBuild profilingType;
inherit profilingTypeParam;
eventlog = builtins.elem "eventlog" profilingTypeModifiers;
infoTable = builtins.elem "info-table" profilingTypeModifiers;
}
;
# Based on the profiling mode requested get the needed haskell.nix project.
project =
let
module = {pkgs, lib, ...}:
if profiling.infoTable
then
{ modules = [
{ # For all reinstalled packages.
# Same as `cabal.project`:
### package *
### ghc-options: -finfo-table-map -fdistinct-constructor-tables
ghcOptions = [ "-finfo-table-map" "-fdistinct-constructor-tables" ];
}
];
}
else {}
;
in
# Even when using `useCabalRun` we want to enter a shell were all the
# dependencies are built with the requested profiling/info-table
# combination. If not Cabal will re-build all dependencies with profiling
# or only add "info-table" to the executable/target.
# Note: `base` won't include "info-table" unless you build GHC with it.
if profiledBuild
then cardanoNodeProject.profiled.appendModule( module )
else cardanoNodeProject.appendModule( module )
;
## The default shell is defined by flake.nix: (cardanoNodeProject = flake.project.${final.system})
inherit (project) shell;
## XXX: remove this once people retrain their muscle memory:
dev = project.shell;
# 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";
workbench-shell =
with customConfig.localCluster;
import ./nix/workbench/shell.nix
{ inherit pkgs lib haskellLib project;
inherit setLocale haveGlibcLocales;
inherit workbenchDevMode;
inherit withHoogle;
workbench-runner = pkgs.workbench-runner
{ inherit profiling;
inherit profileName backendName useCabalRun;
};
};
devops =
let profileName = "devops-bage";
workbench-runner = pkgs.workbench-runner
{ inherit profiling;
inherit profileName;
backendName = "supervisor";
useCabalRun = false;
};
devopsShell = with customConfig.localCluster;
import ./nix/workbench/shell.nix
{ inherit pkgs lib haskellLib project;
inherit setLocale haveGlibcLocales;
inherit workbench-runner workbenchDevMode;
inherit withHoogle;
};
in project.shellFor {
name = "devops-shell";
packages = _: [];
nativeBuildInputs = with cardanoNodePackages; [
alejandra
nix
cardano-cli
bech32
cardano-node
cardano-profile
cardano-topology
cardano-tracer
locli
tx-generator
pkgs.graphviz
python3Packages.supervisor
python3Packages.ipython
cardanolib-py
pstree
pkgs.time
pkgs.util-linux
workbench.workbench
git
graphviz
jq
moreutils
procps
workbench-runner.workbench-interactive-start
workbench-runner.workbench-interactive-stop
workbench-runner.workbench-interactive-restart
];
# Disable build tools for all of hsPkgs (would include duplicates for cardano-cli, cardano-node, etc.)
allToolDeps = false;
shellHook = ''
echo "DevOps Tools" \
| ${figlet}/bin/figlet -f banner -c \
| ${lolcat}/bin/lolcat
${devopsShell.shellHook}
${setLocale}
# Unless using specific network:
${lib.optionalString (__hasAttr "network" customConfig) ''
export CARDANO_NODE_SOCKET_PATH="$PWD/state-node-${customConfig.network}/node.socket"
${lib.optionalString (__hasAttr "utxo" pkgs.commonLib.cardanoLib.environments.${customConfig.network}) ''
# Selfnode and other test clusters have public secret keys that we pull from iohk-nix
echo "To access funds use UTXO_SKEY and UTXO_VKEY environment variables"
export UTXO_SKEY="${pkgs.commonLib.cardanoLib.environments.${customConfig.network}.utxo.signing}"
export UTXO_VKEY="${pkgs.commonLib.cardanoLib.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"`'
'';
};
in
shell // { inherit workbench-shell; inherit devops; inherit dev; }