Skip to content

Commit

Permalink
workbench: refactoring of modules dependencies
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
fmaste committed Dec 5, 2022
1 parent 9100ae5 commit 5c4ff32
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 245 deletions.
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
benchmarks = collectComponents' "benchmarks" projectPackages;
});

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

packages =
exes
Expand All @@ -292,7 +292,7 @@

## This is a very light profile, no caching&pinning needed.
workbench-ci-test =
(pkgs.workbench-instance
(pkgs.workbench-runner
{
profileName = "ci-test-bage";
backendName = "supervisor";
Expand Down
45 changes: 27 additions & 18 deletions nix/pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -79,34 +79,43 @@ final: prev: with final; {
# A generic, parameteric version of the workbench development environment.
workbench = pkgs.callPackage ./workbench {};

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

# A parametrisable workbench, that can be used with nix-shell or lorri.
# See https://input-output-hk.github.io/haskell.nix/user-guide/development/
workbench-instance =
# The general idea is:
# backendName -> useCabalRun -> backend
# stateDir -> batchName -> profileName -> backend -> workbench -> runner
# * `workbench` is in case a pinned version of the workbench is needed.
workbench-runner =
let backendRegistry =
{
supervisor = ./workbench/backend/supervisor.nix;
nomad = ./workbench/backend/nomad.nix;
nomad = ./workbench/backend/nomad.nix;
};
in
{ backendName
, profileName ? customConfig.localCluster.profileName
, batchName ? customConfig.localCluster.batchName
, useCabalRun ? false
, workbenchDevMode ? false
, profiled ? false
, workbench ? pkgs.workbench
, backendWorkbench ? pkgs.callPackage (backendRegistry."${backendName}")
{ inherit useCabalRun workbench; }
, cardano-node-rev ? null
{ stateDir ? customConfig.localCluster.stateDir
, batchName ? customConfig.localCluster.batchName
, profileName ? customConfig.localCluster.profileName
, backendName ? customConfig.localCluster.backendName
, useCabalRun ? false
, profiled ? false
, cardano-node-rev ? null
, workbench ? pkgs.workbench
, workbenchDevMode ? false
}:
pkgs.callPackage ./workbench/backend/run.nix
let
# The `useCabalRun` flag is set in the backend to allow the backend to
# override its value. The runner uses the value of `useCabalRun` from
# the backend to prevent a runner using a different value.
backend = import (backendRegistry."${backendName}")
{ inherit pkgs lib useCabalRun; };
in import ./workbench/backend/runner.nix
{
inherit batchName profileName backendWorkbench cardano-node-rev;
inherit pkgs lib cardanoNodePackages;
inherit stateDir batchName profileName backend;
inherit cardano-node-rev;
inherit workbench workbenchDevMode;
};

# Disable failing python uvloop tests
Expand Down
111 changes: 46 additions & 65 deletions nix/workbench/backend/nomad.nix
Original file line number Diff line number Diff line change
@@ -1,79 +1,60 @@
let
basePort = 30000;
cacheDirDefault = "${__getEnv "HOME"}/.cache/cardano-workbench";
stateDir = "run/current";
in
{ pkgs
, lib
, workbench
##
, cacheDir ? cacheDirDefault
, extraBackendConfig ? {}
## `useCabalRun` not used here like in `supervisor.nix`.
, ...
}:
let
backend =
rec
{ name = "nomad";

# Unlike the supervisor backend `useCabalRun` is always false here.
useCabalRun = false;
name = "nomad";

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

extraShellPkgs = with pkgs; [
# https://docs.podman.io/en/latest/markdown/podman.1.html#rootless-mode
podman
# Was not needed even thou it says so!
# https://docs.podman.io/en/latest/markdown/podman.1.html#note-unsupported-file-systems-in-rootless-mode
# fuse-overlayfs
nomad
nomad-driver-podman
];
extraShellPkgs = with pkgs; [
# https://docs.podman.io/en/latest/markdown/podman.1.html#rootless-mode
podman
# Was not needed even thou it says so!
# https://docs.podman.io/en/latest/markdown/podman.1.html#note-unsupported-file-systems-in-rootless-mode
# fuse-overlayfs
nomad
nomad-driver-podman
];

materialise-profile =
{ profileNix }:
let
supervisorConfPath =
import ./supervisor-conf.nix
{ inherit (profileNix) node-services;
inherit
pkgs lib stateDir
basePort
extraBackendConfig;
unixHttpServerPort = "/tmp/supervisor.sock";
};
nomadConf =
import ./nomad-conf.nix
{ inherit pkgs;
inherit
(pkgs.cardanoNodePackages)
cardano-node cardano-tracer tx-generator;
};
in pkgs.runCommand "workbench-backend-output-${profileNix.name}-${name}"
(rec {
inherit supervisorConfPath;
# All In One
clusterImage = nomadConf.clusterImage;
clusterImageCopyToPodman = clusterImage.copyToPodman;
clusterImageName = clusterImage.imageName;
clusterImageTag = clusterImage.imageTag;
})
''
mkdir $out
materialise-profile =
{ stateDir, profileNix }:
let
supervisorConfPath =
import ./supervisor-conf.nix
{ inherit (profileNix) node-services;
inherit pkgs lib stateDir;
unixHttpServerPort = "/tmp/supervisor.sock";
};
nomadConf =
import ./nomad-conf.nix
{ inherit pkgs;
inherit
(pkgs.cardanoNodePackages)
cardano-node cardano-tracer tx-generator;
};
in pkgs.runCommand "workbench-backend-output-${profileNix.name}-${name}"
(rec {
inherit supervisorConfPath;
# All In One
clusterImage = nomadConf.clusterImage;
clusterImageCopyToPodman = clusterImage.copyToPodman;
clusterImageName = clusterImage.imageName;
clusterImageTag = clusterImage.imageTag;
})
''
mkdir $out
ln -s $supervisorConfPath $out/supervisor.conf
ln -s $supervisorConfPath $out/supervisor.conf
ln -s $clusterImage $out/clusterImage
echo $clusterImageName > $out/clusterImageName
echo $clusterImageTag > $out/clusterImageTag
ln -s $clusterImageCopyToPodman/bin/copy-to-podman $out/clusterImageCopyToPodman
'';
};
ln -s $clusterImage $out/clusterImage
echo $clusterImageName > $out/clusterImageName
echo $clusterImageTag > $out/clusterImageTag
ln -s $clusterImageCopyToPodman/bin/copy-to-podman $out/clusterImageCopyToPodman
'';
in
{
inherit cacheDir stateDir basePort;
inherit workbench;
inherit backend;
inherit name useCabalRun extraShellPkgs materialise-profile;
}
43 changes: 19 additions & 24 deletions nix/workbench/backend/run.nix → nix/workbench/backend/runner.nix
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
let
batchNameDefault = "plain";
profileNameDefault = "default-bage";
in
{ pkgs
, lib
, cardanoNodePackages
, backendWorkbench
##
, profileName ? profileNameDefault
, batchName ? batchNameDefault
, stateDir
, batchName
, profileName
, backend
##
, workbenchDevMode ? false
, cardano-node-rev ? "0000000000000000000000000000000000000000"
, workbench
, workbenchDevMode ? false
##
, cacheDir ? "${__getEnv "HOME"}/.cache/cardano-workbench"
, basePort ? 30000
}:
let
inherit (backendWorkbench) workbench backend cacheDir stateDir basePort;

backendName = backendWorkbench.backend.name;
backendName = backend.name;

useCabalRun = backendWorkbench.backend.useCabalRun;
inherit (backend) useCabalRun;

with-backend-profile =
{ envArgsOverride ? {} }: ## TODO: envArgsOverride is not used!
workbench.with-profile
{ inherit backend profileName; };
with-backend-profile = workbench.with-profile
{ inherit stateDir profileName backend basePort workbench; };

inherit (with-backend-profile {}) profileNix profile topology genesis;
inherit (with-backend-profile) profileNix profile topology genesis;
in
let

Expand Down Expand Up @@ -74,8 +72,7 @@ in
{ trace ? false }:
let
inherit
(with-backend-profile
{ envArgsOverride = { cacheDir = "./cache"; stateDir = "./"; }; })
(with-backend-profile)
profileNix profile topology genesis;

run = pkgs.runCommand "workbench-run-${backendName}-${profileName}"
Expand All @@ -93,7 +90,7 @@ in
zstd
]
++
backendWorkbench.backend.extraShellPkgs
backend.extraShellPkgs
;
}
''
Expand Down Expand Up @@ -148,10 +145,8 @@ in
};
in
{
inherit stateDir;
inherit profileName;
inherit workbench backendWorkbench;
inherit (backendWorkbench) backend;
inherit stateDir batchName profileName backend;
inherit workbench;
inherit profileNix profile topology genesis;
inherit interactive-start interactive-stop interactive-restart;
inherit profile-run;
Expand Down
7 changes: 1 addition & 6 deletions nix/workbench/backend/supervisor-conf.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{ pkgs
, lib
, stateDir
, basePort
, node-services
, unixHttpServerPort ? null
, inetHttpServerPort ? null
## Last-moment overrides:
, extraBackendConfig
}:

with lib;
Expand Down Expand Up @@ -71,9 +68,7 @@ let
stopasgroup = true;
killasgroup = true;
};
}
//
extraBackendConfig;
};

##
## nodeSvcSupervisorProgram :: NodeService -> SupervisorConfSection
Expand Down
Loading

0 comments on commit 5c4ff32

Please sign in to comment.