Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaste committed Sep 15, 2024
1 parent 94c2406 commit bef86e5
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 58 deletions.
7 changes: 5 additions & 2 deletions nix/pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ in with final;
name = profileName;
value =
let
profile = workbench.profile {inherit profileName;};
profile = workbench.profile
{ inherit profileName;
inherit (customConfig) profiling;
};
backend = workbench.backend
{ backendName = "nomadcloud";
stateDir = customConfig.localCluster.stateDir;
Expand All @@ -144,7 +147,7 @@ in with final;
}
;
profileData = profile.materialise-profile
{ inherit backend; inherit (customConfig) profiling; }
{ inherit backend; }
;
backendData = backend.materialise-profile {inherit profileData;};
in pkgs.runCommand "workbench-data-${profileName}" {}
Expand Down
31 changes: 27 additions & 4 deletions nix/workbench/backend/runner.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,32 @@ let
backendName = backend.name;
inherit (backend) stateDir basePort useCabalRun;

profileData = profile.materialise-profile
{ inherit backend; };
backendData = backend.materialise-profile
{ inherit profileData; };
data =
if cardano-node-rev == null || cardano-node-rev == pkgs.gitrev
# Same commit.
then
{ useNodeRev = false;
profileData = profile.materialise-profile
{ inherit backend; };
backendData = backend.materialise-profile
{ inherit profileData; };
}
# WARNING!
else
# Backend parameters must be the default ones.
if (__trace stateDir stateDir) != "run/current" || (__trace basePort basePort) != 30000
then throw "Unsupported combination"
else
let workbench-data = (__getFlake "github:intersectmbo/cardano-node/${cardano-node-rev}").packages.${builtins.currentSystem}.profile-data.${profileName};
in
{ useNodeRev = true;
profileData = "${workbench-data}/profileData";
backendData = "${workbench-data}/backendData";
}
;

inherit (data) useNodeRev profileData backendData;

in
let

Expand All @@ -47,6 +69,7 @@ in
--backend-data ${backendData} \
--cache-dir ${cacheDir} \
--base-port ${toString basePort} \
${pkgs.lib.optionalString useNodeRev ''--node-rev ${cardano-node-rev}''} \
${pkgs.lib.optionalString useCabalRun ''--cabal''} \
${__concatStringsSep " " workbenchStartArgs} \
"$@"
Expand Down
158 changes: 106 additions & 52 deletions nix/workbench/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,51 @@
with lib;

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

workbench' = tools:
pkgs.stdenv.mkDerivation {
pname = "workbench";
# Workbench derivation and function to create derivations from `wb` commands.
##############################################################################

version = "0.1";

src = ./.;

buildInputs = with pkgs; [ makeWrapper ];

buildPhase = ''
patchShebangs .
'';

postFixup = ''
wrapProgram "$out/bin/wb" \
--argv0 wb \
--prefix PATH ":" ${makeBinPath tools} \
--set WB_CHAP_PATH ${chap} \
--set WB_NIX_PLAN ${nixPlanJson}
'';

installPhase = ''
mkdir -p $out/bin
cp -a wb ede profile $out/bin
for dir in . analyse backend genesis topology
do cp -a $dir/* $out/bin/$dir
done
'';

dontStrip = true;
};
workbench' =
let
# recover CHaP location from cardano's project
chap = cardanoNodeProject.args.inputMap."https://chap.intersectmbo.org/";
# build plan as computed by nix
nixPlanJson = cardanoNodeProject.plan-nix.json;
in tools:
pkgs.stdenv.mkDerivation {
pname = "workbench";

version = "0.1";

src = ./.;

buildInputs = with pkgs; [ makeWrapper ];

buildPhase = ''
patchShebangs .
'';

postFixup = ''
wrapProgram "$out/bin/wb" \
--argv0 wb \
--prefix PATH ":" ${makeBinPath tools} \
--set WB_CHAP_PATH ${chap} \
--set WB_NIX_PLAN ${nixPlanJson}
'';

installPhase = ''
mkdir -p $out/bin
cp -a wb ede profile $out/bin
for dir in . analyse backend genesis topology
do cp -a $dir/* $out/bin/$dir
done
'';

dontStrip = true;
}
;

# Workbench with its dependencies to call from Nix.
workbench = with cardanoNodePackages; with pkgs; workbench' (
[ git graphviz
jq
Expand All @@ -58,30 +65,50 @@ let
);

runWorkbench =
name: command:
name: command: # Name of the derivation and `wb` command to run.
pkgs.runCommand name {} ''
${workbench}/bin/wb ${command} > $out
'';

# Helper functions.
##############################################################################

runJq =
name: args: query:
pkgs.runCommand name {} ''
args=(${args})
${pkgs.jq}/bin/jq '${query}' "''${args[@]}" > $out
'';

profile-names-json =
runWorkbench "profile-names.json" "profiles list";
# Auxiliary functions of `wb` commands.
##############################################################################

profile-names = __fromJSON (__readFile profile-names-json);

profile-names =
__fromJSON (__readFile profile-names-json);
profile-names-json = runWorkbench "profile-names.json" "profiles list";

# Output
################################################################################
in pkgs.lib.fix (self: {
inherit cardanoNodePackages;
inherit workbench' workbench runWorkbench;
inherit runJq;

inherit profile-names-json profile-names;
inherit profile-names profile-names-json;

# Return a profile attr with a `materialise-profile` function.
# profileName -> profiling -> profile
profile =
{ profileName
, profiling
}:
(import ./profile/profile.nix
{ inherit pkgs lib;
workbenchNix = self;
inherit profileName profiling;
}
)
;

# Return a backend attr with a `materialise-profile` function.
# backendName -> stateDir -> basePort -> useCabalRun -> backend
Expand All @@ -106,18 +133,29 @@ in pkgs.lib.fix (self: {
{ inherit pkgs lib stateDir basePort useCabalRun; }
;

# Return a profile attr with a `materialise-profile` function.
# profileName -> profiling -> profile
profile =
data =
{ profileName
, profiling
, backendName
, stateDir
, basePort
, useCabalRun
}:
(import ./profile/profile.nix
{ inherit pkgs lib;
workbenchNix = self;
inherit profileName profiling;
}
)
let
profile = self.profile
{ inherit profileName profiling; }
;
backend = self.backend
{ inherit backendName stateDir basePort useCabalRun; }
;
in rec {
profileData = profile.materialise-profile
{ inherit backend; }
;
backendData = backend.materialise-profile
{ inherit profileData; }
;
}
;

# A conveniently-parametrisable workbench preset.
Expand Down Expand Up @@ -153,10 +191,26 @@ in pkgs.lib.fix (self: {
{
inherit pkgs lib;
inherit profile backend;
inherit batchName;
inherit cardano-node-rev;
inherit workbench; # The derivation.
inherit cardanoNodePackages;
inherit cardano-node-rev;
inherit batchName;
inherit workbenchDevMode workbenchStartArgs;
};
})


# TODO: Use "own" `customConfig`
# customConfig = rec {
# profileName = "default-coay";
# backendName = "supervisor";
# stateDir = "run/current";
# cacheDir = "${stateDir}/.cache";
# basePort = 30000;
# useCabalRun = true;
# batchName = "undefined";
# workbenchDevMode = true;
# workbenchStartArgs = [];
# extraBackendConfig = {};
# profiling = "none";
# };
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ let
workbench-runner = pkgs.custom-config-workbench-runner
{ inherit profileName backendName useCabalRun;
profiling = profilingEff;
cardano-node-rev = "8da106d9ff3c10d283f6d985d3acb77820cb8f51";
};
};

Expand Down

0 comments on commit bef86e5

Please sign in to comment.