Skip to content

Commit 5c4ff32

Browse files
committed
workbench: refactoring of modules dependencies
- Remove repeated code (services-config) from backends - Move 'services-config' to profiles and out of the backends - Move the backend dependency out from 'all-profiles' - Remove unused code and parameters or its defaults - Remove 'stateDir' from the backends - Renames for clarity
1 parent 9100ae5 commit 5c4ff32

13 files changed

+206
-245
lines changed

flake.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
benchmarks = collectComponents' "benchmarks" projectPackages;
279279
});
280280

281-
inherit (pkgs) workbench all-profiles-json workbench-instance;
281+
inherit (pkgs) workbench all-profiles-json workbench-runner;
282282

283283
packages =
284284
exes
@@ -292,7 +292,7 @@
292292

293293
## This is a very light profile, no caching&pinning needed.
294294
workbench-ci-test =
295-
(pkgs.workbench-instance
295+
(pkgs.workbench-runner
296296
{
297297
profileName = "ci-test-bage";
298298
backendName = "supervisor";

nix/pkgs.nix

+27-18
Original file line numberDiff line numberDiff line change
@@ -79,34 +79,43 @@ final: prev: with final; {
7979
# A generic, parameteric version of the workbench development environment.
8080
workbench = pkgs.callPackage ./workbench {};
8181

82-
all-profiles-json = (workbench.all-profiles
83-
{ inherit (workbench-instance { backendName = "supervisor";
84-
profileName = "default-bage";
85-
}) backend; }).JSON;
82+
all-profiles-json = workbench.profile-names-json;
8683

8784
# A parametrisable workbench, that can be used with nix-shell or lorri.
8885
# See https://input-output-hk.github.io/haskell.nix/user-guide/development/
89-
workbench-instance =
86+
# The general idea is:
87+
# backendName -> useCabalRun -> backend
88+
# stateDir -> batchName -> profileName -> backend -> workbench -> runner
89+
# * `workbench` is in case a pinned version of the workbench is needed.
90+
workbench-runner =
9091
let backendRegistry =
9192
{
9293
supervisor = ./workbench/backend/supervisor.nix;
93-
nomad = ./workbench/backend/nomad.nix;
94+
nomad = ./workbench/backend/nomad.nix;
9495
};
9596
in
96-
{ backendName
97-
, profileName ? customConfig.localCluster.profileName
98-
, batchName ? customConfig.localCluster.batchName
99-
, useCabalRun ? false
100-
, workbenchDevMode ? false
101-
, profiled ? false
102-
, workbench ? pkgs.workbench
103-
, backendWorkbench ? pkgs.callPackage (backendRegistry."${backendName}")
104-
{ inherit useCabalRun workbench; }
105-
, cardano-node-rev ? null
97+
{ stateDir ? customConfig.localCluster.stateDir
98+
, batchName ? customConfig.localCluster.batchName
99+
, profileName ? customConfig.localCluster.profileName
100+
, backendName ? customConfig.localCluster.backendName
101+
, useCabalRun ? false
102+
, profiled ? false
103+
, cardano-node-rev ? null
104+
, workbench ? pkgs.workbench
105+
, workbenchDevMode ? false
106106
}:
107-
pkgs.callPackage ./workbench/backend/run.nix
107+
let
108+
# The `useCabalRun` flag is set in the backend to allow the backend to
109+
# override its value. The runner uses the value of `useCabalRun` from
110+
# the backend to prevent a runner using a different value.
111+
backend = import (backendRegistry."${backendName}")
112+
{ inherit pkgs lib useCabalRun; };
113+
in import ./workbench/backend/runner.nix
108114
{
109-
inherit batchName profileName backendWorkbench cardano-node-rev;
115+
inherit pkgs lib cardanoNodePackages;
116+
inherit stateDir batchName profileName backend;
117+
inherit cardano-node-rev;
118+
inherit workbench workbenchDevMode;
110119
};
111120

112121
# Disable failing python uvloop tests

nix/workbench/backend/nomad.nix

+46-65
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,60 @@
1-
let
2-
basePort = 30000;
3-
cacheDirDefault = "${__getEnv "HOME"}/.cache/cardano-workbench";
4-
stateDir = "run/current";
5-
in
61
{ pkgs
72
, lib
8-
, workbench
9-
##
10-
, cacheDir ? cacheDirDefault
11-
, extraBackendConfig ? {}
123
## `useCabalRun` not used here like in `supervisor.nix`.
134
, ...
145
}:
156
let
16-
backend =
17-
rec
18-
{ name = "nomad";
19-
20-
# Unlike the supervisor backend `useCabalRun` is always false here.
21-
useCabalRun = false;
7+
name = "nomad";
228

23-
services-config = import ./services-config.nix {inherit lib workbench basePort stateDir; useCabalRun = false;};
9+
# Unlike the supervisor backend `useCabalRun` is always false here.
10+
useCabalRun = false;
2411

25-
extraShellPkgs = with pkgs; [
26-
# https://docs.podman.io/en/latest/markdown/podman.1.html#rootless-mode
27-
podman
28-
# Was not needed even thou it says so!
29-
# https://docs.podman.io/en/latest/markdown/podman.1.html#note-unsupported-file-systems-in-rootless-mode
30-
# fuse-overlayfs
31-
nomad
32-
nomad-driver-podman
33-
];
12+
extraShellPkgs = with pkgs; [
13+
# https://docs.podman.io/en/latest/markdown/podman.1.html#rootless-mode
14+
podman
15+
# Was not needed even thou it says so!
16+
# https://docs.podman.io/en/latest/markdown/podman.1.html#note-unsupported-file-systems-in-rootless-mode
17+
# fuse-overlayfs
18+
nomad
19+
nomad-driver-podman
20+
];
3421

35-
materialise-profile =
36-
{ profileNix }:
37-
let
38-
supervisorConfPath =
39-
import ./supervisor-conf.nix
40-
{ inherit (profileNix) node-services;
41-
inherit
42-
pkgs lib stateDir
43-
basePort
44-
extraBackendConfig;
45-
unixHttpServerPort = "/tmp/supervisor.sock";
46-
};
47-
nomadConf =
48-
import ./nomad-conf.nix
49-
{ inherit pkgs;
50-
inherit
51-
(pkgs.cardanoNodePackages)
52-
cardano-node cardano-tracer tx-generator;
53-
};
54-
in pkgs.runCommand "workbench-backend-output-${profileNix.name}-${name}"
55-
(rec {
56-
inherit supervisorConfPath;
57-
# All In One
58-
clusterImage = nomadConf.clusterImage;
59-
clusterImageCopyToPodman = clusterImage.copyToPodman;
60-
clusterImageName = clusterImage.imageName;
61-
clusterImageTag = clusterImage.imageTag;
62-
})
63-
''
64-
mkdir $out
22+
materialise-profile =
23+
{ stateDir, profileNix }:
24+
let
25+
supervisorConfPath =
26+
import ./supervisor-conf.nix
27+
{ inherit (profileNix) node-services;
28+
inherit pkgs lib stateDir;
29+
unixHttpServerPort = "/tmp/supervisor.sock";
30+
};
31+
nomadConf =
32+
import ./nomad-conf.nix
33+
{ inherit pkgs;
34+
inherit
35+
(pkgs.cardanoNodePackages)
36+
cardano-node cardano-tracer tx-generator;
37+
};
38+
in pkgs.runCommand "workbench-backend-output-${profileNix.name}-${name}"
39+
(rec {
40+
inherit supervisorConfPath;
41+
# All In One
42+
clusterImage = nomadConf.clusterImage;
43+
clusterImageCopyToPodman = clusterImage.copyToPodman;
44+
clusterImageName = clusterImage.imageName;
45+
clusterImageTag = clusterImage.imageTag;
46+
})
47+
''
48+
mkdir $out
6549
66-
ln -s $supervisorConfPath $out/supervisor.conf
50+
ln -s $supervisorConfPath $out/supervisor.conf
6751
68-
ln -s $clusterImage $out/clusterImage
69-
echo $clusterImageName > $out/clusterImageName
70-
echo $clusterImageTag > $out/clusterImageTag
71-
ln -s $clusterImageCopyToPodman/bin/copy-to-podman $out/clusterImageCopyToPodman
72-
'';
73-
};
52+
ln -s $clusterImage $out/clusterImage
53+
echo $clusterImageName > $out/clusterImageName
54+
echo $clusterImageTag > $out/clusterImageTag
55+
ln -s $clusterImageCopyToPodman/bin/copy-to-podman $out/clusterImageCopyToPodman
56+
'';
7457
in
7558
{
76-
inherit cacheDir stateDir basePort;
77-
inherit workbench;
78-
inherit backend;
59+
inherit name useCabalRun extraShellPkgs materialise-profile;
7960
}

nix/workbench/backend/run.nix nix/workbench/backend/runner.nix

+19-24
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
let
2-
batchNameDefault = "plain";
3-
profileNameDefault = "default-bage";
4-
in
51
{ pkgs
2+
, lib
63
, cardanoNodePackages
7-
, backendWorkbench
84
##
9-
, profileName ? profileNameDefault
10-
, batchName ? batchNameDefault
5+
, stateDir
6+
, batchName
7+
, profileName
8+
, backend
119
##
12-
, workbenchDevMode ? false
1310
, cardano-node-rev ? "0000000000000000000000000000000000000000"
11+
, workbench
12+
, workbenchDevMode ? false
13+
##
14+
, cacheDir ? "${__getEnv "HOME"}/.cache/cardano-workbench"
15+
, basePort ? 30000
1416
}:
1517
let
16-
inherit (backendWorkbench) workbench backend cacheDir stateDir basePort;
17-
18-
backendName = backendWorkbench.backend.name;
18+
backendName = backend.name;
1919

20-
useCabalRun = backendWorkbench.backend.useCabalRun;
20+
inherit (backend) useCabalRun;
2121

22-
with-backend-profile =
23-
{ envArgsOverride ? {} }: ## TODO: envArgsOverride is not used!
24-
workbench.with-profile
25-
{ inherit backend profileName; };
22+
with-backend-profile = workbench.with-profile
23+
{ inherit stateDir profileName backend basePort workbench; };
2624

27-
inherit (with-backend-profile {}) profileNix profile topology genesis;
25+
inherit (with-backend-profile) profileNix profile topology genesis;
2826
in
2927
let
3028

@@ -74,8 +72,7 @@ in
7472
{ trace ? false }:
7573
let
7674
inherit
77-
(with-backend-profile
78-
{ envArgsOverride = { cacheDir = "./cache"; stateDir = "./"; }; })
75+
(with-backend-profile)
7976
profileNix profile topology genesis;
8077

8178
run = pkgs.runCommand "workbench-run-${backendName}-${profileName}"
@@ -93,7 +90,7 @@ in
9390
zstd
9491
]
9592
++
96-
backendWorkbench.backend.extraShellPkgs
93+
backend.extraShellPkgs
9794
;
9895
}
9996
''
@@ -148,10 +145,8 @@ in
148145
};
149146
in
150147
{
151-
inherit stateDir;
152-
inherit profileName;
153-
inherit workbench backendWorkbench;
154-
inherit (backendWorkbench) backend;
148+
inherit stateDir batchName profileName backend;
149+
inherit workbench;
155150
inherit profileNix profile topology genesis;
156151
inherit interactive-start interactive-stop interactive-restart;
157152
inherit profile-run;

nix/workbench/backend/supervisor-conf.nix

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
{ pkgs
22
, lib
33
, stateDir
4-
, basePort
54
, node-services
65
, unixHttpServerPort ? null
76
, inetHttpServerPort ? null
8-
## Last-moment overrides:
9-
, extraBackendConfig
107
}:
118

129
with lib;
@@ -71,9 +68,7 @@ let
7168
stopasgroup = true;
7269
killasgroup = true;
7370
};
74-
}
75-
//
76-
extraBackendConfig;
71+
};
7772

7873
##
7974
## nodeSvcSupervisorProgram :: NodeService -> SupervisorConfSection

0 commit comments

Comments
 (0)