Coder Social home page Coder Social logo

eqtylab-actions / magic-nix-cache-action Goto Github PK

View Code? Open in Web Editor NEW

This project forked from determinatesystems/magic-nix-cache-action

0.0 0.0 0.0 9.4 MB

Save 30-50%+ of CI time without any effort or cost. Use Magic Nix Cache, a totally free and zero-configuration binary cache for Nix on GitHub Actions.

License: MIT License

JavaScript 10.23% TypeScript 75.12% Nix 8.85% Just 5.79%

magic-nix-cache-action's Introduction

Magic Nix Cache

Save 30-50%+ of CI time without any effort or cost. Use Magic Nix Cache, a totally free and zero-configuration binary cache for Nix on GitHub Actions.

Add our GitHub Action after installing Nix, in your workflow, like this:

- uses: DeterminateSystems/magic-nix-cache-action@main

See Usage for a detailed example.

Why use the Magic Nix Cache?

Magic Nix Cache uses the GitHub Actions built-in cache to share builds between Workflow runs, and has many advantages over alternatives.

  1. Totally free: backed by GitHub Actions' cache, there is no additional service to pay for.
  2. Zero configuration: add our action to your workflow. That's it. Everything built in your workflow will be cached.
  3. No secrets: Forks and pull requests benefit from the cache, too.
  4. Secure: Magic Nix Cache follows the same semantics as the GitHub Actions cache, and malicious pull requests cannot pollute your project.
  5. Private: The cache is stored in the GitHub Actions cache, not with an additional third party.

Note: the Magic Nix Cache doesn't offer a publicly available cache. This means the cache is only usable in CI. Zero to Nix has an article on binary caching if you want to share Nix builds with users outside of CI.

Usage

Add it to your Linux and macOS GitHub Actions workflows, like this:

name: CI

on:
  push:
  pull_request:

jobs:
  check:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v3
      - uses: DeterminateSystems/nix-installer-action@main
      - uses: DeterminateSystems/magic-nix-cache-action@main
      - uses: DeterminateSystems/flake-checker-action@main
      - name: Run `nix build`
        run: nix build .

That's it. Everything built in your workflow will be cached.

Usage Notes

The GitHub Actions Cache has a rate limit on reads and writes. Occasionally, large projects or large rebuilds may exceed those rate-limits, and you'll see evidence of that in your logs. The error looks like this:

error: unable to download 'http://127.0.0.1:37515/<...>': HTTP error 418
       response body:
       GitHub API error: API error (429 Too Many Requests): StructuredApiError { message: "Request was blocked due to exceeding usage of resource 'Count' in namespace ''." }

The caching daemon and Nix both handle this gracefully, and won't cause your CI to fail. When the rate limit is exceeded while pulling dependencies, your workflow may perform more builds than usual. When the rate limit is exceeded while uploading to the cache, the remainder of those store paths will be uploaded on the next run of the workflow.

Concepts

Upstream cache

When you configure an upstream cache for the Magic Nix Cache, any store paths fetched from that source are not cached because they are known to be fetchable on future workflow runs. The default is https://cache.nixos.org but you can set a different upstream:

- uses: DeterminateSystems/magic-nix-cache-action@main
  with:
    upstream-cache: https://my-binary-cache.com

Action Options

Parameter Description Required Default
diagnostic-endpoint Diagnostic endpoint url where diagnostics and performance data is sent. To disable set this to an empty string. https://install.determinate.systems/magic-nix-cache/perf
flakehub-api-server The FlakeHub API server. https://api.flakehub.com
flakehub-cache-server The FlakeHub binary cache server. https://cache.flakehub.com
flakehub-flake-name The name of your flake on FlakeHub. Defaults to the current name of the GitHub repository it is running in.
listen The host and port to listen on. 127.0.0.1:37515
source-binary Run a version of the cache binary from somewhere already on disk. Conflicts with all other source-* options.
source-branch The branch of magic-nix-cache to use. Conflicts with all other source-* options. main
source-pr The PR of magic-nix-cache to use. Conflicts with all other source-* options.
source-revision The revision of nix-magic-nix-cache to use. Conflicts with all other source-* options.
source-tag The tag of magic-nix-cache to use. Conflicts with all other source-* options.
source-url A URL pointing to a magic-nix-cache binary. Overrides all other source-* options.
startup-notification-port The port magic-nix-cache uses for daemon startup notification. 41239
upstream-cache Your preferred upstream cache. Store paths in this store will not be cached in GitHub Actions' cache. https://cache.nixos.org
use-flakehub Whether to upload build results to FlakeHub Cache. true
use-gha-cache Whether to upload build results to the GitHub Actions cache. true

magic-nix-cache-action's People

Contributors

grahamc avatar edolstra avatar cole-h avatar lucperkins avatar hoverbear avatar flexiondotorg avatar cameronraysmith avatar edmundmiller avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.