about summary refs log tree commit diff
path: root/nix
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2024-02-13T16·14+0100
committerclbot <clbot@tvl.fyi>2024-03-02T23·01+0000
commitaa14e36a91a5a54ad39161b6b0f2d3c951b33d9d (patch)
tree723e752a29915692f5ac4c1742499e2c6e6772dd /nix
parent53fb9ff4c6a2aaa4e0eaa1fe782b3104b95e5fe8 (diff)
refactor(nix/buildkite): make more use of formal arguments r/7628
When changing the buildkite pipeline code I found that some functions
have a lot of arguments where the order is not necessarily clear. To
ease further refactors / new features, I've ported them over to taking
attribute sets.

Note that this technically is a breaking change, as these functions are
all exposed. Not sure how often they'd be called from the outside,
though.

Change-Id: I118c8c5242922403d12f6e5a61beaf68f636b40a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10847
Autosubmit: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'nix')
-rw-r--r--nix/buildkite/default.nix18
1 files changed, 10 insertions, 8 deletions
diff --git a/nix/buildkite/default.nix b/nix/buildkite/default.nix
index c53d58eecd..892f49f963 100644
--- a/nix/buildkite/default.nix
+++ b/nix/buildkite/default.nix
@@ -46,13 +46,13 @@ rec {
 
   # Determine whether to skip a target if it has not diverged from the
   # HEAD branch.
-  shouldSkip = parentTargetMap: label: drvPath:
+  shouldSkip = { parentTargetMap ? { }, label, drvPath }:
     if (hasAttr label parentTargetMap) && parentTargetMap."${label}".drvPath == drvPath
     then "Target has not changed."
     else false;
 
   # Create build command for a derivation target.
-  mkBuildCommand = target: drvPath: concatStringsSep " " [
+  mkBuildCommand = { target, drvPath }: concatStringsSep " " [
     # First try to realise the drvPath of the target so we don't evaluate twice.
     # Nix has no concept of depending on a derivation file without depending on
     # at least one of its `outPath`s, so we need to discard the string context
@@ -66,17 +66,16 @@ rec {
   ];
 
   # Create a pipeline step from a single target.
-  mkStep = headBranch: parentTargetMap: target: cancelOnBuildFailing:
+  mkStep = { headBranch, parentTargetMap, target, cancelOnBuildFailing }:
     let
       label = mkLabel target;
       drvPath = unsafeDiscardStringContext target.drvPath;
-      shouldSkip' = shouldSkip parentTargetMap;
     in
     {
       label = ":nix: " + label;
       key = hashString "sha1" label;
-      skip = shouldSkip' label drvPath;
-      command = mkBuildCommand target drvPath;
+      skip = shouldSkip { inherit label drvPath parentTargetMap; };
+      command = mkBuildCommand { inherit target drvPath; };
       env.READTREE_TARGET = label;
       cancel_on_build_failing = cancelOnBuildFailing;
 
@@ -190,14 +189,17 @@ rec {
       # phase (as phases end up in different chunks).
       targetToSteps = target:
         let
-          step = mkStep headBranch parentTargetMap target cancelOnBuildFailing;
+          mkStepArgs = {
+            inherit headBranch parentTargetMap target cancelOnBuildFailing;
+          };
+          step = mkStep mkStepArgs;
 
           # Same step, but with an override function applied. This is
           # used in mkExtraStep if the extra step needs to modify the
           # parent derivation somehow.
           #
           # Note that this will never affect the label.
-          overridable = f: mkStep headBranch parentTargetMap (f target) cancelOnBuildFailing;
+          overridable = f: mkStep (mkStepArgs // { target = (f target); });
 
           # Split extra steps by phase.
           splitExtraSteps = lib.groupBy ({ phase, ... }: phase)