From bef86e5b2f35edfb21fb2bdbd915c46eb3f98d0e Mon Sep 17 00:00:00 2001 From: Federico Mastellone Date: Sun, 15 Sep 2024 12:04:37 +0000 Subject: [PATCH] WIP --- nix/pkgs.nix | 7 +- nix/workbench/backend/runner.nix | 31 +++++- nix/workbench/default.nix | 158 +++++++++++++++++++++---------- shell.nix | 1 + 4 files changed, 139 insertions(+), 58 deletions(-) diff --git a/nix/pkgs.nix b/nix/pkgs.nix index c5b80839871..ae032d744e7 100644 --- a/nix/pkgs.nix +++ b/nix/pkgs.nix @@ -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; @@ -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}" {} diff --git a/nix/workbench/backend/runner.nix b/nix/workbench/backend/runner.nix index be63e8ab056..abe659674f9 100644 --- a/nix/workbench/backend/runner.nix +++ b/nix/workbench/backend/runner.nix @@ -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 @@ -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} \ "$@" diff --git a/nix/workbench/default.nix b/nix/workbench/default.nix index f657a47333b..575343dbf88 100644 --- a/nix/workbench/default.nix +++ b/nix/workbench/default.nix @@ -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 @@ -58,11 +65,14 @@ 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 {} '' @@ -70,18 +80,35 @@ let ${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 @@ -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. @@ -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"; +# }; diff --git a/shell.nix b/shell.nix index 73cede3d48c..d582cf1691a 100644 --- a/shell.nix +++ b/shell.nix @@ -80,6 +80,7 @@ let workbench-runner = pkgs.custom-config-workbench-runner { inherit profileName backendName useCabalRun; profiling = profilingEff; + cardano-node-rev = "8da106d9ff3c10d283f6d985d3acb77820cb8f51"; }; };