ci: Evaluate with a pool of nix-eval-jobs workers
Build llm-agents / build (pull_request) Skipped

Each CI job ran in its own `nix build`, and its output path came from
a second `nix eval`. Every one of those evaluations paid ~15s and
~4 GiB to evaluate the flake before reaching its job, and import from
derivation stalled each job in turn. The final `ciDrv` evaluation
covered every job once more.

Evaluate everything once with `nix-eval-jobs` instead: workers keep
the shared evaluation for several jobs and wait on import from
derivation in parallel, and the worker count and memory bound cap
evaluation at 24 GiB of the 40 GiB `git` VM. Build every job in one
`nix build --keep-going`, push the results in one copy, and build the
profiled link farm from the known output paths, which makes `ciDrv`
unnecessary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jackos1998andClaude Opus 5.5 committed 2026-11-26 20:33:17 +00:00
1 parent 6abf3a1f3a
commit 10aa3228be
6 files changed
+124 -51

No files matched your search

+1 -28
View File
@@ -52,31 +52,4 @@ jobs:
env:
HARMONIA_SSH_KEY: ${{ secrets.HARMONIA_SSH_KEY }}
CI_IFD_REQUIRED: ${{ steps.ifd.outputs.required }}
run: |
set -o pipefail
nix_options=(--option allow-import-from-derivation "$CI_IFD_REQUIRED")
echo "::group::Collect cache garbage"
ci/push-to-cache.sh --gc
echo "::endgroup::"
nix eval "${nix_options[@]}" --json --apply "builtins.attrNames" .#ci.x86_64-linux | jq -cr '.[]' | while read job; do
echo "::group::Build $job"
nix build "${nix_options[@]}" --no-link .#ci.x86_64-linux."$job"
echo "::endgroup::"
echo "::group::Cache $job"
ci/push-to-cache.sh "$(nix eval "${nix_options[@]}" --raw .#ci.x86_64-linux."$job")"
echo "::endgroup::"
done
if [[ "$CI_IFD_REQUIRED" == true ]]; then
echo "::group::Check flake"
# The target closures are available for the evaluation-time reference graphs.
nix flake check "${nix_options[@]}"
echo "::endgroup::"
fi
echo "Building and caching CI derivation"
nix build "${nix_options[@]}" --no-link .#ciDrv.x86_64-linux
UPDATE_PROFILE=1 ci/push-to-cache.sh "$(nix eval "${nix_options[@]}" --raw .#ciDrv.x86_64-linux)"
run: ci/build-and-cache.sh
+85
View File
@@ -0,0 +1,85 @@
#!/usr/bin/env bash
# Evaluate, build and cache every attribute of `.#ci.<system>`, then point the
# cache's `nixfiles` profile at a link farm of the results.
#
# CI_IFD_REQUIRED=true allows import from derivation and runs the flake check
# after the builds, when the evaluation-time reference graphs are available.
set -euo pipefail
system=x86_64-linux
allow_ifd="${CI_IFD_REQUIRED:-false}"
# Every evaluation worker first pays for a shared evaluation of the flake (a
# few GiB), so keep workers alive for several jobs. workers * memory is the
# evaluation budget; it must leave room on the runner for Gitea and for builds
# started by import from derivation.
eval_workers="${CI_EVAL_WORKERS:-4}"
eval_worker_memory="${CI_EVAL_WORKER_MEMORY:-6144}"
nix_options=(--option allow-import-from-derivation "$allow_ifd")
work="$(mktemp -d)"
failed=0
echo "::group::Collect cache garbage"
ci/push-to-cache.sh --gc
echo "::endgroup::"
echo "::group::Evaluate"
nix_eval_jobs="$(nix build --no-link --print-out-paths ".#nixpkgs.unstable.$system.nix-eval-jobs")/bin/nix-eval-jobs"
"$nix_eval_jobs" "${nix_options[@]}" \
--workers "$eval_workers" --max-memory-size "$eval_worker_memory" \
--gc-roots-dir "$work/gc-roots" \
--flake ".#ci.$system" > "$work/jobs.json" || failed=1
echo "::endgroup::"
# Workflow commands are single lines, so escape the multi-line errors
jq -r 'select(.error) |
"::error title=Evaluation of \(.attrPath[0]) failed::" +
(.error | gsub("\u001b\\[[0-9;]*m"; "") |
gsub("%"; "%25") | gsub("\r"; "%0D") | gsub("\n"; "%0A"))' "$work/jobs.json"
jq -s -e 'any(.error)' "$work/jobs.json" > /dev/null && failed=1
jq -s 'map(select(.drvPath) | { (.attrPath[0]): .outputs.out }) | add // { }' \
"$work/jobs.json" > "$work/outputs.json"
mapfile -t installables < <(jq -r 'select(.drvPath) | .drvPath + "^out"' "$work/jobs.json")
# One build lets independent jobs build in parallel
if (( ${#installables[@]} )); then
echo "::group::Build"
nix build --keep-going --no-link "${installables[@]}" || failed=1
echo "::endgroup::"
fi
built=()
while IFS=$'\t' read -r job path; do
if nix-store --check-validity "$path" 2> /dev/null; then
built+=("$path")
else
echo "::error title=Build of $job failed::See the build log above."
fi
done < <(jq -r 'to_entries[] | "\(.key)\t\(.value)"' "$work/outputs.json")
if (( ${#built[@]} )); then
echo "::group::Cache"
ci/push-to-cache.sh "${built[@]}"
echo "::endgroup::"
fi
if (( failed )); then
exit 1
fi
if [[ "$allow_ifd" == true ]]; then
echo "::group::Check flake"
nix flake check "${nix_options[@]}"
echo "::endgroup::"
fi
# Build the link farm from the known outputs rather than evaluating them again
echo "::group::Update cache profile"
farm_drv="$(nix eval --impure --raw ".#nixpkgs.unstable.$system" --apply "pkgs:
(pkgs.linkFarm \"ci\" (builtins.mapAttrs (_: builtins.storePath)
(builtins.fromJSON (builtins.readFile \"$work/outputs.json\")))).drvPath")"
farm="$(nix build --no-link --print-out-paths "$farm_drv^out")"
UPDATE_PROFILE=1 ci/push-to-cache.sh "$farm"
echo "::endgroup::"
+8 -5
View File
@@ -31,12 +31,15 @@ if [ "${1-}" = "--gc" ]; then
exit
fi
path="$1"
if [ -n "${UPDATE_PROFILE-}" ] && [ $# -ne 1 ]; then
echo "UPDATE_PROFILE needs exactly one path" >&2
exit 1
fi
echo "Pushing $path to cache..."
nix copy --no-check-sigs --to "$STORE_URI" "$path"
echo "Pushing $# path(s) to cache..."
nix copy --no-check-sigs --to "$STORE_URI" "$@"
if [ -n "$UPDATE_PROFILE" ]; then
if [ -n "${UPDATE_PROFILE-}" ]; then
echo "Updating profile..."
remote_cmd nix-env -p "$REMOTE_STORE"/nix/var/nix/profiles/nixfiles --set "$path"
remote_cmd nix-env -p "$REMOTE_STORE"/nix/var/nix/profiles/nixfiles --set "$1"
fi
+1 -2
View File
@@ -51,8 +51,7 @@ Per platform (`eachDefaultSystem`), the flake produces:
- `devShells.default` — the `numtide/devshell` from [`devshell/`](../devshell) (see
[deployment.md](deployment.md)).
- `ci.<system>` — one attr per buildable thing (`system-<name>`, `home-<name>` with `@` mangled
to `-at-`, `package-<name>`, plus `shell`), consumed by CI; `ciDrv` is a `linkFarm` of all of
them.
to `-at-`, `package-<name>`, plus `shell`), consumed by CI.
## Systems: `systemOpts` and `mkSystem`
+29 -15
View File
@@ -302,26 +302,40 @@ GitHub/Gitea Actions workflows live in [`.gitea/workflows/`](../.gitea/workflows
On pushes to `master`, this installs Determinate Nix on the runner (via
`DeterminateSystems/determinate-nix-action`, configured with the same performance settings and
Harmonia substituter as the boxes). CI normally runs `nix flake check --no-build` first and
keeps import from derivation disabled. It builds every attribute of `.#ci.x86_64-linux`:
systems as `system-<name>`, homes as `home-<name>` (with `@` changed to `-at-`), packages as
`package-<name>`, and the development `shell`. Each result is pushed to the
Harmonia cache with [`ci/push-to-cache.sh`](../ci/push-to-cache.sh). Before the first push, the
workflow deletes cache-profile generations older than its retention period, then collects
unreachable paths so a full cache cannot prevent collection from being reached. Paths pushed by
`slop build` survive collection through their own GC roots (see
[`slop-broker.md`](slop-broker.md#binary-cache)).
Harmonia substituter as the boxes). A newer push cancels a run still in progress. CI normally
runs `nix flake check --no-build` first and keeps import from derivation disabled. It then runs
[`ci/build-and-cache.sh`](../ci/build-and-cache.sh), which builds every attribute of
`.#ci.x86_64-linux`: systems as `system-<name>`, homes as `home-<name>` (with `@` changed to
`-at-`), packages as `package-<name>`, and the development `shell`.
The script works in stages:
- **Collect garbage.** It deletes cache-profile generations older than their retention period,
then collects unreachable paths so a full cache cannot prevent collection from being reached.
Paths pushed by `slop build` survive collection through their own GC roots (see
[`slop-broker.md`](slop-broker.md#binary-cache)).
- **Evaluate.** [`nix-eval-jobs`](https://github.com/nix-community/nix-eval-jobs) evaluates the
attributes in a pool of workers. Each worker reuses one evaluation of the flake for several
jobs, and the worker count and per-worker memory bound (`CI_EVAL_WORKERS`,
`CI_EVAL_WORKER_MEMORY`) cap the evaluation's memory on the runner.
- **Build.** One `nix build --keep-going` builds every evaluated derivation, so a failing job
doesn't stop the others.
- **Cache.** Every output that built is pushed to the Harmonia cache with
[`ci/push-to-cache.sh`](../ci/push-to-cache.sh). Any evaluation or build failure fails the run
at this point.
- **Update the profile.** A `linkFarm` of all the outputs, built from their known store paths
rather than a second evaluation, is pushed with `UPDATE_PROFILE=1`. That updates the
`nixfiles` profile on the cache box.
When `.#ciIfdReasons.x86_64-linux` lists an active exception, CI logs a warning with the reason
and allows import from derivation for the target builds. It runs a build-capable flake
check afterward. CI checks [the shared runtime replacement list](../lib/runtime-dependency-replacements.nix)
and allows import from derivation for the evaluation. The evaluation workers then wait on those
builds in parallel. CI runs a build-capable flake check after caching and before updating the
profile. CI checks [the shared runtime replacement list](../lib/runtime-dependency-replacements.nix)
against the nixpkgs channels used by its systems and standalone homes. A matching entry
requires reading generated store reference graphs during evaluation.
It then builds `.#ciDrv.x86_64-linux`, a `linkFarm` of all CI attributes, and pushes it with
`UPDATE_PROFILE=1`. That updates the `nixfiles` profile on the cache box. The SSH store uses
`/var/lib/harmonia`, `HARMONIA_SSH_KEY`, and pinned `ci/known_hosts`; clients use
`https://nix-cache.nul.ie` through `lib.my.c.nix.cache`.
The SSH store uses `/var/lib/harmonia`, `HARMONIA_SSH_KEY`, and pinned `ci/known_hosts`; clients
use `https://nix-cache.nul.ie` through `lib.my.c.nix.cache`.
### `installer.yaml`
-1
View File
@@ -303,7 +303,6 @@
homes' // systems' // packages' // {
inherit shell;
};
ciDrv = pkgs.linkFarm "ci" ci;
ciIfdReasons =
let