diff --git a/nix/pkgs.nix b/nix/pkgs.nix index 1228fda671f..95105eac31f 100644 --- a/nix/pkgs.nix +++ b/nix/pkgs.nix @@ -6,26 +6,26 @@ let inherit (prev.pkgs) lib; inherit (prev) customConfig; - # A generic, fully parameteric version of the workbench development environment. + # A generic, fully parametric version of the workbench development environment. workbench = import ./workbench {inherit pkgs lib; inherit (final) cardanoNodePackages cardanoNodeProject;}; # Workbench runner instantiated by parameters from customConfig: workbench-runner = - { stateDir ? customConfig.localCluster.stateDir - , batchName ? customConfig.localCluster.batchName - , profileName ? customConfig.localCluster.profileName + { profileName ? customConfig.localCluster.profileName + , profiling ? customConfig.profiling , backendName ? customConfig.localCluster.backendName + , stateDir ? customConfig.localCluster.stateDir , basePort ? customConfig.localCluster.basePort , useCabalRun ? customConfig.localCluster.useCabalRun , workbenchDevMode ? customConfig.localCluster.workbenchDevMode + , batchName ? customConfig.localCluster.batchName , workbenchStartArgs ? customConfig.localCluster.workbenchStartArgs - , profiling ? customConfig.profiling , cardano-node-rev ? null }: workbench.runner - { inherit stateDir batchName profileName backendName basePort useCabalRun; - inherit workbenchDevMode workbenchStartArgs profiling cardano-node-rev; + { inherit profileName profiling backendName stateDir basePort useCabalRun; + inherit batchName workbenchDevMode workbenchStartArgs cardano-node-rev; }; in with final; diff --git a/nix/workbench/backend/runner.nix b/nix/workbench/backend/runner.nix index cb1e80aa4ff..c4bcde5f773 100644 --- a/nix/workbench/backend/runner.nix +++ b/nix/workbench/backend/runner.nix @@ -1,17 +1,15 @@ -{ pkgs -, lib +{ pkgs, lib ## , profile , backend -, batchName ## -, cardano-node-rev -, workbench -, cardanoNodePackages +, workbench # The derivation. , workbenchDevMode +, cardanoNodePackages # The binaries to use when calling the workbench. +, batchName , workbenchStartArgs ## -, cacheDir ? "${__getEnv "HOME"}/.cache/cardano-workbench" +, cardano-node-rev }: let profileName = profile.name; @@ -33,7 +31,7 @@ in ## In dev mode, call the script directly: ++ pkgs.lib.optionals (!workbenchDevMode) [ workbench ]; - + cacheDir = "${__getEnv "HOME"}/.cache/cardano-workbench"; workbench-interactive-start = pkgs.writeScriptBin "start-cluster" '' set -euo pipefail diff --git a/nix/workbench/default.nix b/nix/workbench/default.nix index f657a47333b..92691dffd9a 100644 --- a/nix/workbench/default.nix +++ b/nix/workbench/default.nix @@ -1,5 +1,4 @@ -{ pkgs -, lib +{ pkgs, lib , cardanoNodePackages , cardanoNodeProject }: @@ -7,11 +6,15 @@ 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 derivation and functions to create derivations from `wb` commands. + ############################################################################## + workbench' = tools: pkgs.stdenv.mkDerivation { pname = "workbench"; @@ -45,24 +48,37 @@ let dontStrip = true; }; - workbench = with cardanoNodePackages; with pkgs; workbench' ( - [ git graphviz - jq - moreutils - procps - cardano-cli - cardano-profile - cardano-topology - ] ++ lib.optional (!pkgs.stdenv.hostPlatform.isDarwin) db-analyser - ++ [ locli ] + # Workbench with its dependencies to call from Nix. + workbench = workbench' ( + (with pkgs; + [ git graphviz + jq + moreutils + procps + ] + ) + ++ + (with cardanoNodePackages; + [ + cardano-cli + cardano-profile + cardano-topology + locli + ] + ) + ++ + lib.optional (!pkgs.stdenv.hostPlatform.isDarwin) pkgs.db-analyser ); 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,19 +86,37 @@ 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; + # 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 backend = @@ -106,20 +140,6 @@ in pkgs.lib.fix (self: { { inherit pkgs lib stateDir basePort useCabalRun; } ; - # 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; - } - ) - ; - # A conveniently-parametrisable workbench preset. # See https://input-output-hk.github.io/haskell.nix/user-guide/development/ # The general idea is: @@ -127,22 +147,20 @@ in pkgs.lib.fix (self: { # 2. backendName -> stateDir -> basePort -> useCabalRun -> backend # 3. profile -> backend -> batchName -> runner runner = - { stateDir - , batchName - , profileName + { profileName + , profiling , backendName + , stateDir , basePort , useCabalRun , workbenchDevMode + , batchName , workbenchStartArgs - , profiling , cardano-node-rev }: let # Only a name needed to create a profile attrset. - profile = self.profile - { inherit profileName profiling; } - ; + profile = self.profile { inherit profileName profiling; }; # 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. @@ -153,10 +171,8 @@ in pkgs.lib.fix (self: { { inherit pkgs lib; inherit profile backend; - inherit batchName; + inherit workbench workbenchDevMode cardanoNodePackages; + inherit batchName workbenchStartArgs; inherit cardano-node-rev; - inherit workbench; # The derivation. - inherit cardanoNodePackages; - inherit workbenchDevMode workbenchStartArgs; }; }) diff --git a/nix/workbench/profile/profile.nix b/nix/workbench/profile/profile.nix index 278da951851..cdbcbf7d35a 100644 --- a/nix/workbench/profile/profile.nix +++ b/nix/workbench/profile/profile.nix @@ -1,7 +1,6 @@ { pkgs, lib , workbenchNix -, profileName -, profiling +, profileName, profiling }: let