diff --git a/.github/workflows/nix-cache.yml b/.github/workflows/nix-cache.yml new file mode 100644 index 0000000..1bfe3d8 --- /dev/null +++ b/.github/workflows/nix-cache.yml @@ -0,0 +1,67 @@ +# Copyright lowRISC and contributors. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +# Pushes the doris package to lowRISC's public Nix cache on every merge to +# main, so flakes that take doris as an input (`github:lowRISC/doris`) +# download it instead of building it. It authenticates with a short-lived +# token from lowRISC's CA, which trusts this repository's GitHub OIDC +# identity, so no secret is stored. + +name: Nix cache + +on: + push: + branches: [main] + workflow_dispatch: + +permissions: + contents: read + +# Pushes of the same commit are idempotent, but don't run two at once. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +jobs: + push: + # Only lowRISC's repository can get a cache token, not forks. + if: github.repository == 'lowRISC/doris' + strategy: + # Build every system, even if one fails. + fail-fast: false + matrix: + include: + - system: x86_64-linux + runner: ubuntu-latest + - system: aarch64-linux + runner: ubuntu-24.04-arm + name: Push (${{ matrix.system }}) + runs-on: ${{ matrix.runner }} + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v4 + + - uses: cachix/install-nix-action@v31 + with: + extra_nix_config: | + substituters = https://nix-cache.lowrisc.org/public/ https://cache.nixos.org/ + trusted-public-keys = nix-cache.lowrisc.org-public-1:O6JLD0yXzaJDPiQW1meVu32JIDViuaPtGDfjlOopU7o= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= + + - name: Build + run: nix build .#packages.${{ matrix.system }}.default --print-build-logs + + - name: Get a short-lived token for the public cache + id: get-token + uses: lowrisc/ci-actions/ca-token@v1 + with: + ca_api_endpoint: "https://ca.lowrisc.org/api/nix-caches/public/token" + ca_api_method: "GET" + + - name: Push to the public cache + run: | + nix profile install nixpkgs#attic-client + attic login --set-default lowrisc https://nix-cache.lowrisc.org/ ${{ steps.get-token.outputs.token }} + attic push public result