From dce1a7480c283e5298f5f8ecdb1df95f164c7576 Mon Sep 17 00:00:00 2001 From: sterni Date: Sat, 9 Mar 2024 13:15:34 +0100 Subject: feat(nix/buildkite): use keys based on drvPaths where possible This will make it easier to emit intra pipeline dependencies based on the dependencies between derivations contained therein later. A consequence of this change is that it is no longer possible to have the same derivation be exposed as multiple steps in the pipeline. I doubt that having this is very useful, though. Keys for extraSteps are not changed significantly, but are distinguished from derivation based steps (with prefix `drv-*`) by their prefix `extra-step-*`. Change-Id: I4165900e512b3967fa3ca4cd5bffd44bc15915fc Reviewed-on: https://cl.tvl.fyi/c/depot/+/11115 Autosubmit: sterni Reviewed-by: ezemtsov Tested-by: BuildkiteCI --- nix/buildkite/default.nix | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'nix') diff --git a/nix/buildkite/default.nix b/nix/buildkite/default.nix index b7715e902f..cb40fb9623 100644 --- a/nix/buildkite/default.nix +++ b/nix/buildkite/default.nix @@ -29,6 +29,23 @@ let inherit (depot.nix.readTree) mkLabel; in rec { + # Create a unique key for the buildkite pipeline based on the given derivation + # or drvPath. A consequence of using such keys is that every derivation may + # only be exposed as a single, unique step in the pipeline. + keyForDrv = drvOrPath: + let + drvPath = + if lib.isDerivation drvOrPath then drvOrPath.drvPath + else if lib.isString drvOrPath then drvOrPath + else builtins.throw "keyForDrv: expected string or derivation"; + + # Only use the drv hash to prevent escaping problems. Buildkite also has a + # limit of 100 characters on keys. + in + "drv-" + (builtins.substring 0 32 + (builtins.baseNameOf (unsafeDiscardStringContext drvPath)) + ); + # Given an arbitrary attribute path generate a Nix expression which obtains # this from the root of depot (assumed to be ./.). Attributes may be any # Nix strings suitable as attribute names, not just Nix literal-safe strings. @@ -81,7 +98,7 @@ rec { in { label = ":nix: " + label; - key = hashString "sha1" label; + key = keyForDrv target; skip = shouldSkip { inherit label drvPath parentTargetMap; }; command = mkBuildCommand { attrPath = targetAttrPath target; @@ -394,7 +411,7 @@ rec { commandScriptLink = "nix-buildkite-extra-step-command-script"; step = { - key = hashString "sha1" "${cfg.label}-${cfg.parentLabel}"; + key = "extra-step-" + hashString "sha1" "${cfg.label}-${cfg.parentLabel}"; label = ":gear: ${cfg.label} (from ${cfg.parentLabel})"; skip = let -- cgit 1.4.1