Skip to content

Commit 9966cff

Browse files
committed
wb | obtain all dependencies from the same, maybe custom, haskell.nix project
1 parent f539113 commit 9966cff

File tree

13 files changed

+171
-107
lines changed

13 files changed

+171
-107
lines changed

nix/pkgs.nix

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ let
66
inherit (final) pkgs;
77
inherit (prev.pkgs) lib;
88
inherit (prev) customConfig;
9-
# Workbench development environment entrypoint parametrized with current pkgs.
9+
# Parametrized helper entrypoint for the workbench development environment.
1010
workbench = import ./workbench
11-
{inherit pkgs lib; inherit (final) cardanoNodePackages cardanoNodeProject;};
11+
{ inherit pkgs lib;
12+
haskellProject = final.cardanoNodeProject;
13+
}
14+
;
1215

1316
in with final;
1417
{

nix/workbench/backend/nomad.nix

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{ pkgs
22
, lib
3+
, haskellProject
34
, stateDir
45
, subBackendName
56
, ...
@@ -145,29 +146,33 @@ let
145146
# the one used to enter the shell.
146147
cardano-node = rec {
147148
# Local reference only used if not "cloud".
148-
# Avoid rebuilding on every commit because of `set-git-rev`.
149-
nix-store-path = pkgs.cardanoNodePackages.cardano-node.passthru.noGitRev;
149+
nix-store-path = haskellProject.exes.cardano-node;
150150
flake-reference = "github:intersectmbo/cardano-node";
151+
# Where to fetch the binary from during "cloud" runs.
152+
# Avoid nix cache misses on every commit because of `set-git-rev`.
151153
flake-output = "cardanoNodePackages.cardano-node.passthru.noGitRev"
152154
;
153155
};
154156
cardano-cli = rec {
155157
# Local reference only used if not "cloud".
156-
# Avoid rebuilding on every commit because of `set-git-rev`.
157-
nix-store-path = pkgs.cardanoNodePackages.cardano-cli.passthru.noGitRev;
158+
nix-store-path = (haskellProject.getPackage "cardano-cli").components.exes.cardano-cli;
158159
flake-reference = "github:input-output-hk/cardano-cli";
160+
# Where to fetch the binary from during "cloud" runs.
161+
# Avoid nix cache misses on every commit because of `set-git-rev`.
159162
flake-output = "cardanoNodePackages.cardano-cli.passthru.noGitRev";
160163
};
161164
cardano-tracer = rec {
162165
# Local reference only used if not "cloud".
163-
nix-store-path = pkgs.cardanoNodePackages.cardano-tracer;
166+
nix-store-path = haskellProject.exes.cardano-tracer;
164167
flake-reference = "github:intersectmbo/cardano-node";
165168
flake-output = "cardanoNodePackages.cardano-tracer";
166169
};
167170
tx-generator = rec {
168171
# Local reference only used if not "cloud".
169-
nix-store-path = pkgs.cardanoNodePackages.tx-generator.passthru.noGitRev;
172+
nix-store-path = haskellProject.exes.tx-generator;
170173
flake-reference = "github:intersectmbo/cardano-node";
174+
# Where to fetch the binary from during "cloud" runs.
175+
# Avoid nix cache misses on every commit because of `set-git-rev`.
171176
flake-output = "cardanoNodePackages.tx-generator.passthru.noGitRev";
172177
};
173178
}

nix/workbench/backend/nomad/cloud.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{ pkgs
22
, lib
3+
, haskellProject
34
, stateDir
45
, basePort # ignored, just passed to the runner (unlike `supervisor.nix`).
56
## `useCabalRun` overridden parameter (unlike `supervisor.nix`).
@@ -39,7 +40,9 @@ let
3940
# Build a Nomad Job specification for this Nomad "sub-backend".
4041
materialise-profile =
4142
let params = {
42-
inherit pkgs lib stateDir;
43+
inherit pkgs lib;
44+
inherit haskellProject;
45+
inherit stateDir;
4346
subBackendName = "cloud";
4447
};
4548
in (import ../nomad.nix params).materialise-profile

nix/workbench/backend/nomad/exec.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{ pkgs
22
, lib
3+
, haskellProject
34
, stateDir
45
, basePort # ignored, just passed to the runner (unlike `supervisor.nix`).
56
## `useCabalRun` overridden parameter (unlike `supervisor.nix`).
@@ -37,7 +38,9 @@ let
3738
# Build a Nomad Job specification for this Nomad "sub-backend".
3839
materialise-profile =
3940
let params = {
40-
inherit pkgs lib stateDir;
41+
inherit pkgs lib;
42+
inherit haskellProject;
43+
inherit stateDir;
4144
subBackendName = "exec";
4245
};
4346
in (import ../nomad.nix params).materialise-profile

nix/workbench/backend/runner.nix

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{ pkgs, lib
22
## The binaries/scripts to use when calling the workbench.
3-
, cardanoNodeProject
4-
, cardanoNodePackages
3+
, haskellProject
54
, workbench # The derivation.
65
## Profile dependent parameters.
76
, profile
@@ -33,9 +32,9 @@ let
3332
cacheDir = "${__getEnv "HOME"}/.cache/cardano-workbench";
3433

3534
# recover CHaP location from cardano's project
36-
chap = cardanoNodeProject.args.inputMap."https://chap.intersectmbo.org/";
35+
chap = haskellProject.args.inputMap."https://chap.intersectmbo.org/";
3736
# build plan as computed by nix
38-
nixPlanJson = cardanoNodeProject.plan-nix + "/plan.json";
37+
nixPlanJson = haskellProject.plan-nix + "/plan.json";
3938

4039
# Optimize cache hits setting gitrev using bash once inside the shell.
4140
workbench-envars =
@@ -122,12 +121,9 @@ let
122121
]
123122
)
124123
++
125-
(with cardanoNodePackages;
126-
[
127-
cardano-cli
128-
locli
129-
]
130-
)
124+
[ haskellProject.exes.locli
125+
haskellProject.hsPkgs.cardano-cli.components.exes.cardano-cli
126+
]
131127
;
132128

133129
workbench-profile-run =
@@ -200,7 +196,7 @@ let
200196
--genesis-cache-entry ${genesisFiles}
201197
--batch-name smoke-test
202198
--base-port ${toString basePort}
203-
--node-source ${pkgs.cardanoNodeProject.args.src}
199+
--node-source ${haskellProject.args.src}
204200
--node-rev ${cardano-node-rev}
205201
--cache-dir ./cache
206202
${__concatStringsSep " " workbenchStartArgs}

nix/workbench/backend/supervisor.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{ pkgs
22
, lib
3+
, haskellProject
34
, stateDir
45
, basePort
56
, useCabalRun

nix/workbench/default.nix

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
# The workbench entrypoint,
12
{ pkgs, lib
2-
, cardanoNodeProject
3-
, cardanoNodePackages
3+
# This provided project attrset will be used all over the workbench instead
4+
# of the flake's `pkgs` or `cardanoNodePackages`. This allows to easily
5+
# parametrize the whole build at any point, be it only for the workbench in
6+
# "nix/pkgs.nix" or when entering a workbench shell in
7+
# "nix/workbench/shell.nix".
8+
# Also, by using a haskell.nix project instead of `cardanoNodePackages` or
9+
# `pkgs` to fetch it's project related dependencies we are sure they are not
10+
# tagged with the git commit because if we use the `set-git-rev` versions of
11+
# `cardano-node` and/or `tx-generator` then on every distinct commit ID all
12+
# the scripts generated by the workbench (start.sh files) will be re-generated
13+
# instead of obtained from the cache in the nix store.
14+
, haskellProject
415
}:
516

617
with lib;
@@ -51,7 +62,7 @@ let
5162
)
5263
# Include only the extensions defined above.
5364
(lib.any id
54-
(attrValues (mapAttrs
65+
(lib.attrValues (mapAttrs
5566
(dirName: suffixes:
5667
(lib.hasPrefix (dirName + "/") relativePath)
5768
&&
@@ -90,7 +101,7 @@ let
90101

91102
profile-names-json = pkgs.runCommand "profile-names.json" {}
92103
''
93-
${cardanoNodePackages.cardano-profile}/bin/cardano-profile "names" > $out
104+
${haskellProject.exes.cardano-profile}/bin/cardano-profile "names" > $out
94105
''
95106
;
96107

@@ -99,8 +110,8 @@ let
99110

100111
in pkgs.lib.fix (self: {
101112

102-
inherit cardanoNodePackages;
103113
inherit workbench;
114+
inherit haskellProject;
104115
inherit profile-names-json profile-names;
105116

106117
# Return a profile attr with a `materialise-profile` function.
@@ -132,7 +143,9 @@ in pkgs.lib.fix (self: {
132143
, profiling
133144
}:
134145
(backendRegistry."${backendName}")
135-
{ inherit pkgs lib stateDir basePort;
146+
{ inherit pkgs lib;
147+
inherit haskellProject;
148+
inherit stateDir basePort;
136149
# The `useCabalRun` and `profiling` flags are set in the backend to
137150
# allow the backend to override its values. The runner must use the
138151
# value of these two flags from the backend to prevent having a runner
@@ -175,7 +188,7 @@ in pkgs.lib.fix (self: {
175188
in import ./backend/runner.nix
176189
{
177190
inherit pkgs lib;
178-
inherit cardanoNodeProject cardanoNodePackages;
191+
inherit haskellProject;
179192
inherit workbench;
180193
inherit profile backend;
181194
inherit batchName workbenchStartArgs;

nix/workbench/profile/profile.nix

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{ pkgs, lib
2-
# The workbench development environment as it was parametrized.
2+
# The workbench attrset as it was parametrized.
33
, workbenchNix
44
, profileName
55
}:
@@ -19,8 +19,8 @@ let
1919
moreutils # sponge
2020
jq
2121
graphviz
22-
workbenchNix.cardanoNodePackages.cardano-profile
23-
workbenchNix.cardanoNodePackages.cardano-topology
22+
workbenchNix.haskellProject.exes.cardano-profile
23+
workbenchNix.haskellProject.exes.cardano-topology
2424
];
2525
}
2626
''
@@ -56,12 +56,13 @@ let
5656
profile = __fromJSON (__readFile profileJsonPath);
5757
nodeSpecs = __fromJSON (__readFile nodeSpecsJsonPath);
5858
inherit
59-
(pkgs.callPackage
59+
(import
6060
../service/nodes.nix
61-
{ inherit backend profile nodeSpecs;
61+
{ inherit pkgs;
62+
inherit workbenchNix;
63+
inherit backend profile nodeSpecs;
6264
inherit (backend) profiling;
6365
inherit profileJsonPath topologyJsonPath;
64-
inherit workbenchNix;
6566
## This ports the (very minimal) config of the deprecated iohk-nix
6667
## testnet environment to workbench, removing the dependency on it.
6768
baseNodeConfig =
@@ -72,16 +73,18 @@ let
7273
LastKnownBlockVersion-Alt = 0;
7374
}
7475
//
75-
workbenchNix.cardanoNodePackages.cardanoLib.defaultLogConfig
76+
workbenchNix.haskellProject.pkgs.cardanoLib.defaultLogConfig
7677
;
7778
}
7879
)
7980
node-services
8081
;
8182
inherit
82-
(pkgs.callPackage
83+
(import
8384
../service/generator.nix
84-
{ inherit backend profile nodeSpecs;
85+
{ inherit pkgs;
86+
inherit (workbenchNix) haskellProject;
87+
inherit backend profile nodeSpecs;
8588
inherit node-services;
8689
}
8790
)
@@ -93,7 +96,10 @@ let
9396
start =
9497
''
9598
${import ../workload/${name}.nix
96-
{inherit pkgs profile nodeSpecs workload;}
99+
{ inherit pkgs;
100+
inherit (workbenchNix) haskellProject;
101+
inherit profile nodeSpecs workload;
102+
}
97103
}
98104
${workload.entrypoints.producers}
99105
''
@@ -102,16 +108,22 @@ let
102108
profile.workloads
103109
;
104110
inherit
105-
(pkgs.callPackage
111+
(import
106112
../service/tracer.nix
107-
{inherit backend profile nodeSpecs;}
113+
{ inherit pkgs;
114+
inherit (workbenchNix) haskellProject;
115+
inherit backend profile nodeSpecs;
116+
}
108117
)
109118
tracer-service
110119
;
111120
healthcheck-service =
112-
(pkgs.callPackage
121+
(import
113122
../service/healthcheck.nix
114-
{inherit backend profile nodeSpecs;}
123+
{ inherit pkgs;
124+
inherit (workbenchNix) haskellProject;
125+
inherit backend profile nodeSpecs;
126+
}
115127
)
116128
;
117129
in {
@@ -146,7 +158,7 @@ let
146158
inherit topologyJsonPath topologyDotPath;
147159
inherit nodeSpecsJsonPath;
148160
nodeServices = __toJSON
149-
(lib.mapAttrs
161+
(pkgs.lib.mapAttrs
150162
(name: node-service:
151163
{ inherit name;
152164
inherit (node-service) start config;

nix/workbench/service/generator.nix

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{ pkgs
2-
2+
, haskellProject
33
, backend
44
, profile
55
, nodeSpecs
@@ -57,11 +57,13 @@ let
5757
;
5858
} // optionalAttrs profile.node.tracer {
5959
tracerSocketPath = "../tracer/tracer.socket";
60+
# Decide where the executable comes from:
61+
#########################################
6062
} // optionalAttrs (!backend.useCabalRun) {
61-
# Use to `noGitRev` to avoid rebuilding on every commit.
62-
executable = "${pkgs.cardanoNodePackages.tx-generator.passthru.noGitRev}/bin/tx-generator";
63-
} // optionalAttrs backend.useCabalRun {
63+
executable = "${haskellProject.exes.tx-generator}/bin/tx-generator";
64+
} // optionalAttrs backend.useCabalRun {
6465
executable = "tx-generator";
66+
#########################################
6567
});
6668

6769
##

nix/workbench/service/healthcheck.nix

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{ pkgs
2+
, haskellProject
23
, backend
34
, profile
45
, nodeSpecs
@@ -12,17 +13,19 @@ let
1213
supervisor = pkgs.supervisor;
1314
grep = pkgs.gnugrep;
1415
jq = pkgs.jq;
15-
# Avoid rebuilding the script on every commit.
16-
# `noGitRev` does not have `set-git-rev` that is set on every commit.
17-
cardano-node = with pkgs;
16+
# Decide where the executables come from:
17+
#########################################
18+
cardano-node =
1819
if backend.useCabalRun
1920
then "cardano-node"
20-
else cardanoNodePackages.cardano-node.passthru.noGitRev + "/bin/cardano-node"
21+
else haskellProject.exes.cardano-node + "/bin/cardano-node"
2122
;
22-
cardano-cli = with pkgs;
23+
cardano-cli =
2324
if backend.useCabalRun
2425
then "cardano-cli"
25-
else cardanoNodePackages.cardano-cli.passthru.noGitRev + "/bin/cardano-cli";
26+
else haskellProject.hsPkgs.cardano-cli.components.exes.cardano-cli + "/bin/cardano-cli"
27+
;
28+
#########################################
2629
in {
2730
start =
2831
# Assumptions:

0 commit comments

Comments
 (0)