forked from IntersectMBO/cardano-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.nix
168 lines (143 loc) · 5.05 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
# This file is used by nix-shell.
# It just takes the shell attribute from default.nix.
{ config ? {}
, sourcesOverride ? {}
, withHoogle ? true
, clusterProfile ? "default-mary"
, customConfig ? { profileName = clusterProfile; }
, autoStartCluster ? false
, useCabalRun ? false
, workbenchDevMode ? false
, workbenchConfig ?
{ inherit useCabalRun workbenchDevMode; }
, pkgs ? import ./nix {
inherit config sourcesOverride workbenchConfig;
}
}:
with pkgs;
let
commandHelp =
''
echo "
Commands:
* niv update <package> - update package
* cardano-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
"
'';
# This provides a development environment that can be used with nix-shell or
# lorri. See https://input-output-hk.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.
clusterCabal = mkCluster (lib.recursiveUpdate customConfig (workbenchConfig // { useCabalRun = true; }));
clusterNix = mkCluster (lib.recursiveUpdate customConfig (workbenchConfig // { useCabalRun = false; }));
shell = cardanoNodeHaskellPackages.shellFor {
name = "cabal-dev-shell";
inherit withHoogle;
packages = ps: lib.attrValues (haskell-nix.haskellLib.selectProjectPackages ps);
# These programs will be available inside the nix-shell.
buildInputs = with haskellPackages; [
cabal-install
cardano-ping
ghcid
hlint
weeder
nix
niv
pkgconfig
profiteur
profiterole
python3Packages.supervisor
ghc-prof-flamegraph
sqlite-interactive
tmux
pkgs.git
]
## Workbench's main script is called directly in dev mode.
++ lib.optionals (!workbenchDevMode)
[
pkgs.workbench.workbench
]
## Local cluster not available on Darwin,
## because psmisc fails to build on Big Sur.
++ lib.optionals (!stdenv.isDarwin)
[
clusterCabal.start
clusterCabal.stop
];
# Prevents cabal from choosing alternate plans, so that
# *all* dependencies are provided by Nix.
exactDeps = true;
shellHook = ''
echo "workbench: setting 'cabal.project' for local builds.."
./scripts/cabal-inside-nix-shell.sh
function atexit() {
echo "workbench: reverting 'cabal.project' to the index version.."
./scripts/cabal-inside-nix-shell.sh --restore
${lib.optionalString autoStartCluster ''
if wb local supervisord-running
then echo "workbench: stopping cluster (because 'autoStartCluster' implies this):"
stop-cluster
fi''}
}
trap atexit EXIT
${lib.optionalString (autoStartCluster && useCabalRun) ''
unset NIX_ENFORCE_PURITY
''}
${pkgs.workbench.shellHook}
${lib.optionalString autoStartCluster ''
echo "workbench: starting cluster (because 'autoStartCluster' is true):"
start-cluster
''}
${commandHelp}
set +e
'';
};
devops =
stdenv.mkDerivation {
name = "devops-shell";
buildInputs = [
cabal-install
niv
cardano-cli
bech32
cardano-node
python3Packages.supervisor
python3Packages.ipython
clusterNix.start
clusterNix.stop
cardanolib-py
pkgs.workbench.workbench
];
shellHook = ''
echo "DevOps Tools" \
| ${figlet}/bin/figlet -f banner -c \
| ${lolcat}/bin/lolcat
wb explain-mode
source <(cardano-cli --bash-completion-script cardano-cli)
source <(cardano-node --bash-completion-script cardano-node)
# Socket path default to first node launched by "start-cluster":
export CARDANO_NODE_SOCKET_PATH=$(wb local get-node-socket-path ${clusterNix.stateDir})
# 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 export GITHUB_TOKEN if you hit rate limits with niv"
${commandHelp}
${lib.optionalString autoStartCluster ''
echo "workbench: starting cluster (because 'autoStartCluster' is true):"
start-cluster
''}
'';
};
in
shell // { inherit devops; }