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 <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
sterni 2024-02-13 17:14:08 +01:00 committed by clbot
parent 53fb9ff4c6
commit aa14e36a91

View file

@ -46,13 +46,13 @@ rec {
# Determine whether to skip a target if it has not diverged from the # Determine whether to skip a target if it has not diverged from the
# HEAD branch. # HEAD branch.
shouldSkip = parentTargetMap: label: drvPath: shouldSkip = { parentTargetMap ? { }, label, drvPath }:
if (hasAttr label parentTargetMap) && parentTargetMap."${label}".drvPath == drvPath if (hasAttr label parentTargetMap) && parentTargetMap."${label}".drvPath == drvPath
then "Target has not changed." then "Target has not changed."
else false; else false;
# Create build command for a derivation target. # 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. # 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 # 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 # 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. # Create a pipeline step from a single target.
mkStep = headBranch: parentTargetMap: target: cancelOnBuildFailing: mkStep = { headBranch, parentTargetMap, target, cancelOnBuildFailing }:
let let
label = mkLabel target; label = mkLabel target;
drvPath = unsafeDiscardStringContext target.drvPath; drvPath = unsafeDiscardStringContext target.drvPath;
shouldSkip' = shouldSkip parentTargetMap;
in in
{ {
label = ":nix: " + label; label = ":nix: " + label;
key = hashString "sha1" label; key = hashString "sha1" label;
skip = shouldSkip' label drvPath; skip = shouldSkip { inherit label drvPath parentTargetMap; };
command = mkBuildCommand target drvPath; command = mkBuildCommand { inherit target drvPath; };
env.READTREE_TARGET = label; env.READTREE_TARGET = label;
cancel_on_build_failing = cancelOnBuildFailing; cancel_on_build_failing = cancelOnBuildFailing;
@ -190,14 +189,17 @@ rec {
# phase (as phases end up in different chunks). # phase (as phases end up in different chunks).
targetToSteps = target: targetToSteps = target:
let 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 # Same step, but with an override function applied. This is
# used in mkExtraStep if the extra step needs to modify the # used in mkExtraStep if the extra step needs to modify the
# parent derivation somehow. # parent derivation somehow.
# #
# Note that this will never affect the label. # 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. # Split extra steps by phase.
splitExtraSteps = lib.groupBy ({ phase, ... }: phase) splitExtraSteps = lib.groupBy ({ phase, ... }: phase)