diff options
author | sterni <sternenseemann@systemli.org> | 2024-02-13T16·36+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-03-02T23·32+0000 |
commit | 206742949bd8778e3209592f275dd29774c909c7 (patch) | |
tree | 556696d3b89749027ec2a49e383dc3e5c63f643f | |
parent | aa14e36a91a5a54ad39161b6b0f2d3c951b33d9d (diff) |
refactor(nix/buildkite): use attr path over target drv in mkBuild* r/7629
mkBuild* is independent of the target abstraction, we can just use attribute paths. That is useful because we'll want to reuse that code in order to avoid building derivations (apart from unavoidable IfD) during pipeline construction for extraSteps. Breaking Change for mkBuildExpr and mkBuildCommand. Change-Id: I03646310192087d3e50f358a714472d1ac1a652f Reviewed-on: https://cl.tvl.fyi/c/depot/+/10848 Tested-by: BuildkiteCI Autosubmit: sterni <sternenseemann@systemli.org> Reviewed-by: tazjin <tazjin@tvl.su>
-rw-r--r-- | nix/buildkite/default.nix | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/nix/buildkite/default.nix b/nix/buildkite/default.nix index 892f49f9639a..e45deade4bea 100644 --- a/nix/buildkite/default.nix +++ b/nix/buildkite/default.nix @@ -29,20 +29,14 @@ let inherit (depot.nix.readTree) mkLabel; in rec { - # Creates a Nix expression that yields the target at the specified - # location in the repository. - # - # This makes a distinction between normal targets (which physically - # exist in the repository) and subtargets (which are "virtual" - # targets exposed by a physical one) to make it clear in the build - # output which is which. - mkBuildExpr = target: + # 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. + mkBuildExpr = attrPath: let descend = expr: attr: "builtins.getAttr \"${attr}\" (${expr})"; - targetExpr = foldl' descend "import ./. {}" target.__readTree; - subtargetExpr = descend targetExpr target.__subtarget; in - if target ? __subtarget then subtargetExpr else targetExpr; + foldl' descend "import ./. {}" attrPath; # Determine whether to skip a target if it has not diverged from the # HEAD branch. @@ -51,8 +45,8 @@ rec { then "Target has not changed." else false; - # Create build command for a derivation target. - mkBuildCommand = { target, drvPath }: concatStringsSep " " [ + # Create build command for an attribute path pointing to a derivation. + mkBuildCommand = { attrPath, 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 @@ -62,7 +56,7 @@ rec { # Since we don't gcroot the derivation files, they may be deleted by the # garbage collector. In that case we can reevaluate and build the attribute # using nix-build. - "|| (test ! -f '${drvPath}' && nix-build -E '${mkBuildExpr target}' --show-trace)" + "|| (test ! -f '${drvPath}' && nix-build -E '${mkBuildExpr attrPath}' --show-trace)" ]; # Create a pipeline step from a single target. @@ -75,7 +69,12 @@ rec { label = ":nix: " + label; key = hashString "sha1" label; skip = shouldSkip { inherit label drvPath parentTargetMap; }; - command = mkBuildCommand { inherit target drvPath; }; + command = mkBuildCommand { + attrPath = + target.__readTree + ++ lib.optionals (target ? __subtarget) [ target.__subtarget ]; + inherit drvPath; + }; env.READTREE_TARGET = label; cancel_on_build_failing = cancelOnBuildFailing; |