Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ci: Custom GitHub Runners for Nix Builds#1745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
samrose merged 62 commits intodevelopfromcustom-github-runners
Dec 8, 2025

Conversation

@yvan-sraka
Copy link
Collaborator

@yvan-srakayvan-sraka commentedAug 11, 2025
edited by jfroche
Loading

This PR implements a migration from GitHub's standard runners to a hybrid infrastructure combining self-hosted and ephemeral Blacksmith runners for building Nix packages.
The implementation includes runner selection, dynamic build matrix generation, and optimized caching strategies to improve build performance and cost efficiency.

Problem Statement

The previous CI implementation had several limitations:

  1. Monolithic build process: A single job attempted to build all packages across all architectures
  2. Inefficient resource allocation: All packages used the same runner type regardless of build complexity
  3. Limited parallelization: Builds couldn't be efficiently distributed across different runner types
  4. Redundant builds: No mechanism to skip packages already available in the binary cache
  5. Poor cost optimization: Large, expensive builds ran on the same infrastructure as small, quick builds
  6. Poor job output clarity: No separation of build results made it hard to identify issues

Solution Architecture

High-Level Design

┌─────────────────┐│   nix-eval      │  Evaluates flake, generates build matrix│   (Blacksmith)  │  Identifies cached vs. uncached packages└────────┬────────┘  Identifies large packages         │         ├──────────────┬──────────────┬         │              │              │                       v              v              v              ┌────────────────┐ ┌────────────────┐ ┌────────────────┐│ aarch64-linux  │ │ aarch64-darwin │ │ x86_64-linux   ││ Self-hosted/   │ │ Self-hosted    │ │ Blacksmith     ││ Blacksmith     │ │ (macOS)        │ │ Ephemeral      │└────────────────┘ └────────────────┘ └────────────────┘

Architecture Components

  1. Nix Evaluation Phase (nix-eval.yml):

    • Runs on powerful ephemeral runner (32vcpu)
    • Evaluates all flake outputs usingnix-eval-jobs
    • Checks cache status for each package
    • Generates optimized build matrices per architecture
  2. Build Phases (separate jobs per architecture):

    • aarch64-linux: Self-hosted or Blacksmith ARM runners
    • aarch64-darwin: Self-hosted macOS runners
    • x86_64-linux: Blacksmith ephemeral runners
  3. Runner Selection Logic:

    • KVM-required packages → Self-hosted runners with KVM support
    • Large packages (Rust, PostGIS) → 32vcpu runners
    • Standard packages → 8vcpu runners
    • Darwin packages → Self-hosted macOS runners

Key Components

1. Dynamic Matrix Generation (github-matrix Package)

Location:nix/packages/github-matrix/

Core Responsibilities:

  • Evaluates Nix flake outputs usingnix-eval-jobs (https://github.com/nix-community/nix-eval-jobs)
  • Determines package dependencies and build order using topological sorting
  • Identifies cached packages to skip redundant builds
  • Assigns appropriate runners based on package requirements
  • Generates GitHub Actions-compatible JSON matrices

Package Size Detection:

  • UsesrequiredSystemFeatures = ["big-parallel"] in package definitions
  • Automatically allocates 32vcpu runners for:
    • Rust-based extensions (pg_graphql, pg_jsonschema, wrappers)
    • PostGIS (complex C++ builds)
    • pgvector with heavy dependencies

Output Format:

{"aarch64_linux": {"include": [      {"attr":"checks.aarch64-linux.pg_graphql_15","name":"pg_graphql-15.7","system":"aarch64-linux","runs_on": {"labels": ["blacksmith-32vcpu-ubuntu-2404-arm"]},"postgresql_version":"15"      }    ]  },"x86_64_linux": {...},"aarch64_darwin": {...}}

2. Custom Nix Installation Actions

Unify Nix installation across different runner types with two reusable GitHub Actions.

Ephemeral Runners (nix-install-ephemeral)

Location:.github/actions/nix-install-ephemeral/

Purpose: Set up Nix on fresh Blacksmith runners where Nix is not pre-installed

Features:

  • Installs Nix 2.31.2 using cachix/install-nix-action
  • Configures binary cache substituters
  • Optionally sets up AWS credentials for cache pushing
  • Creates post-build hook for automatic cache uploads

Configuration:

-uses:./.github/actions/nix-install-ephemeralwith:push-to-cache:'true'# Enable for build jobsenv:DEV_AWS_ROLE:${{ secrets.DEV_AWS_ROLE }}NIX_SIGN_SECRET_KEY:${{ secrets.NIX_SIGN_SECRET_KEY }}

Cache Upload Mechanism:

  • Post-build hook automatically uploads successful builds to S3
  • Uses Nix signing keys for trusted binary cache
  • Hook script:/etc/nix/upload-to-cache.sh

Self-Hosted Runners (nix-install-self-hosted)

Location:.github/actions/nix-install-self-hosted/

Purpose: Configure AWS credentials on persistent self-hosted runners where Nix is pre-installed

Features:

  • Assumes AWS IAM role via OIDC
  • Writes credentials to/etc/nix/aws/nix-aws-credentials
  • Supports custom role duration (default 5 hours)

3. Reusable Nix Eval Workflow

Location:.github/workflows/nix-eval.yml

Purpose: Shared workflow for matrix generation

Features:

  • Callable from other workflows viaworkflow_call
  • Outputs structured JSON matrix
  • Runs on high-performance ephemeral runner
  • Handles optional AWS credentials for cache access

4. Restructured Build Workflow

Location:.github/workflows/nix-build.yml

New Structure:

jobs:nix-eval:# Generate build matricesuses:./.github/workflows/nix-eval.ymlnix-build-aarch64-linux:needs:nix-evalstrategy:matrix:${{ fromJSON(needs.nix-eval.outputs.matrix).aarch64_linux }}# Build ARM Linux packagesnix-build-aarch64-darwin:needs:nix-evalstrategy:matrix:${{ fromJSON(needs.nix-eval.outputs.matrix).aarch64_darwin }}# Build macOS ARM packagesnix-build-x86_64-linux:needs:nix-evalstrategy:matrix:${{ fromJSON(needs.nix-eval.outputs.matrix).x86_64_linux }}# Build x86_64 Linux packagesrun-testinfra:needs:[nix-build-aarch64-linux, ...]# Only run if all builds succeed or skiprun-tests:needs:[nix-build-aarch64-linux, ...]# Run test suite

Key Improvements:

  1. Parallel Architecture Builds: Each architecture builds independently
  2. Smart Job Skipping: Uses!cancelled() with success/skip conditions
  3. Dynamic Job Names: Include PostgreSQL version for clarity

Related PRs

@yvan-srakayvan-srakaforce-pushed thecustom-github-runners branch 16 times, most recently from1eb74b8 todb1e5e4CompareSeptember 29, 2025 14:29
@jfrochejfrocheforce-pushed thecustom-github-runners branch 5 times, most recently from003d671 to840005bCompareSeptember 29, 2025 21:14
jfrocheand others added22 commitsDecember 8, 2025 14:42
We might not need the full 8vcpu for aarch64-linux builds, so thischange reduces the runner size to 4vcpu to wait less for availableblacksmith runners.
Co-authored-by: samrose <samuel@supabase.io>
Fix github-matrix that would hang when nix-eval-jobs encountered errors due to subprocess pipe deadlock - stderr buffer would fill while reading stdout.This change ensure that evaluation errors are visible and the workflow fails properly while still showing which packages succeeded.
…isibilityIntegrates github-action-utils library to improve error and warningvisibility in GitHub Actions UI through workflow command annotations.
Refactor error handling to collect and group evaluation errors similar to warnings. Errors with the same message are now displayed together with a list of affected attributes.
Extract core error messages and format them better for GitHub Actionsannotations.
Add nix-eval to needs dependencies and check its result in conditional expressions to prevent downstream test jobs from running when evaluation fails.
We are running an older version of the 'result' library that uses'_value' instead of 'ok_value' to access the successful result of acomputation.
…nsionsTo be able to build extensions versions packages separately in CI, weneed to expose them in a nested structure. It is currently not possibleto do so with the flattened packages structure, as the individualextension packages are not directly accessible.In this change, we replace the flattened package structure with nestedlegacyPackages to improve discoverability of individual extensionpackages.
Simplify extension package naming by removing the redundant "-all" suffix that was appended to pname attributes.
…workflowsTo make sure we only build what is necessary, we start building packages first, then run checks once all packages are built successfully.
Use the same 8 vCPU runner for aarch64 builds as used for x86_64 builds to improve build performance.
@samrosesamrose added this pull request to themerge queueDec 8, 2025
Merged via the queue intodevelop with commit1493ca6Dec 8, 2025
18 checks passed
@samrosesamrose deleted the custom-github-runners branchDecember 8, 2025 17:15
hunleyd added a commit that referenced this pull requestDec 8, 2025
* origin:  refactor: Move read-replica.conf to conf.d (#1956)  ci: Custom GitHub Runners for Nix Builds (#1745)  fix: search path and migration grants (#1939)  chore: bump admin api version (#1964)
hunleyd added a commit that referenced this pull requestDec 8, 2025
* origin:  refactor: Move read-replica.conf to conf.d (#1956)  ci: Custom GitHub Runners for Nix Builds (#1745)  fix: search path and migration grants (#1939)  chore: bump admin api version (#1964)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@samrosesamrosesamrose approved these changes

@hunleydhunleydhunleyd approved these changes

@jfrochejfrocheAwaiting requested review from jfroche

Assignees

@yvan-srakayvan-sraka

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@yvan-sraka@samrose@hunleyd@jfroche

[8]ページ先頭

©2009-2025 Movatter.jp