From aa14e36a91a5a54ad39161b6b0f2d3c951b33d9d Mon Sep 17 00:00:00 2001 From: sterni Date: Tue, 13 Feb 2024 17:14:08 +0100 Subject: refactor(nix/buildkite): make more use of formal arguments 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 Tested-by: BuildkiteCI Reviewed-by: tazjin --- nix/buildkite/default.nix | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'nix') diff --git a/nix/buildkite/default.nix b/nix/buildkite/default.nix index c53d58eecdae..892f49f9639a 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) -- cgit 1.4.1