Skip to content

Commit

Permalink
wb | indentation and cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaste committed Sep 20, 2024
1 parent 5c35c24 commit 539fa09
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 60 deletions.
14 changes: 7 additions & 7 deletions nix/pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions nix/workbench/backend/runner.nix
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down
102 changes: 59 additions & 43 deletions nix/workbench/default.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{ pkgs
, lib
{ pkgs, lib
, cardanoNodePackages
, cardanoNodeProject
}:

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";
Expand Down Expand Up @@ -45,44 +48,75 @@ 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 {} ''
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;

# 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 =
Expand All @@ -106,43 +140,27 @@ 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:
# 1. profileName -> profiling -> profile
# 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.
Expand All @@ -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;
};
})
3 changes: 1 addition & 2 deletions nix/workbench/profile/profile.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{ pkgs, lib
, workbenchNix
, profileName
, profiling
, profileName, profiling
}:

let
Expand Down

0 comments on commit 539fa09

Please sign in to comment.