Skip to content

Commit 539fa09

Browse files
committed
wb | indentation and cleaning
1 parent 5c35c24 commit 539fa09

File tree

4 files changed

+73
-60
lines changed

4 files changed

+73
-60
lines changed

nix/pkgs.nix

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ let
66
inherit (prev.pkgs) lib;
77
inherit (prev) customConfig;
88

9-
# A generic, fully parameteric version of the workbench development environment.
9+
# A generic, fully parametric version of the workbench development environment.
1010
workbench = import ./workbench
1111
{inherit pkgs lib; inherit (final) cardanoNodePackages cardanoNodeProject;};
1212

1313
# Workbench runner instantiated by parameters from customConfig:
1414
workbench-runner =
15-
{ stateDir ? customConfig.localCluster.stateDir
16-
, batchName ? customConfig.localCluster.batchName
17-
, profileName ? customConfig.localCluster.profileName
15+
{ profileName ? customConfig.localCluster.profileName
16+
, profiling ? customConfig.profiling
1817
, backendName ? customConfig.localCluster.backendName
18+
, stateDir ? customConfig.localCluster.stateDir
1919
, basePort ? customConfig.localCluster.basePort
2020
, useCabalRun ? customConfig.localCluster.useCabalRun
2121
, workbenchDevMode ? customConfig.localCluster.workbenchDevMode
22+
, batchName ? customConfig.localCluster.batchName
2223
, workbenchStartArgs ? customConfig.localCluster.workbenchStartArgs
23-
, profiling ? customConfig.profiling
2424
, cardano-node-rev ? null
2525
}:
2626
workbench.runner
27-
{ inherit stateDir batchName profileName backendName basePort useCabalRun;
28-
inherit workbenchDevMode workbenchStartArgs profiling cardano-node-rev;
27+
{ inherit profileName profiling backendName stateDir basePort useCabalRun;
28+
inherit batchName workbenchDevMode workbenchStartArgs cardano-node-rev;
2929
};
3030

3131
in with final;

nix/workbench/backend/runner.nix

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
{ pkgs
2-
, lib
1+
{ pkgs, lib
32
##
43
, profile
54
, backend
6-
, batchName
75
##
8-
, cardano-node-rev
9-
, workbench
10-
, cardanoNodePackages
6+
, workbench # The derivation.
117
, workbenchDevMode
8+
, cardanoNodePackages # The binaries to use when calling the workbench.
9+
, batchName
1210
, workbenchStartArgs
1311
##
14-
, cacheDir ? "${__getEnv "HOME"}/.cache/cardano-workbench"
12+
, cardano-node-rev
1513
}:
1614
let
1715
profileName = profile.name;
@@ -33,7 +31,7 @@ in
3331
## In dev mode, call the script directly:
3432
++ pkgs.lib.optionals (!workbenchDevMode)
3533
[ workbench ];
36-
34+
cacheDir = "${__getEnv "HOME"}/.cache/cardano-workbench";
3735
workbench-interactive-start = pkgs.writeScriptBin "start-cluster" ''
3836
set -euo pipefail
3937

nix/workbench/default.nix

Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
{ pkgs
2-
, lib
1+
{ pkgs, lib
32
, cardanoNodePackages
43
, cardanoNodeProject
54
}:
65

76
with lib;
87

98
let
9+
1010
# recover CHaP location from cardano's project
1111
chap = cardanoNodeProject.args.inputMap."https://chap.intersectmbo.org/";
1212
# build plan as computed by nix
1313
nixPlanJson = cardanoNodeProject.plan-nix.json;
1414

15+
# Workbench derivation and functions to create derivations from `wb` commands.
16+
##############################################################################
17+
1518
workbench' = tools:
1619
pkgs.stdenv.mkDerivation {
1720
pname = "workbench";
@@ -45,44 +48,75 @@ let
4548
dontStrip = true;
4649
};
4750

48-
workbench = with cardanoNodePackages; with pkgs; workbench' (
49-
[ git graphviz
50-
jq
51-
moreutils
52-
procps
53-
cardano-cli
54-
cardano-profile
55-
cardano-topology
56-
] ++ lib.optional (!pkgs.stdenv.hostPlatform.isDarwin) db-analyser
57-
++ [ locli ]
51+
# Workbench with its dependencies to call from Nix.
52+
workbench = workbench' (
53+
(with pkgs;
54+
[ git graphviz
55+
jq
56+
moreutils
57+
procps
58+
]
59+
)
60+
++
61+
(with cardanoNodePackages;
62+
[
63+
cardano-cli
64+
cardano-profile
65+
cardano-topology
66+
locli
67+
]
68+
)
69+
++
70+
lib.optional (!pkgs.stdenv.hostPlatform.isDarwin) pkgs.db-analyser
5871
);
5972

6073
runWorkbench =
61-
name: command:
74+
name: command: # Name of the derivation and `wb` command to run.
6275
pkgs.runCommand name {} ''
6376
${workbench}/bin/wb ${command} > $out
6477
'';
6578

79+
# Helper functions.
80+
##############################################################################
81+
6682
runJq =
6783
name: args: query:
6884
pkgs.runCommand name {} ''
6985
args=(${args})
7086
${pkgs.jq}/bin/jq '${query}' "''${args[@]}" > $out
7187
'';
7288

73-
profile-names-json =
74-
runWorkbench "profile-names.json" "profiles list";
89+
# Auxiliary functions of `wb` commands.
90+
##############################################################################
7591

76-
profile-names =
77-
__fromJSON (__readFile profile-names-json);
92+
profile-names = __fromJSON (__readFile profile-names-json);
93+
94+
profile-names-json = runWorkbench "profile-names.json" "profiles list";
95+
96+
# Output
97+
################################################################################
7898

7999
in pkgs.lib.fix (self: {
100+
80101
inherit cardanoNodePackages;
81102
inherit workbench' workbench runWorkbench;
82103
inherit runJq;
83-
84104
inherit profile-names-json profile-names;
85105

106+
# Return a profile attr with a `materialise-profile` function.
107+
# profileName -> profiling -> profile
108+
profile =
109+
{ profileName
110+
, profiling
111+
}:
112+
(import ./profile/profile.nix
113+
{ inherit pkgs lib;
114+
workbenchNix = self;
115+
inherit profileName profiling;
116+
}
117+
)
118+
;
119+
86120
# Return a backend attr with a `materialise-profile` function.
87121
# backendName -> stateDir -> basePort -> useCabalRun -> backend
88122
backend =
@@ -106,43 +140,27 @@ in pkgs.lib.fix (self: {
106140
{ inherit pkgs lib stateDir basePort useCabalRun; }
107141
;
108142

109-
# Return a profile attr with a `materialise-profile` function.
110-
# profileName -> profiling -> profile
111-
profile =
112-
{ profileName
113-
, profiling
114-
}:
115-
(import ./profile/profile.nix
116-
{ inherit pkgs lib;
117-
workbenchNix = self;
118-
inherit profileName profiling;
119-
}
120-
)
121-
;
122-
123143
# A conveniently-parametrisable workbench preset.
124144
# See https://input-output-hk.github.io/haskell.nix/user-guide/development/
125145
# The general idea is:
126146
# 1. profileName -> profiling -> profile
127147
# 2. backendName -> stateDir -> basePort -> useCabalRun -> backend
128148
# 3. profile -> backend -> batchName -> runner
129149
runner =
130-
{ stateDir
131-
, batchName
132-
, profileName
150+
{ profileName
151+
, profiling
133152
, backendName
153+
, stateDir
134154
, basePort
135155
, useCabalRun
136156
, workbenchDevMode
157+
, batchName
137158
, workbenchStartArgs
138-
, profiling
139159
, cardano-node-rev
140160
}:
141161
let
142162
# Only a name needed to create a profile attrset.
143-
profile = self.profile
144-
{ inherit profileName profiling; }
145-
;
163+
profile = self.profile { inherit profileName profiling; };
146164
# The `useCabalRun` flag is set in the backend to allow the backend to
147165
# override its value. The runner uses the value of `useCabalRun` from
148166
# the backend to prevent a runner using a different value.
@@ -153,10 +171,8 @@ in pkgs.lib.fix (self: {
153171
{
154172
inherit pkgs lib;
155173
inherit profile backend;
156-
inherit batchName;
174+
inherit workbench workbenchDevMode cardanoNodePackages;
175+
inherit batchName workbenchStartArgs;
157176
inherit cardano-node-rev;
158-
inherit workbench; # The derivation.
159-
inherit cardanoNodePackages;
160-
inherit workbenchDevMode workbenchStartArgs;
161177
};
162178
})

nix/workbench/profile/profile.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{ pkgs, lib
22
, workbenchNix
3-
, profileName
4-
, profiling
3+
, profileName, profiling
54
}:
65

76
let

0 commit comments

Comments
 (0)